How to use the screen-name value to check a field of a structure In ABAP?

Viewed 163

I have created a screen in ABAP for a new Infotype. Inside the program, I'm doing a loop screen to get different values, but the most important is to know the value of the field inside of the value of screen-name.

An example

screen-name = 'table-field' 

valuefield = screen-name.

**if valuefield is initial. 
...
endif.**

How can I do this?

1 Answers

You can dynamically access a screen value by using FIELD-SYMBOLS

screen-name = 'table-field'.

assign (screen-name) to FIELD-SYMBOL(<fs>).

" you must check if the assignement has been done successfully
" before accessing the content
if sy-subrc = 0 and <fs> is initial.
endif.

If your ABAP version does not allow inline declaration you can consider this:

screen-name = 'table-field'.

FIELD-SYMBOLS <fs> type any.
assign (screen-name) to <fs>.

if sy-subrc = 0 and <fs> is initial.
endif.
Related