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 END OF and AT NEW fails ...

Former Member
0 Kudos

Hi,

I have a program where i am looping an internal table (say detail table with 3 liens) which has got a column named hdrid with same values. Another table say header exists wit hthe same hdrid, just one record.

In my code I say

LOOP AT t_detail INTO wa_detail.

...

...

AT NEW hdrid.

ENDAT.

AT END OF hdrid.

ENDAT.

ENDLOOP.

Now it so happens that when looping thru my detail table, the AT END OF hdrid is supposed to trigger only when that column in the detail table changes which is like after the 3rd record. But it is triggering when the first record is read !! Also the AT NEW hdrid is also triggering for every record in the detail table !! What could be wrong ? I debugged and checked the value, it is the same as I expected , say 827789. Only when that value changes these two must be triggered..Any tips ?

thks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

make sure you sort the table before you loop it. Sort the table as below.

if HDRID is first field in the internal table then

sort HDRID field2 field3.....

if HDRID is second field in the internal table then

sort field1 HDRID field3.....

if HDRID is third field in the internal table then

sort field1 field2 HDRID .....

and so on.............

5 REPLIES 5

former_member195698
Active Contributor
0 Kudos

The field HDRID should be the first field in your internal table...

AT NEW field1 -- this takes all the field to the LEFT of field1 (including field1) while determining the NEW RECORD

Former Member
0 Kudos

In your table t_detail try to put the field HDRID how the frist field.


DATA: BEGIN OF t_detail,
             hdrid type ...,
             field2 type ...,
             field3 type ...,
          END OF t_detail.

P561888
Active Contributor
0 Kudos

Hi ,

Using the AT NEW and AT LAST in the Loop is:

First say itab1 we have the 5 fields at that time if u do this it will consider the left fields that i means u r writing the at new field3 . but here it will consider the first 2 left fields also ,,so better declare one internal table seperately to use the AT LAST or AT END OF of ....

Reagrds,

Bharani

Former Member
0 Kudos

make sure you sort the table before you loop it. Sort the table as below.

if HDRID is first field in the internal table then

sort HDRID field2 field3.....

if HDRID is second field in the internal table then

sort field1 HDRID field3.....

if HDRID is third field in the internal table then

sort field1 field2 HDRID .....

and so on.............

Former Member
0 Kudos

My question is, why does sap continues to support this instructions? I've seen several programs that have them and do everything wrong.

If it is not possible to do a break in the right place why don't they check it before compiling?