Overtake using Search & Replace¶
Instead of overtaking the whole method, overtake using Search and Replace can be used. This type of overtake finds a code section and replaces it with the code you want. If the code is changed in the underlying layer, you only need to handle your change, if the code you searched for has been removed. This is a type of surgical overtake, where you only overtake a small piece of code and not the whole method. Advanced overtake is suitable when you have few places in the same method that you want to change.
Code in a lower layer can be changed in different ways by adding $SEARCH, $REPLACE, $APPEND, $PREPEND and $END macro instructions. 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.
Syntax of the replace statements, see $SEARCH.
Note: Replace statement is only allowed in the customization layer.
Search and Replace¶
In $SEARCH and $REPLACE you search for a given row(s) and replace the row(s) with the change you want to have in that part.
Example:
@Overtake Base
FUNCTION Get_Queue_Id (
object_group_id_ IN VARCHAR2 ) RETURN NUMBER
IS
temp_ override_overtake_tab.queue_id%TYPE;
BEGIN
$SEARCH
SELECT queue_id
INTO temp_
FROM override_overtake_tab
WHERE object_group_id = object_group_id_;
$REPLACE
SELECT queue_id
INTO temp_
FROM override_overtake_tab
WHERE object_group_id = object_group_id_ or object_group_id_ = 'XxX';
$END
END Get_Queue_Id;
¶
In generated, deployable code:
--@IgnoreMissingSysinit
FUNCTION Get_Queue_Id (
object_group_id_ IN VARCHAR2 ) RETURN NUMBER
IS
FUNCTION Base (
object_group_id_ IN VARCHAR2 ) RETURN NUMBER
IS
temp_ override_overtake_tab.queue_id%TYPE;
BEGIN
IF (object_group_id_ IS NULL) THEN
RETURN NULL;
END IF;
/*SEARCH section
SELECT queue_id
INTO temp_
FROM override_overtake_tab
WHERE object_group_id = object_group_id_;
REPLACE section*/
SELECT queue_id
INTO temp_
FROM override_overtake_tab
WHERE object_group_id = object_group_id_ or object_group_id_ = 'XxX';
/*END of text edit section*/
RETURN temp_;
EXCEPTION
WHEN no_data_found THEN
RETURN NULL;
WHEN too_many_rows THEN
Raise_Too_Many_Rows___(object_group_id_, 'Get_Queue_Id');
END Base;
FUNCTION Ext (
object_group_id_ IN VARCHAR2 ) RETURN NUMBER
IS
BEGIN
RETURN Base(object_group_id_);
END Ext;
BEGIN
RETURN Ext(object_group_id_);
END Get_Queue_Id;
¶
In case you only want to replace a part of a statement, the commands $TEXTSEARCH, $TEXTREPLACE and $TEXTEND can be used instead. Here you only include the code line(s) that you want to search and replace.
Example:
@Overtake Base
FUNCTION Get (
object_group_id_ IN VARCHAR2 ) RETURN NUMBER
IS
BEGIN
$TEXTSEARCH
WHERE object_group_id = object_group_id_;
$TEXTREPLACE
WHERE object_group_id = object_group_id_ or object_group_id_ = 'XxX';
$TEXTEND
END Get;
¶
In generated, deployable code:
--@IgnoreMissingSysinit
FUNCTION Get (
object_group_id_ IN VARCHAR2 ) RETURN NUMBER
IS
FUNCTION Base (
object_group_id_ IN VARCHAR2 ) RETURN Public_Rec
IS
temp_ Public_Rec;
BEGIN
IF (object_group_id_ IS NULL) THEN
RETURN NULL;
END IF;
SELECT object_group_id, rowid, rowversion, rowkey,
description,
queue_id
INTO temp_
FROM override_overtake_tab
/*SEARCH section
WHERE object_group_id = object_group_id_;
REPLACE section*/
WHERE object_group_id = object_group_id_ or object_group_id_ = 'XxX';
/*END of text edit section*/
RETURN temp_;
EXCEPTION
WHEN no_data_found THEN
RETURN NULL;
WHEN too_many_rows THEN
Raise_Too_Many_Rows___(object_group_id_, 'Get');
END Base;
FUNCTION Ext (
object_group_id_ IN VARCHAR2 ) RETURN NUMBER
IS
BEGIN
RETURN Base(object_group_id_);
END Ext;
BEGIN
RETURN Ext(object_group_id_);
END Get;
¶
Search and Prepend¶
In $SEARCH and $PREPEND or in $TEXTSEARCH and $TEXTPREPEND, you search for a given row(s) and adds your change before the row(s) you searched for.
Example:
@Overtake Core
PROCEDURE Calculate (
calc_value_ OUT NUMBER,
calc_value2_ OUT NUMBER,
object_group_id_ IN VARCHAR2)
IS
BEGIN
$PREPEND
IF (object_group_id_ = 'ZzZ') THEN
object_group_id_ := 'XxX';
END IF;
$SEARCH
IF (object_group_id_ = 'XxX') THEN
x_ := 1;
y_ := 1;
ELSE
x_ := 2;
y_ := 2;
END IF;
$END
END Calculate;
¶
In generated, deployable code:
PROCEDURE Calculate (
calc_value_ OUT NUMBER,
calc_value2_ OUT NUMBER,
object_group_id_ IN VARCHAR2)
IS
PROCEDURE Core (
calc_value_ OUT NUMBER,
calc_value2_ OUT NUMBER,
object_group_id_ IN VARCHAR2)
IS
x_ NUMBER;
y_ NUMBER;
BEGIN
x_ := 0;
y_ := 0;
/*PREPEND section*/
IF (object_group_id_ = 'ZzZ') THEN
object_group_id_ := 'XxX';
END IF;
/*SEARCH section*/
IF (object_group_id_ = 'XxX') THEN
x_ := 1;
y_ := 1;
ELSE
x_ := 2;
y_ := 2;
END IF;
calc_value_ := x_;
calc_value2_ := x_ + y_;
END Core;
PROCEDURE Ext (
calc_value_ OUT NUMBER,
calc_value2_ OUT NUMBER,
object_group_id_ IN VARCHAR2)
IS
BEGIN
Core(calc_value_, calc_value2_, object_group_id_);
END Ext;
BEGIN
General_SYS.Init_Method(Override_Overtake_API.lu_name_, 'Override_Overtake_API', 'Calculate');
Ext(calc_value_, calc_value2_, object_group_id_);
END Calculate;
¶
Search and Append¶
In $SEARCH and $APPEND or in $TEXTSEARCH and $TEXTAPPEND you search for a given row(s) and adds your change after the row(s) you searched for.
Example:
@Overtake Core
PROCEDURE Calculate2 (
calc_value_ OUT NUMBER,
calc_value2_ OUT NUMBER,
object_group_id_ IN VARCHAR2)
IS
x_ NUMBER;
y_ NUMBER;
BEGIN
x_ := 0;
y_ := 0;
IF (object_group_id_ = 'XxX') THEN
x_ := 1;
y_ := 1;
ELSE
x_ := 2;
y_ := 2;
END IF;
calc_value_ := x_;
$SEARCH
calc_value2_ := x_ + y_;
$APPEND
IF (object_group_id_ = 'ZzZ') THEN
calc_value_ := calc_value_ + calc_value2_;
END IF;
$END
END Calculate2;
¶
In generated, deployable code:
PROCEDURE Calculate2 (
calc_value_ OUT NUMBER,
calc_value2_ OUT NUMBER,
object_group_id_ IN VARCHAR2)
IS
PROCEDURE Core (
calc_value_ OUT NUMBER,
calc_value2_ OUT NUMBER,
object_group_id_ IN VARCHAR2)
IS
x_ NUMBER;
y_ NUMBER;
BEGIN
x_ := 0;
y_ := 0;
IF (object_group_id_ = 'XxX') THEN
x_ := 1;
y_ := 1;
ELSE
x_ := 2;
y_ := 2;
END IF;
calc_value_ := x_;
calc_value2_ := x_ + y_;
/*APPEND section*/
IF (object_group_id_ = 'ZzZ') THEN
calc_value_ := calc_value_ + calc_value2_;
END IF;
/*END of text edit section*/
END Core;
PROCEDURE Ext (
calc_value_ OUT NUMBER,
calc_value2_ OUT NUMBER,
object_group_id_ IN VARCHAR2)
IS
BEGIN
Core(calc_value_, calc_value2_, object_group_id_);
END Ext;
BEGIN
General_SYS.Init_Method(Override_Overtake_API.lu_name_, 'Override_Overtake_API', 'Calculate2');
Ext(calc_value_, calc_value2_, object_group_id_);
END Calculate2;