SAP Tutorials Blog


 


Structures can be accessed as a whole. You can also address the individual components of structures at the appropriate operand positions.

To address the components, use the structure component selector -.

For variables with reference to a structured data object, the object component selector -> can be used: ...dref->comp .... The following syntax also works, but is less convenient: ... dref->*-comp ....

ADT and the ABAP Editor provide code completion for structure components after the component selectors.

"Addressing components via the structure component selector

... struc-comp1 ...

... struc-comp2 ...

... struc-comp3 ...


"Examples for addressing the whole structure and individual components

IF struc IS INITIAL. 

  ...

ENDIF.


IF struc-comp1 = 1. 

  ...

ENDIF.


DATA(complete_struc) = struc.

DATA(comp_value) = struc-comp2.


"Type and data declarations

TYPES: type_1 TYPE structured_type-comp1,

       type_2 LIKE struc-comp1.


DATA: var_1 TYPE structured_type-comp1,

      var_2 LIKE struc-comp1.


"Variables with reference to a structured data object

DATA ref_struc_1 TYPE REF TO structured_type.

ref_struc_1 = NEW #( ).

"Excursion: Creating a reference variable using inline declaration

DATA(ref_struc_2) = NEW structured_type( ).


... ref_struc_1->comp1 ...

... ref_struc_1->*-comp1 ...  "Using the dereferencing operator

... ref_struc_2->comp2 ... 

... ref_struc_2->*-comp2 ...  "Using the dereferencing operator

Nested components can be addressed using chaining:


... struc-substructure-comp1 ...

... address_n-name-title ...


Serkan AKKAVAK

Computer Engineer BSc

Head of SAP & Software Department

Contact : serkurumsal@yandex.com