SAP FINAL INLINE



Get Example source ABAP code based on a different SAP table
  


• ( ) FINAL
• FINAL ABAP_DECL_OPERATOR

FINAL, Inline Declaration for Immutable Variables

ABAP_SYNTAX
... FINAL(var) ...

What does it do?
Declaration of an immutable variable . A declaration expression with the declaration operator FINAL in general works in the same way as an inline declaration with the declaration operator DATA and the same general rules apply.
While DATA declares a regular variable, FINAL declares an immutable variable: The write position where the variable var is declared with FINAL is the only one, where a value can be assigned to that variable in the current context. In all other positions, any write access leads either to a syntax error or the uncatchable exception MOVE_TO_LIT_NOTALLOWED_NODATA.
The declaration operator FINAL can be used in the same declaration positions as the operator DATA with one exception: FINAL cannot be used behind OPEN CURSOR because usually there is always a second write access with CLOSE CURSOR in the same context.



Latest notes:

The fact that there is only one write position for FINAL in a context does not mean that only one write access can be executed at runtime. For example, the declaration operator FINAL can be positioned inside a loop or it can be used after INTO in a LOOP statement. Then a value is assigned multiple times to var, but var cannot be changed in any other write position.
If a data object called final already exists in the current context, FINAL(var) is interpreted as a substring access and not as an inline declaration.
NON_V5_HINTS
ABAP_HINT_END

ABAP_PGL
Immutable Variables
ABAP_PGL_END

ABAP_EXAMPLE_VX5
Four immutable variables date, yesterday, result, and wa are declared inline with FINAL. They can be used at read positions but any attempt using them at write positions would lead to a syntax error or an exception.
ABEXA 01669
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
Inline declaration of an internal table as a target field of a SELECT statement and inline declaration of a variable for the table transformed to HTML. The data type of the variable is determined by the return value of the method.
ABEXA 00978
ABAP_EXAMPLE_END