abap assigning a structure by component

DATA: BEGIN OF line,
        col1 TYPE i VALUE '11',
        col2 TYPE i VALUE '22',
        col3 TYPE i VALUE '33',
      END OF line.

DATA comp(5) TYPE c VALUE 'COL3'.

FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE ANY, <f3> TYPE ANY.

ASSIGN line TO <f1>.
ASSIGN comp TO <f2>.

DO 3 TIMES.
  ASSIGN COMPONENT sy-index OF STRUCTURE <f1> TO <f3>.
  WRITE <f3>.
ENDDO.

ASSIGN COMPONENT <f2> OF STRUCTURE <f1> TO <f3>.
WRITE / <f3>.

你可能感兴趣的:(abap assigning a structure by component)