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

Need Control Break statement Logic for the Below example.

former_member815151
Discoverer
0 Likes
1,138

in my internal table the data's are like this .

5888 10 C 100

5888 10 C 30

5888 10 D 20

5888 20 D 50

5888 30 D 100

5888 30 D 100

5890 10 C 50

5890 10 C 50

5890 20 C 100

5890 20 D 50

5890 20 D 20

5890 40 C 100

5890 40 D 30

5892 20 C 20

5892 30 D 10

5892 30 D 10

5892 30 D 10

5892 40 D 10

5892 40 C 10

5892 40 C 10

5892 40 C 10

its needs to be like .

Doc number Doc item Balance

5888 10 110

5888 20 50

5888 30 -200

Sub Total -40

Doc number Doc item Balance

5890 10 100

5890 20 30

5890 40 -70

Sub Total 60

Doc number Doc item Balance

5892 20 20

5892 30 -30

5892 40 20

Sub Total 10

Grand Total -50

3 REPLIES 3
Read only

Sandra_Rossi
Active Contributor
1,068

The answer will be different according to how you render the result. Is it ALV? Something else?

Or is it just homework? In that case, what is your problem with looping at the lines, doing the sum if same doc number and same doc item, doing the subtotal or the grand total?

Read only

venkateswaran_k
Active Contributor
0 Likes
1,068
jeniljeff

You can use loop - endloop : Within that COLLECT statement.

Read only

anujawani242683
Active Participant
0 Likes
1,068

Hi jeniljeff

Please find syntax below.make sure when you use control break statement, sort internal table by fields which are used with control break statement.
sort it_tab ascending by filed_name1 field_name2.
Loop at it_tab into wa_tab.
at new field_name1(Doc_Number) field_name2(C,D..) .
write:/ Doc_number.
endat.
write: doc_item.
at end of field_name1(Doc_Number) field_name2(C,D..)
sum.
write: Balance.
total = total + balance.
endat.
endloop.
write:/ 'Grand Total is',total.