Assigning Components of Structures to a Field Symbol
For a structured data object <s>, you can use the statement
ASSIGN COMPONENT <comp> OF STRUCTURE <s> TO <FS>.
to assign one of its components <comp> to the field symbol <FS>. You can specify the component <comp> either as a literal or a variable. If <comp> is of type C or a structure that has no internal tables as components, it specifies the name of the component. If <comp> has any other elementary data type, it is converted to type I and specifies the number of the component. If the assignment is successful, SY-SUBRC is set to 0. Otherwise, it is set to 4.
This statement is particularly important for addressing components of structured data objects dynamically. If you assign a data object to a field symbol either generically or usingcasting, or pass it generically (or using casting) to the parameter interface of a procedure, you cannot address its components either statically or dynamically. Instead, you must use the above statement. This allows indirect access either using the component name or its index number.
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) VALUE 'COL3'.
FIELD-SYMBOLS: <F1>, <F2>, <F3>.
ASSIGN LINE TO <F1>.
ASSIGN COMP TO <F2>.
DO 3 TIMES.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <F1> TO <F3>.
ASSIGN COMPONENT <F2> OF STRUCTURE <F1> TO <F3>.
WRITE / <F3>.
The output is:
11 22 33
The field symbol <F1> points to the structure LINE, <F2> points to the field COMP. In the