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.
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
Add a comment