How to dynamically call Field Symbols

  • A+
Category:Languages

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. 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: