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

Control Break statements logic

Former Member
0 Likes
598

Consider table ITAB with three fields BELNR, TAX and AMOUNT. The body has the following records.

BELNR TAX(%) AMOUNT

doc1 12.5 1500

doc2 10.0 2000

doc3 10.0 2100

doc4 11.0 8900

doc4 11.0 900

doc4 12.0 7000

Needs to use the control break statements to add up the amounts for same TAX Rate for a particular DOC number.

What should be the logic?

I am using this. Is it correct?

loop at itab.

at new BELNR.

ENDAT.

at end of TAX.

sum.

endat.

endloop.

is it correct? if not, pls advice.

thanks

M A

1 ACCEPTED SOLUTION
Read only

former_member69765
Contributor
0 Likes
562

Not so difficult... Use COLLECT Statement.

Collect statement adds all the numeric fields for which the non-numeric fields are common..

consider this example.

Field1(Type C) Field2(Type C) Field3(Type N or any type that can be summed)

A1 B1 5

A1 B1 3

A2 B1 7

A2 B2 4

A2 B1 2

Loot at ITAB_1 into WA.

collect wa into ITAB_2

Endloop.

Now the ITAB_2 will look like this : A1 B1 8

A2 B1 9

A2 B2 4

This is what you want right....

Note : If the tax(%) field is type p.. it will be added... so u store it in a temp internal table with type c so that it does not adds up...

Hope this works... If it doesnt tell me.. I will explain in detail...

PS : Do F1 on collect and see if my explanation is not clear. Believe me this is the easiest way to do this..

And Plz reward points if you think your problem is answered.

Message was edited by:

Varun Verma

Consider table ITAB with three fields BELNR, TAX and AMOUNT. The body has the following records.

BELNR TAX(%) AMOUNT

doc1 12.5 1500

doc2 10.0 2000

doc3 10.0 2100

doc4 11.0 8900

doc4 11.0 900

doc4 12.0 7000

Needs to use the control break statements to add up the amounts for same TAX Rate for a particular DOC number.

What should be the logic?

I am using this. Is it correct?

loop at itab.

at new BELNR.

ENDAT.

at end of TAX.

sum.

endat.

endloop.

is it correct? if not, pls advice.

thanks

M A

4 REPLIES 4
Read only

Former Member
0 Likes
562

I think it is not correct.

First you need to sort the internal table and the SUM statement will not work for currency fields.

sort itab by belnr tax.

loop at itab.

l_index = sy-tabix.

l_amount = l_amount + amount.

at end of tax.

read table itab into wa_itab index l_index.

wa_itab-amount = l_amount.

append wa_itab to itab_final.

clear l_amount.

endat.

endloop.

Read only

venkata_ramisetti
Active Contributor
0 Likes
562

You are correct. AT END OF TAX will give you total of amounts.

loop at itab.

at new BELNR.

ENDAT.

at end of TAX.

sum.

endat.

endloop.

YOu will get values like follows

doc1 12.5 1500

doc2 10.0 2000

doc3 10.0 2100

doc4 11.0 9800

doc4 12.0 7000

Thanks

Ramakrishna

Message was edited by:

Ramakrishna Ramisetti

Read only

former_member69765
Contributor
0 Likes
563

Not so difficult... Use COLLECT Statement.

Collect statement adds all the numeric fields for which the non-numeric fields are common..

consider this example.

Field1(Type C) Field2(Type C) Field3(Type N or any type that can be summed)

A1 B1 5

A1 B1 3

A2 B1 7

A2 B2 4

A2 B1 2

Loot at ITAB_1 into WA.

collect wa into ITAB_2

Endloop.

Now the ITAB_2 will look like this : A1 B1 8

A2 B1 9

A2 B2 4

This is what you want right....

Note : If the tax(%) field is type p.. it will be added... so u store it in a temp internal table with type c so that it does not adds up...

Hope this works... If it doesnt tell me.. I will explain in detail...

PS : Do F1 on collect and see if my explanation is not clear. Believe me this is the easiest way to do this..

And Plz reward points if you think your problem is answered.

Message was edited by:

Varun Verma

Read only

0 Likes
562

Thanks a lot to all.

Thanks a ton to Varun.

I have resolved the issue with Varun's suggestion.