2018 Aug 24 10:56 AM
Hello Team,
I read somewhere all LOOP statement can be tweaked to form FOR statement. But I wasn't able to achieve it.
I am trying to achieve a dynamic looping using FOR statement. Is FOR supports such a requirement by somehow?
In my case, iteration is dependent on certain values. So can I have such a flexibility using FOR statement. These values are not possible to pass in WHERE conditions.
"<lt_change_log> is dynamic internal table
LOOP AT <lt_change_log> ASSIGNING FIELD-SYMBOL(<ls_change_log>).
ASSIGN COMPONENT 'CDHDR' OF STRUCTURE <ls_change_log> TO <ls_cdhdr>.
LOOP AT <ls_change_log>-cdpos_tab[] ASSIGNING FIELD-SYMBOL(<ls_cdpos>)WHERE changenr = <ls_cdhdr>-changenr.
if <ls_cdpos>-new_value is not initial.
....
else.
continue.
endif.
ENDLOOP.
ENDLOOP.
2018 Aug 24 4:07 PM
"Is FOR supports such a requirement by somehow?"
See the documentation,
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenfor_cond.htm
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenfor_cond.htm
Dynamic WHERE is possible and also nested FORs should work.
What you can't do, is to nest statements as ASSIGN COMPONENT. Only other expressions are possible. And for that you still need LOOP. But that's OK, since expressions don't make statements obsolete. They have another scope.
2018 Aug 24 4:07 PM
"Is FOR supports such a requirement by somehow?"
See the documentation,
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenfor_cond.htm
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenfor_cond.htm
Dynamic WHERE is possible and also nested FORs should work.
What you can't do, is to nest statements as ASSIGN COMPONENT. Only other expressions are possible. And for that you still need LOOP. But that's OK, since expressions don't make statements obsolete. They have another scope.
2018 Aug 27 6:22 AM
Hi Horst,
OK thank you for the information. So for now I would understand that, FOR cannot support dynamic programming.. So LOOP ENDLOOP is still essential..
2018 Aug 27 8:37 AM
2018 Aug 27 7:40 AM
Why? What's the point of replacing LOOP? Where did you read this?