SAP DATA INLINE



Get Example source ABAP code based on a different SAP table
  


• ( ) DATA
• DATA ABAP_DECL_OPERATOR

DATA, Inline Declaration for Variables

ABAP_SYNTAX
... DATA(var) ...

What does it do?
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.

ABAP_PGL
Only use inline declarations locally .
ABAP_PGL_END



Latest notes:

A valid statement with an inline declaration of a variable can generally be interpreted as a short form for a declaration statement used as a direct prefix. 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.
BEGIN_SECTION SAP_INTERNAL_HINT
The opposite direction is not always possible, namely if the same variable is used multiply in one statement and if the sequence rule cannot be fulfilled.
END_SECTION SAP_INTERNAL_HINT
Just like the statement DATA, an inline declaration does not open a local context for the current statement block. An inline declaration for a variable can only be made once within a context and the variable must not have been declared there using DATA.
An inline declaration can never occur on the right-hand side of an assignment or within an expression.
The operand position and the types of other operands can be included in the static derivation of the operand type. If the type of a different operand cannot be identified statically, for example because it is specified as a generically typed field symbol, either a suitable standard type is used or no inline declaration is possible.
If the operand type is defined by reference to a data type of the ABAP Dictionary, it is inherited with its semantic properties, such as field help, input help, or conversion routines.
If multiple equally valid operand types are possible in a declaration position, the recommended preferred data type is generally used.
If no other write accesses to the variable var should take place in the current context, it is preferable to use the declaration operator FINAL to declare an immutable variable instead of DATA.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
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.
ABEXA 00977
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
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. DATA(data) = '1'.
DATA(data) = '2'.
ABAP_EXAMPLE_END