‎2006 Oct 24 2:01 AM
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.
‎2006 Oct 24 3:34 AM
field-symbols <col> type any.
loop at table into line.
assign component (text) of structure line to <col>.
if <col> eq 'something'.
....
endloop.
‎2006 Oct 24 2:44 AM
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
‎2006 Oct 24 3:34 AM
field-symbols <col> type any.
loop at table into line.
assign component (text) of structure line to <col>.
if <col> eq 'something'.
....
endloop.
‎2006 Oct 24 1:33 PM
Thank you both, you were very helpfull !!
Just having a problem, but already saw what was...
In line:
.
Thanks for the great help !!
LuÃs Cruz
Message was edited by: LuÃs Cruz