‎2008 Nov 18 6:03 AM
Hello,
I need to select lines from one internal table (with a large number of fields) based on different fields. E.g.
Table: zitab1
Fields: field1, field2, ..., fieldN
If I want to go through the table based on fields: field1, field2 and field3, I have to use the following code:
LOOP AT ZITAB1 WHERE FIELD1 EQ 'SEARCH_KEY'.
...
ENDLOOP.
LOOP AT ZITAB1 WHERE FIELD2 EQ 'SEARCH_KEY'.
...
ENDLOOP.
LOOP AT ZITAB1 WHERE FIELD3 EQ 'SEARCH_KEY'.
...
ENDLOOP.
Is there a way to read the itab using field selection at runtime so I can replace all these separate loop statements with a single statement, e.g.
LOOP AT ZITAB1 WHERE (FIELD) EQ 'SEARCH_KEY'.
...
ENDLOOP.
where (FIELD) can be specified to be any of the fields in the table zitab1?
Help is appreciated.
Regards
Edited by: Khan Awkhan on Nov 18, 2008 7:04 AM
‎2008 Nov 18 6:08 AM
Hi Khan,
By using field-symbols, i think this might be possible.
First define this LOOP in a sub-routine to which you pass the field name as a parameter.
Then, you can use the syntax
ASSIGN COMPONENT OF .......to assign the field name to a field-symbol. Pass this as the parameter to the sub-routine.
In the sub-routine, while looping, you can try using this parameter (Field-Symbol) and check against the search key (This can also be passed using a field-symbol).
Try this. I think you should be able to crack it.
Best Regards,
Ram.
‎2008 Nov 18 6:08 AM
Hi Khan,
By using field-symbols, i think this might be possible.
First define this LOOP in a sub-routine to which you pass the field name as a parameter.
Then, you can use the syntax
ASSIGN COMPONENT OF .......to assign the field name to a field-symbol. Pass this as the parameter to the sub-routine.
In the sub-routine, while looping, you can try using this parameter (Field-Symbol) and check against the search key (This can also be passed using a field-symbol).
Try this. I think you should be able to crack it.
Best Regards,
Ram.
‎2008 Nov 18 6:42 AM
Hi:
Try to use Subroutine by passing the field name and its value.
Regards
Shashi