New ABAP has enabled us for the inline declaration.
Gone are the days where we have to declare each and every variable before using it.
Example :
Old approach :
Data : lv_1 type char4.
lv_1 = ‘NAME’
New approach :
Data(lv_1) = ‘NAME’.
Apart from the above simple approach we have below new operators :
1.1. Value operator :
For variables
Old –
Data : lv_1 type char2,
lv_3 type matnr.
New -
DATA(lv_1) = value char2( ).
DATA(lv_2) = value int4( ). “inbuilt data type can be used
DATA(lv_3) = value matnr( ). “DDIC object can be used
For structure :
Data(ls_struc1) = value <structure>( ).
Example :
Data(ls_struc1) = value mara( ).
For internal table :
Data(ls_struc1) = value <table type>( ).
Example :
Data(lt_itab1) = value mara_tab( ). " mara_tab is standard table type
Creating ranges :
lt_range1 TYPE RANGE OF i.
lt_range = VALUE #( sign = 'I' option = 'EQ' ( low = '1' ) ( low = '2' )
lt_range1 = VALUE #( sign = 'I' option = 'EQ' ( low = 1 high = 4 ) ).
1.2. New Operator
Old :
DATA: lo_obj1 TYPE REF TO <Class1>.
Create object lo_obj1.
New :
DATA(lo_ob1) = new Class1( ).
OR
DATA: lo_obj1 TYPE REF TO <Class1>.
Lo_obj1 = NEW #( ).
“ ‘#’ is used when the type is already defined , hence type will be automatically derived from previous declaration statement.
When we need to pass a value to constructor :
No comments:
Post a Comment