Constructor expression create a new variable from scratch. Components have initial value unless passed explicity using expression argument. A template value or start can be applied using BASE, before actual construction takes place. Valid since ABAP 740 SP08.
Below are some basic example codes of BASE being applied in VALUE, NEW and CORRESPONDING.
TYPES: BEGIN OF ts, a, b, c, END OF ts.
"VALUE with BASE
DATA(base1) = VALUE ts( a = 'a' b = 'b' c = 'c' ).
DATA(ls1) = VALUE #( BASE base1 a = '.' ).
cl_demo_output=>write( base1 ).
cl_demo_output=>write( ls1 ).
"NEW with BASE
DATA(ldr1) = NEW #( BASE base1 b = '.' ).
cl_demo_output=>write( ldr1->* ).
"CORRESPONDING with BASE
TYPES: BEGIN OF ts2, b, c, END OF ts2.
DATA(ls2) = CORRESPONDING ts( BASE ( base1 ) VALUE ts2( b = '.' ) ).
cl_demo_output=>write( ls2 ).
"display all
cl_demo_output=>display( ).
No comments:
Post a Comment