Application Development 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: 

Does REDUCE perform better using sorted tables?

matteo_pascon
Explorer
0 Kudos
436

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

fedaros
Product and Topic Expert
Product and Topic Expert
363

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

fedaros
Product and Topic Expert
Product and Topic Expert
364

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

0 Kudos
363

Wonderful! Thanks for the insights.

363

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.

0 Kudos
363

Got it. Thanks for sharing the documentation.