2023 Sep 19 10:20 AM
Hello every one,
could you please provide some examples of code inside a for iteration cycle?
With new abap code we can substitute loop with for to make iteration faster but how can i write code inside the iteration?
With loop:
Loop at itab assigning field-symbols(<fs>).
Write your code i.e perform o call function or any other code.
endloop.
How can I write my code inside for cycle?
2023 Sep 19 10:33 AM
I never used FOR expressions in ABAP so far.
But as far as I understood, it can be only used to fill data from one internal table to another:
https://blogs.sap.com/2017/11/08/for-expression-in-abap-7.40-best-case-scenarios/
From my point of view, you can't perform a CALL FUNCTION etc. inside the FOR statement.
2023 Sep 19 10:44 AM
Hi Kolz, thanks for your reply.
I thought as much.
Since I must process more than 80.000 items in a loop, the best way is to parallel processing or to divide this iteration into short ranges of records.
2023 Sep 19 11:03 AM
It's bad programming in my view but:
DATA(something) = VALUE #( FOR wa IN Itab ( zmy_class->mymethod( wa ) ).
and have mymethod have some kind of side-effect. E.g. calling a function module.
Oh, and PERFORM is obsolete in most circumstances. Don't use it.
2023 Sep 19 3:32 PM
Hello Matthew,
I see.
I named perform only to explain all and ask if it was possible to add code into for cycle and replace loop with for.
However, please, since we are here, what do you suggest to replace the obsolete calling perform?
In any case, the for cycle is indicated to fill data into a different table from another one, but if we have to make different code, the best way is to use loop. Doesn't it?
2023 Sep 19 4:27 PM
Use classes and methods instead of performs. Note: this is only in new code. Not legacy.
2023 Sep 19 12:28 PM
Where did you find this myth? ("With new abap code we can substitute loop with for to make iteration faster")
I guess many people are mistaken about what are Constructor Expressions for...
Maybe you'd better ask this question: "why should ABAP developers use Constructor Expressions instead of older syntax? In what situations?"