‎2007 Jun 22 10:12 AM
I have an internal table that has a structure something like:
BEGIN OF itab,
item(10) TYPE c,
opt1 TYPE c,
opt2 TYPE c,
opt3 TYPE c,
END OF itab.It contains values like:
Item Opt1 Opt2 Opt3
Item1 X
Item2 X X
Item3 XI want to create a method that will loop dynamically on the table for a selected field.
Something like
LOOP AT itab WHERE (field) EQ 'X'.Where "field" could be Opt1, Opt2 or Opt3.
Is this possible? I have tried using a field symbol
ASSIGN (field) TO <fs_field>.
LOOP AT itab WHERE <fs_field> EQ 'X'.And I get the error "no component exists with the name <fs_field>.
‎2007 Jun 22 11:08 AM
As an alternative perhaps you can move your dynamic check to within the loop?
LOOP AT itab.
ASSIGN (field) TO <fs_field>.
IF <fs_field> EQ 'X'.
...
ENDIF.
ENDLOOP.
‎2007 Jun 22 11:03 AM
Hi,
The help says this is not possible:
WHERE log_exp
Effect
WHERE can be specified with all table-types. After WHERE, you can specify any logical expression log_exp in which the first operand of any singular comparison is a component of the internal table. For this reason, all logical expressions are possible except for IS ASSIGNED, IS REQUESTED and IS SUPPLIED. <b>Dynamic specification of a component through bracketed character-type data objects is not possible</b>. Loops at sorted tables must have compatible operands of the logical expression. All rows are read for which the logical expression is true.
Not much help I know but atleast you know where you stand.
‎2007 Jun 22 11:08 AM
As an alternative perhaps you can move your dynamic check to within the loop?
LOOP AT itab.
ASSIGN (field) TO <fs_field>.
IF <fs_field> EQ 'X'.
...
ENDIF.
ENDLOOP.
‎2007 Jun 22 11:18 AM
Hi
It can't create a dynamic WHERE condition for the LOOP statament, it's possible for the SELECT only, so u need to check your fields inside of LOOP using field-symbols:
LOOP AT itab.
IF ........ood ide
FIELD = <...>.
ENDIF.
ASSIGN (FIELD) TO <FS_FIELD>.
CHECK <FS_FIELD> = 'X'.
ENDLOOP.The problem can be on the performance because you need to loop all records of the internal table, if you use a WHERE clauses the performace will be better.
So if the ITAB can have many records you should decide if it can be a good idea to use the field-symbols.
Max
‎2007 Jun 22 11:20 AM
Yes. That's what I'm going to have to go with.
Not the best performance, but it works.