Professional Documents
Culture Documents
Inline Data Declarations
Inline Data Declarations
• The following examples show inline data declarations: Instead of declaring a variable statically as a global
variable in the program or a local variable in the current context (subroutine, function module, or method),
the declaration is delayed until the statement is executed.
• The name of the variable is enclosed in parentheses and there are no gaps between the data addition, the
opening and closing parentheses, and the name.
• The type of the variable is determined automatically from the context of the statement: In the first example
below, the variable gx_excp will have the type REF TO cx_sy_move_cast_error.
• The variable is created in the statement in which it is declared – it cannot be addressed beforehand.
However, its subsequent lifetime is the same as if it had been declared statically. Hence if the CATCH
statement in the first example below is in the main program, the variable gx_excp is global and remains
alive until the end of the program. Similarly, if the variable is declared within a modularization unit, it remains
alive for the remainder of the corresponding unit.
TRY.
go_oref2 ?= go_oref1.
After
CATCH cx_sy_move_cast_error INTO data(gx_excp).
ENDTRY.
Before
DATA: go_alv TYPE REF TO cl_salv_table.
After
ENDLOOP.
ENDLOOP.