$SEARCH

Instead of overriding code, the search macro provides a search and replace pattern.

Category: layer_control

Code in a lower layer can be changed in different ways by adding $SEARCH, $REPLACE, $APPEND, $PREPEND, $ADD and $END macro instructions

Replace text

...
$SEARCH
   code to search for ...
$REPLACE
   code to replace with ...
$END
...

Delete text

...
$SEARCH
   code to search for ...
$REPLACE
$END
   ...

Add text before (prepend)

...
$PREPEND
   code to add ...
$SEARCH
   code to search for ...
$END
   ...

Add text after (append)

...
$SEARCH
   code to search for ...
$APPEND
   code to follow after ...
$END
   ...

Add text both before and after

...
$PREPEND
   code to add ...
$SEARCH
   code to search for ...
$APPEND
   code to follow after ...
$END
   ...

If you want to write a $SEARCH statement without adding any logic to the body of the method, use $NULL between the BEGIN and END tags.

@Overtake
PROCEDURE Set_Salary (
   salary_ IN  NUMBER )
IS
   $SEARCH
     code to search for ...
   $APPEND
     code to append ...
   $END
BEGIN
   $NULL
END Set_Salary;

If you want to add a declaration but the method in a lower layer has no declarations, you can use $ADD.

@Overtake
PROCEDURE Calculate_Cost (
   order_amount_ IN  NUMBER )
IS
   $ADD
     declaration to add ...
   $END
BEGIN
   $NULL
END Calculate_Cost;

Note:   The code must be written in such a way that it can be parsed as-if the macro commands were comments. If that cannot be accomplished, then the commands $TEXTSEARCH, $TEXTREPLACE, $TEXTAPPEND, $TEXTPREPEND and $TEXTEND can be used instead.

This example searches for the pattern provided, and replaces the code, so that the functionality is modified to return a default value instead of NULL.

--@Overtake Base
FUNCTION Get_Title (
   movie_id_ IN  NUMBER, 
   default_title_ IN VARCHAR2 DEFAULT 'Oblivion' ) RETURN VARCHAR2
IS
BEGIN
   $SEARCH
   IF (movie_id_ IS NULL) THEN
      RETURN NULL;
   END IF;
   $REPLACE
   IF (movie_id_ IS NULL) THEN
      RETURN default_title_;
   END IF;
   $END
END Get_Title;

Note:   *** Commented lines with $KEYWORDS, do not get ignored during the code generation, even it's commented out using single-line comment "--". It is a known limitation in PLSQL, PLSVC and VIEWs files. Instead use multi-line comment "/* */" to comment out unnecessary lines with $ Keywords. Examples as follows:

-- Use multi-line comment to comment out the line with $TEXTSEARCH, if you want to ignore the line when generating code.
             
FUNCTION Get_Title (
   movie_id_ IN  NUMBER, 
   default_title_ IN VARCHAR2 DEFAULT 'Oblivion' ) RETURN VARCHAR2
IS
BEGIN
   $SEARCH
   IF (movie_id_ IS NULL) THEN
      RETURN NULL;
   END IF;
   $REPLACE
   /* $TEXTSEARCH does not need to be used here as we have a valid PL/SQL line. */
   IF (movie_id_ IS NULL) THEN
      RETURN default_title_;
   END IF;
   $END
END Get_Title;
-- Do NOT use single-line comment to comment out the line with $TEXTSEARCH, it doesn't get ignored during code generation.
             
FUNCTION Get_Title (
   movie_id_ IN  NUMBER, 
   default_title_ IN VARCHAR2 DEFAULT 'Oblivion' ) RETURN VARCHAR2
IS
BEGIN
   $SEARCH
   IF (movie_id_ IS NULL) THEN
      RETURN NULL;
   END IF;
   $REPLACE
   -- $TEXTSEARCH does not need to be used here as we have a valid PL/SQL line.
   IF (movie_id_ IS NULL) THEN
      RETURN default_title_;
   END IF;
   $END
END Get_Title;

This page is generated from IFS Developer Studio at 2021-03-10 14:56.