Constant structures can be created with the ... BEGIN OF ... END OF ... additions. Their values cannot be changed.
As shown above, the FINAL declaration operator is used to create immutable variables.
CONSTANTS: BEGIN OF const_struct,
num TYPE i VALUE 123,
str TYPE string VALUE `ABAP`,
n3 TYPE n LENGTH 3 VALUE '000',
c5 TYPE c LENGTH 5 VALUE 'abcde',
END OF const_struct.
DATA(num) = const_struct-num.
"const_struct-num = 456.
TYPES struct_type LIKE const_struct.
FINAL(final_struct) = VALUE struct_type( num = 987 str = `hello` n3 = '123' c5 = 'xyz' ).
DATA(num_from_final) = final_struct-num.
"final_struct-num = 1.
SELECT * FROM zdemo_abap_carr INTO TABLE @DATA(itab).
"The work area is specified as immutable variable. The variable's content cannot be changed
"in the loop, however, the variable is exchanged with the next loop pass.
LOOP AT itab INTO FINAL(wa).
DATA(carrid) = wa-carrid.
"wa-carrid = 'XY'.
ENDLOOP.
Serkan AKKAVAK
Computer Engineer BSc
Head of SAP & Software Department
Contact : serkurumsal@yandex.com

0 Comments