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: 
Read only

Does REDUCE perform better using sorted tables?

matteo_pascon
Explorer
0 Likes
1,459

So, I'm using reduce to get the number of record that satisfy a condition inside a loop.

Will it perform better if the table is declared as sorted using a logic similar to that of parallel cursor or does it actually just check linearly?

The code is as follow.

DATA(sum) = REDUCE i( INIT x = 0 FOR wa IN lt_iloa WHERE ( tplnr = ls_ifl_list-tplnr ) NEXT x = x + 1 ).

1 ACCEPTED SOLUTION
Read only

fedaros
Product and Topic Expert
Product and Topic Expert
1,386

Hi Matteo,

Yes, it will take the advantage of access by key on tplnr and will not run entire internal table. So the difference of execution can be huge and with a constant result time benefit from indexed access.

Regards, Fernando Da Rós

4 REPLIES 4
Read only

fedaros
Product and Topic Expert
Product and Topic Expert
1,387

Hi Matteo,

Yes, it will take the advantage of access by key on tplnr and will not run entire internal table. So the difference of execution can be huge and with a constant result time benefit from indexed access.

Regards, Fernando Da Rós

Read only

0 Likes
1,386

Wonderful! Thanks for the insights.

Read only

1,386

matteo_pascon as documented in ABAP documentation FOR, cond > "As with LOOP AT itab, the following is possible for each expression FOR ... IN itab" > LOOP AT itab, cond :

  • "If the primary table key is specified using its name primary_key, the processing behaves in the same way as if no key were explicitly specified."
  • etc.
Read only

0 Likes
1,386

Got it. Thanks for sharing the documentation.