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: 

Doubt in abap report program.

0 Kudos

Can any one help me to Build a best logic for my internal table data to my output as i mentioned in PICTURE.

I have done it by using grouping concept it is working fine but i want to minimize the logic and increase the performance.

In the below picture there is an internal table and I want the output as in the picture.

And Don't forget to include commas please.

************************************************************************************

LOOP AT it_manufacture INTO lw_manufacture GROUP BY lw_manufacture-name.
WRITE 😕 lw_manufacture-name.
LOOP AT GROUP lw_manufacture INTO lw_manufacture_group.
IF lv_var EQ 1.
CONCATENATE ':' lw_manufacture_group-description INTO lv_str.
WRITE lv_str.
ELSE.
lv_str = lw_manufacture_group-description.
CONCATENATE ',' lv_str INTO lv_str.
WRITE lv_str.
ENDIF.
lv_var = lv_var + 1.
ENDLOOP.
CLEAR lv_var.
lv_var = 1.
ENDLOOP.

1 ACCEPTED SOLUTION

former_member1716
Active Contributor

Hello MAHARSHI PADAMATINTI,

You want to make use of Control Break Statements, I can help with the pseudo code as below:

* Below CODE is Just Pseudo Code to explain the concept.
DATA: LV_CHAR type CHAR50.
SORT it_manufacture by FIELD1.
LOOP AT it_manufacture into lw_manufacture.
AT NEW FIELD1.
DATA(LV_NEW = ABAP_TRUE.
ENDAT.
IF LV_NEW EQ ABAP_TRUE.
CLEAR: LV_CHAR.
LV_CHAR = LW_MANUFACTURE-FIELD2.
CLEAR: LV_NEW.
ELSE.
CONCATENATE LV_CHAR ','  LW_MANUFACTURE-FIELD2 INTO LV_CHAR.
ENDIF.
AT END OF FIELD1.
DATA(LV_END) = ABAP_TRUE.
ENDAT
IF LV_END EQ ABAP_TRUE.
WRITE: LV_CHAR.
ENDIF.
ENDLOOP.

Regards!

4 REPLIES 4

SimoneMilesi
Active Contributor
0 Kudos

I don't understand your question: which is your doubt?
PS.

Better if you format your code

former_member1716
Active Contributor

Hello MAHARSHI PADAMATINTI,

You want to make use of Control Break Statements, I can help with the pseudo code as below:

* Below CODE is Just Pseudo Code to explain the concept.
DATA: LV_CHAR type CHAR50.
SORT it_manufacture by FIELD1.
LOOP AT it_manufacture into lw_manufacture.
AT NEW FIELD1.
DATA(LV_NEW = ABAP_TRUE.
ENDAT.
IF LV_NEW EQ ABAP_TRUE.
CLEAR: LV_CHAR.
LV_CHAR = LW_MANUFACTURE-FIELD2.
CLEAR: LV_NEW.
ELSE.
CONCATENATE LV_CHAR ','  LW_MANUFACTURE-FIELD2 INTO LV_CHAR.
ENDIF.
AT END OF FIELD1.
DATA(LV_END) = ABAP_TRUE.
ENDAT
IF LV_END EQ ABAP_TRUE.
WRITE: LV_CHAR.
ENDIF.
ENDLOOP.

Regards!

0 Kudos

Hey Thanks, I got to know this by friend also Is there any other easy way,

Your answer is good!!!!

Just searching for different techiques/ways,

Any other simpler way you can guide me please.

0 Kudos

MAHARSHI PADAMATINTI

From F1 help for Control Level Processing:

If possible, the use of the addition GROUP BY is recommended, since the grouping is not determined by the structure of the rows and the processing order in this case. 

You can check the demo: DEMO_INT_TABLES_AT_UNSORTED to understand the difference in outcome of them.

For your sample, you just need to concatenate the string and write it when finish:

LOOP AT it_manufacture INTO lw_manufacture GROUP BY lw_manufacture-name.
  lv_str = |{ lw_manufacture-name }: |.
  LOOP AT GROUP lw_manufacture INTO lw_manufacture_group.
    lv_str = COND #( WHEN sy-tabix = 1 
                     THEN |{ lv_str } { lw_manufacture_group-description }|
                     ELSE |{ lv_str },{ lw_manufacture_group-description }| ).
  ENDLOOP.  
  WRITE / lv_str.  
ENDLOOP.

another way is use REDUCE, I updated the answer here.