‎2005 Jul 05 7:37 PM
Hello Everyone
Is it possible for me to write a dynamic where for an internal table. For instance when I try the following it throws a compile-error.
l_string = 'first_name EQ ''SDN'''.
LOOP AT l_it_tyname ASSIGNING <fs_tyname> WHERE (l_string).
WRITE 😕 <fs_tyname>-first_name, ' ', <fs_tyname>-last_name.
ENDLOOP.
If this can be done, could you please post a sample one liner.
Thanks in advance.
Sunil
‎2005 Jul 06 4:16 AM
hi, I think the dynamic Where Condition is unavailable in the internal table loop.
If you really want to realize it, you can try
GENERATE SUBROUTINE POOL <itab> NAME <prog> [<options>].
or other dynamicly generate tech.
Using it, you can generate code as you like, so I think this way should solve you problem, but the performance will drop very much. Are you sure you really want it?
And another way to do like this:
DATA: STR TYPE STRING.
FIELD-SYMBOLS: <FS>.
LOOP AT l_it_tyname ASSIGNING <fs_tyname>.
STR = 'first_name'.
ASSIGN COMPONENT STR OF STRUCTURE <fs_tyname> TO <FS>.
IF <FS> = 'SDN'.
......
WRITE 😕 <fs_tyname>-first_name, ' ', <fs_tyname>-last_name.
ENDLOOP.
‎2005 Jul 06 4:54 AM
Hi Sunil,
A dynamic where caluse is available only for database access (Open SQL). In case of an internal table, you cannot specify a where clause dynamically.
however, in most cases, all requirements for dynamism in case of internal tables can usually be met by using Fields symbols. If you could explain your problem further, I'm sure someone on this forum will help you solve it.
Regards,
Anand Mandalika.
‎2005 Jul 07 6:06 PM
Hi Zhenglin, Anand
Thank you for your inputs but I will not be able to solve my problem with the suggestion given by Zhenglin. My problem is I have the same set of logic, which basically involves looping through an internal table with a different where condition. Instead of writing different methods for each one of them I was thinking of building a "str_where" string and sending it to the method as parameter.
I have now created different methods for each of the condition, I guess sometimes its difficult to find a solution which is right fit for you, and thus forcing me to write in a raw way. If there is another way to solve this problem, I would really appreciate your input.
Thanks in advance.
Sunil
‎2005 Jul 08 7:54 AM
Hi Sunil,
i think the only solution for your problem is to
create dynamic program with GENERATE SUBROUTINE ...
-> i've a programm where i create dynamic where-clauses
for a loop - conditions and statements to the loop can be maintained by user in a customize-table.
short extract:
...
append 'loop at tab2 into wa2 ' to prog.
loop at formel."customize-table
concatenate 'wa1-' formel-feld1 into dbfeld.
if sy-tabix = 1.
concatenate 'where' formel-feld1 formel-operator dbfeld
into prog-line separated by space.
else.
concatenate 'and' formel-feld1 formel-operator dbfeld
into prog-line separated by space.
endif.
append prog.
...
regards Andreas