AS ABAP Release 758, ©Copyright 2024 SAP SE. All rights reserved.ABAP - Keyword Documentation → ABAP - Programming Language → Declarations → Inline Declarations →
DATA, Inline Declaration for Variables
... DATA(var) ...
A declaration expression with the declaration operator DATA declares a variable var that is used as an operand in the current write position. The declared variable is visible statically in the program as of DATA(var) and is valid in the current context. The declaration is made when the program is compiled, regardless of whether the statement is actually executed.
The declaration operator DATA can be specified in any designated declaration position. The date type of the variable is determined by the operand type. It must be possible to derive this type completely statically.
A variable var declared inline cannot be used in a read position of the same statement.
If a data object called data already exists in the current context, DATA(var) is interpreted as a substring access and not as an inline declaration. A syntax warning indicates this. DATA(var) only works as an inline declaration if there is no data object called data yet.
DATA var TYPE ...
... var ...
Deviations from this rule occur only if an identically named data object of a more global context is used in the same statement. This is still valid in the statement and is only hidden after the statement.
Inline declaration of an internal table as the target field of an assignment and inline declaration of an appropriate work area in a LOOP. Since there are other write accesses to the variables, inline declarations with FINAL are not possible here.
TYPES t_itab TYPE TABLE OF i
WITH NON-UNIQUE KEY table_line.
DATA(itab) = VALUE t_itab( ( 1 ) ( 2 ) ( 3 ) ).
APPEND 4 TO itab.
LOOP AT itab INTO DATA(wa).
wa = 0.
If a data object called data does not exist in the current context, the first statement is an inline declaration and the second statement executes a substring access.