1. Declaration

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 :

DATA : lt_range TYPE RANGE OF i,
       lt_range1 TYPE RANGE OF i.
lt_range = VALUE #( sign = 'I' option = 'EQ' ( low = '1' )                                                                                                                                         ( low = '2' ) 
                                                                              ( low = '3' ) 
                                                                              ( low = '4' ) 
                                         ).


          lt_range1 = VALUE #( sign = 'I' option = 'EQ' ( low = 1 high =  4 ) ).


 

NOTE : Please remember that once you will execute your program it will first read all the
declaration lines including inline declaration . 
    So even if you are using inline declaration at last line of your program then also it will get declared and you can see the structure immediately after executing at run time . Note that this doesn’t mean that you can use the inline declared variable before declaring it in the program.

 

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 :

DATA(lo_ob1) = new Class1( <passvalue> ). “<passvalue> is to passed to constructor
Example :
DATA(lo_ob1) = new Class1( ‘TEST’ ).
 

No comments:

Post a Comment