Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CONSTANTS: BEGIN OF gc_const_struct,
- comp1 TYPE string VALUE 'component1',
- comp2 TYPE string VALUE 'component2',
- comp3 TYPE string VALUE 'component3',
- comp4 TYPE string VALUE 'component4',
- END OF gc_const_struct.
- " Get the components of the structure and their number
- DATA(lt_components) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( gc_const_struct ) )->get_components( ).
- DATA(lv_num_of_components) = lines( lt_components ).
- " Iterate over the components of the structure
- " Variant (1) - Iterate over components using loop index
- WHILE sy-index <= lv_num_of_components.
- ASSIGN COMPONENT sy-index OF STRUCTURE gc_const_struct TO FIELD-SYMBOL(<fs_comp_value1>).
- IF <fs_comp_value1> IS NOT ASSIGNED.
- EXIT.
- ELSE.
- WRITE / |Component: { <fs_comp_value1> } |.
- ENDIF.
- ENDWHILE.
- WRITE / '-------------------------------------'.
- " Variant (2) - Directly iterate over component table using LOOP statement
- LOOP AT lt_components ASSIGNING FIELD-SYMBOL(<fs_comp>).
- ASSIGN COMPONENT <fs_comp>-name OF STRUCTURE gc_const_struct TO FIELD-SYMBOL(<fs_comp_value2>).
- IF <fs_comp_value2> IS NOT ASSIGNED.
- EXIT.
- ELSE.
- WRITE / |Component: { <fs_comp_value2> } |.
- ENDIF.
- ENDLOOP.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement