Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. CONSTANTS: BEGIN OF gc_const_struct,
  2. comp1 TYPE string VALUE 'component1',
  3. comp2 TYPE string VALUE 'component2',
  4. comp3 TYPE string VALUE 'component3',
  5. comp4 TYPE string VALUE 'component4',
  6. END OF gc_const_struct.
  7.  
  8.  
  9. " Get the components of the structure and their number
  10. DATA(lt_components) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( gc_const_struct ) )->get_components( ).
  11. DATA(lv_num_of_components) = lines( lt_components ).
  12.  
  13.  
  14. " Iterate over the components of the structure
  15. " Variant (1) - Iterate over components using loop index
  16. WHILE sy-index <= lv_num_of_components.
  17.  
  18. ASSIGN COMPONENT sy-index OF STRUCTURE gc_const_struct TO FIELD-SYMBOL(<fs_comp_value1>).
  19. IF <fs_comp_value1> IS NOT ASSIGNED.
  20. EXIT.
  21. ELSE.
  22. WRITE / |Component: { <fs_comp_value1> } |.
  23. ENDIF.
  24. ENDWHILE.
  25.  
  26. WRITE / '-------------------------------------'.
  27.  
  28. " Variant (2) - Directly iterate over component table using LOOP statement
  29. LOOP AT lt_components ASSIGNING FIELD-SYMBOL(<fs_comp>).
  30.  
  31. ASSIGN COMPONENT <fs_comp>-name OF STRUCTURE gc_const_struct TO FIELD-SYMBOL(<fs_comp_value2>).
  32. IF <fs_comp_value2> IS NOT ASSIGNED.
  33. EXIT.
  34. ELSE.
  35. WRITE / |Component: { <fs_comp_value2> } |.
  36. ENDIF.
  37. ENDLOOP.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement