cancel
Showing results for 
Search instead for 
Did you mean: 

Separate ABAP syntax LOOP GROUP BY and LOOP AT GROUP to different methods

0 Kudos

ABAP OO: Is it possible to separate ABAP syntax LOOP GROUP BY and LOOP AT GROUP to different methods?

We want to develop a readable code(Clean code).
We use syntax LOOP GROUP BY with a lot of logic inside it and we want (inside the LOOP) to separate the different logic stories into different methods. Our problem begin when we need to use syntax LOOP AT GROUP and we want it inside sub-method in the LOOP GROUP BY.

We get error message "No group is bound to &Our grouping structure&" and cant compile it.

Sandra_Rossi
Active Contributor
0 Kudos

You forgot to paste the concerned code!

0 Kudos

Example code:

VXLozano
Active Contributor

Sometimes "readable code" and "clean code" are not the same (I cannot ever do any of those).

My question should be "why?" Why do you need to use that approach? Not sure if it's the best one (I'm just beginning with the new syntax), but I cannot understand why you don't use the old COLLECT thing.

Just build a new table with the grouping fields as key, LOOP the table COLLECT'ing the field you want to summarize.

My two cents. As it's not the answer to your question, I put this in the comments.

Good luck.

Sandra_Rossi
Active Contributor
0 Kudos

Please post the code as text instead of image, so that one can easily answer by testing your code.

After you do that, I will show you how to fix it.

matt
Active Contributor

It looks like you need to do

LOOP AT ... GROUP BY ...
  LOOP AT GROUP ...
    " call method here
  ENDLOOP.
ENDLOOP.

Which seems fairly clean to me and readable to me.

VXLozano
Active Contributor
0 Kudos

Matt should convert his comment to answer.
And if you want really clean/readable code, just encapsulate the whole LOOP-LOOP into a method, and your code will read

summarize_data( changing data = lt_emp_pl ).

that seems neat enough for me.

Accepted Solutions (0)

Answers (0)