Lets say I have a standard structure assigned to a field symbol. Is there a way to pass a variable to the field symbol for dynamic calls?
Eg:
DATA: lt_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE,
parameter_name(10) TYPE c.
parameter_name = 'MATNR'.
LOOP AT lt_mara ASSIGNING FIELD-SYMBOL(<fs_lt_mara>).
WRITE: <fs_lt_mara>-(parameter_name).
ENDLOOP.
Where the parameter_name contains a column name that is available in the mara structure.
It is possible with ASSIGN instruction. Below is an example:
DATA: lt_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE,
parameter_name(10) TYPE c.
parameter_name = 'MATNR'.
FIELD-SYMBOLS: <fs_lt_mara> TYPE mara,
<fs_value> TYPE any.
SELECT * FROM mara UP TO 10 ROWS INTO TABLE lt_mara.
LOOP AT lt_mara ASSIGNING <fs_lt_mara>.
ASSIGN COMPONENT parameter_name OF STRUCTURE <fs_lt_mara> TO <fs_value>.
IF sy-subrc = 0.
WRITE: / <fs_value>.
ENDIF.
ENDLOOP.
I provide another example of ASSIGN
. You do ASSIGN
once and do a LOOP INTO
.
DATA: lt_mara TYPE STANDARD TABLE OF mara,
ls_mara TYPE mara,
lc_matnr TYPE char5 VALUE 'MATNR'.
FIELD-SYMBOLS: <ls_mara> TYPE mara,
<lv_value> TYPE any.
SELECT * FROM mara UP TO 10 ROWS INTO TABLE lt_mara.
ASSIGN COMPONENT lc_matnr OF STRUCTURE ls_mara TO <lv_value>.
CHECK <lv_value> IS ASSIGNED.
LOOP AT lt_mara INTO ls_mara.
WRITE: / <lv_value>.
ENDLOOP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With