Escape character for names in ABAP

Escape character for names.

The character “!” can be written directly before a name in order to distinguish it from an ABAP word of the same name in a statement. With the exception of the first word, each word of a statement that is preceded by the escape character is interpreted as an operand, and not as an ABAP word, in program generation. The escape character itself is not part of a name and is ignored when the statement is executed.

Note:

The escape character may be required on rare occasions in which the compiler cannot tell the difference between an operand and a reserved word of the same name. Otherwise, it can be used for the documentation of operands in the source code.

Example:

Without the escape character “!” before CHANGING after USING, the following program would be syntactically incorrect, because a formal parameter must be entered after USING. Although the second escape character is not necessary, it serves to document USING after CHANGING as a formal parameter.

We can’t activate this piece of code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
*&---------------------------------------------------------------------*
*& Report Z_TEST_PROGRAM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Z_TEST_PROGRAM.

data: var1 type char2,
var2 type char2.

var1 = 'TE'.
perform sub_test using var1 CHANGING var2.

FORM sub_test using changing
changing using.

using = changing.

endform.




But if we change the code to:



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
*&---------------------------------------------------------------------*
*& Report Z_TEST_PROGRAM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Z_TEST_PROGRAM.

data: var1 type char2,

var2 type char2.

var1 = 'TE'.

perform sub_test using var1 CHANGING var2.

FORM sub_test using !changing

changing !using.

using = changing.

endform.


This doesn't give any syntactical error, as shown below.

No comments:

Post a Comment