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: 

AT NEW f, AT END OF f in an inernal table Loop ?

Former Member
0 Kudos

I am trying to subtotal an amount in an internal table by KUNAG. I then want to write this out to the output file. (see code below)

When I run this in debug the AT NEW and the AT END OF of are executed for every loop pass even though the KUNAG value appears to be the same .

Any ideas?

J

LOOP AT it_report2.

AT new kunag.

l_netwr = 0.

ENDAT.

l_netwr = l_netwr + it_report2-netwr.

l_line = it_report2.

TRANSFER l_line TO p_ufile.

AT END OF kunag.

it_report4-netwr = l_netwr.

l_line = it_report4.

TRANSFER l_line TO p_ufile.

ENDAT.

ENDLOOP.

6 REPLIES 6

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Makes sure that the table is sorting by the KUNAG. You can clear l_netwr at the end of the KUNAG, no need to do it at NEW.



<b>sort it_report2 ascending by kunag.</b>

LOOP AT it_report2.


l_netwr = l_netwr + it_report2-netwr.
l_line = it_report2.
TRANSFER l_line TO p_ufile.

AT END OF kunag.
it_report4-netwr = l_netwr.
l_line = it_report4.
TRANSFER l_line TO p_ufile.
l_netwr = 0.
ENDAT.

ENDLOOP.



Regards

Rich Heilman

Former Member
0 Kudos

hi,

did u sort the table???if yes...

did u sort it with kunag??

0 Kudos

Sorry, I should have included that information.

I do have the table sorted by KUNAG.

J

0 Kudos

What is the structure of it_report2?

Regards,

Rich Heilman

Former Member
0 Kudos

What Exactly is ur table structure. can u tell me this?

And one more thing are u using any where condition in Loop statement?

0 Kudos

I have solved the problem. I did not realize I needed KUNAG as the left most field.

thanks J