Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Example of code inside new for iteration

Pier_1973
Participant
0 Kudos
500

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?

6 REPLIES 6

thkolz
Contributor
0 Kudos
415

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.

Pier_1973
Participant
0 Kudos
415

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.

matt
Active Contributor
0 Kudos
415

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.

0 Kudos
415

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?

matt
Active Contributor
0 Kudos
415

Use classes and methods instead of performs. Note: this is only in new code. Not legacy.

Sandra_Rossi
Active Contributor
0 Kudos
415

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?"