Hi all,
Suppose i have this code:
<b>loop at table into line.
....
if line-column1 eq 'something'.
....
endloop.</b>
with that i search if the column line-column1 is equal to 'something', and if it is i do something. That works fine, but now i'm facing a problem.
The column that i need to search may be other of about 60 columns. It's the column i get in a string. For instance:
<b>data: text type string.
text = 'column1'.</b>
Is anyway to somehow get the value of a column by a string? In other words:
- if <b>text='column1'</b> the validation should look as <b>if line-column1 eq 'something'.</b>
- if <b>text='column2'</b> the validation should look as <b>if line-column2 eq 'something'.</b>
If the table had few columns a simple case/when, or even if/else would work, but this is a table with more than 60 columns, so it's an option i'm trying to avoid.
Most likelly i need to store the value of the column i want to search in a string and then use it to compare in IF, but i don't know how.
Some people told me that it might me done with field-symbols and appends, but since i'm kind of newbie in abap world i'm not managing to do that.
Can anyone help me with this?
Thanks in advanced for any help.
field-symbols <col> type any.
loop at table into line.
assign component (text) of structure line to <col>.
if <col> eq 'something'.
....
endloop.
Hello Luis
You are already quite close to the solution to your problem.
DATA: ld_column_1 TYPE string, ld_column_2 TYPE string. FIELD-SYMBOLS: <ls_line> TYPE any, <ld_column> TYPE any. ld_column_1 = 'COL_1'. " upper case !!! ld_column_2 = 'COL_2'. " upper case !!! LOOP AT itab ASSIGNING <ls_line>. * First column UNASSIGN: <ld_column>. ASSIGN COMPONENT (ld_column_1) OF STRUCTURE <ls_line> TO <ld_column>. IF ( <ld_column> IS ASSIGNED ). * Do something if condition is fulfilled IF ( <ld_column> eq 'something' ). ... ENDIF. ENDIF. * Second column UNASSIGN: <ld_column>. ASSIGN COMPONENT (ld_column_2) OF STRUCTURE <ls_line> TO <ld_column>. IF ( <ld_column> IS ASSIGNED ). * Do something if condition is fulfilled IF ( <ld_column> eq 'something' ). ... ENDIF. ENDIF. ENDLOOP.
Regards
Uwe
Add a comment