Gyan Factory

Gyan Factory
SAP Technical Project Support

Thursday, January 14, 2016

VALUE - Value Operator ( Uses of Value operator to fill deep structure)

Step1.
--------------------------------------------------------------------------------------------------------------------------
TYPES : BEGIN OF ty_in,
                 f1 TYPE i,
                 f2 TYPE i,
               END OF ty_in.

TYPES : BEGIN OF ty_str,
                 fld1 TYPE ty_in ,
                fld2 TYPE i,
                fld3 TYPE i,
              END OF ty_str.

" Usual-old of of filling deep structure "
DATA : str1 TYPE ty_str.
str1-fld1-f1 = 1.
str1-fld1-f2 = 2.
str1-fld2 = 3.
str1-fld3 = 4.
WRITE :/ 'Old Way', str1-fld1-f1, str1-fld1-f2, str1-fld2,str1-fld3.
"New way of filling depp dtructure with Value operator"
DATA : str2 TYPE ty_str.
str2 = VALUE #( fld1-f1 = 10        " str2 = VALUE ty_str( fld1-f1 = 10
                              fld1-f2 = 20        "                                        fld1-f2 = 20
                              fld2 = 30            "                                         fld2 = 30
                              fld3 = 40 ).         "                                         fld3 = 40 ).

WRITE :/ 'New Way1', str2-fld1-f1, str2-fld1-f2, str2-fld2,str2-fld3.

DATA : str3 TYPE ty_str.
str3 = VALUE #( fld1 = VALUE #( f1 = 100                             
 
                                                            f2 = 200 )      
                                                           fld2 = 300                   
                                                          fld3 = 400 ).                   

WRITE :/ 'New Way2', str3-fld1-f1, str3-fld1-f2, str3-fld2,str3-fld3.

DATA(str4) =  VALUE ty_str( fld1 = VALUE #( f1 = 1000
                                                                                   f2 = 2000 )
                                                                                  fld2 = 3000
                                                                                  fld3 = 4000 ).
WRITE :/ 'New Way3', str4-fld1-f1, str4-fld1-f2, str4-fld2,str4-fld3.
--------------------------------------------------------------------------------------------------------------------------




























Step2. O/P











No comments:

Post a Comment