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

AT end--at

Former Member
0 Likes
1,860

Gurus,

I have a typical situation. I want to perform certain logic whenever a new document is encountered

in a internal table. The new document definition is a combination of BELNR and GHJAR.

Internal table i_out has following data for example:

BELNR......GJHAR

225........2003

225........2003

226........2003

226........2005

So in above case, there are total three invoice documents:

1) 225....2003

2) 226....2003

3) 226....2005

I have the logic like below

sort i_out by belnr gjhar.

loop at i_out.

at end of belnr.

perform total_amount_cal_for_individual_invoices.

end at.

endloop.

But if I do like this, then total amount calculation for individual invoices is done only two time based on belnr of 225 and 226. I want the logic to consider GJHAR also along with BELNR. If the GJHAR is different for the same invoice number then it should consider it as a different document.

Please help.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,747

Rajesh,

uset statement

at end of gjahr.

endat.

You can also replace your routine, with just sum statement to get the total.

Refer to help for SUM statement.

Regards,

Mahesh

Gurus,

I have a typical situation. I want to perform certain logic whenever a new document is encountered

in a internal table. The new document definition is a combination of BELNR and GHJAR.

Internal table i_out has following data for example:

BELNR......GJHAR

225........2003

225........2003

226........2003

226........2005

So in above case, there are total three invoice documents:

1) 225....2003

2) 226....2003

3) 226....2005

I have the logic like below

sort i_out by belnr gjhar.

loop at i_out.

at end of belnr.

perform total_amount_cal_for_individual_invoices.

end at.

endloop.

But if I do like this, then total amount calculation for individual invoices is done only two time based on belnr of 225 and 226. I want the logic to consider GJHAR also along with BELNR. If the GJHAR is different for the same invoice number then it should consider it as a different document.

Please help.

13 REPLIES 13
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,747

Just work AT the last key, not the first, that will fulfill your requirement.

AT END OF gjahr
PERFORM total_amount_cal_for_individual_invoices.
ENDAT.

A change of BELNR causes a change of GJAHR, just check that BELNR is before GJAHR in the table, as it is in BKPF ([Processing Table Entries in Loops|http://help.sap.com/erp2005_ehp_03/helpdata/EN/fc/eb381a358411d1829f0000e829fbfe/frameset.htm])

Regards

Read only

Former Member
0 Likes
1,747

Hi Rajesh,

Just change the

at end of belnr to at end of gjahr.

Doing so, the combination of belnr and gjahr is taken into consideration. So, whenever the combination changes, the required calculation is performed under at end of.

Now your code looks like this:

sort i_out by belnr gjhar.

loop at i_out.

at end of gjahr.
perform total_amount_cal_for_individual_invoices.
end at.

endloop.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
1,747

Hi Rajesh,

It is

At end of gjhar not at end of belnr in your case...

change it and check it out

regards

padma

Read only

Former Member
0 Likes
1,747

make sure gjhar should be next field to Belnr in the internal table.

belnr,gjhar,.....

sort itab by belnr gjhar.

loop at itab.

at end of gjhar.
"here you can code your logic. 
endat.

endloop.

Read only

Former Member
0 Likes
1,747

as also told by others do it as follow:

sort i_out by belnr gjhar.

loop at i_out.

at end of gjhar.
perform total_amount_cal_for_individual_invoices.
end at.

endloop.

As here it will take the combination of belnr gjhar where as in your previous case it was only considering for belnr .

With luck,

Pritam.

Read only

Former Member
0 Likes
1,748

Rajesh,

uset statement

at end of gjahr.

endat.

You can also replace your routine, with just sum statement to get the total.

Refer to help for SUM statement.

Regards,

Mahesh

Read only

0 Likes
1,747

at end og gjhar is not going to work because if the internal tables has data as follows then it would be a problem:

225........2003

225........2003

226........2003

226........2005

227........2005

228........2005

So fi I use at end of gjhar, then it would do the perform for only two documents, when it should do for actually for five.

1) 225....2003

2) 226....2003

3) 226....2005

4) 227....2005

5) 228....2005

Please provide any insights...

Read only

0 Likes
1,747

AT end of gjhar will not work because if I have following situation, then instead of doing perform for five documents separately it will do only for two based on 2003 and 2005

225........2003

225........2003

226........2003

226........2005

227........2005

228........2005

Please provide any insight

Read only

0 Likes
1,747

Hi Thomas,

AT END OF will take into account the field you specify and all fields before it. So in your case the AT END OF GJAHR will work correctly. You could also change the structure of your table and make GJAHR the first field and BELNR the second and keep the AT logic as you had it. Either way would work, just give the documents in a different order.

Hope this helps,

Gert.

Read only

0 Likes
1,747

do your calculation that the sum before the at end

loop at itab..

sum = sum + field.

  at end of field2.
    write: sum.
    clear sum.
  endat.
endloop.

With luck,

Pritam.

Read only

0 Likes
1,747

Hi Rajesh,

at end of GJAHR will work properly and it performs for 5 times. because at end of always triger when the given field value changes (GJAHR) or its left hand side field value changes (BELNR).

BELNR GJAHR

225........2003

225........2003 <--1

226........2003 <--2

226........2005 <--3

227........2005 <--4

228........2005 <--5

I have placed the arrows whenever AT END OF GJAHR triggers.

1st time it trigger coz BELNR (225) is the last occurance.

2nd time it trigger coz GJAHR(2003) is the last occurance.

3rd time it trigger coz BELNR (226) is the last occurance.

4th time it trigger coz BELNR (227) is the last occurance.

5th time it trigger coz GJAHR (2005) is the last occurance.

Thanks.

<removed_by_moderator>

Khan

Edited by: Julius Bussche on Sep 1, 2008 8:35 AM

Read only

0 Likes
1,747

As i wrote, AT END OF GJAHR will work, if BELNR is before in SORT order AND in structure.

Regards

Read only

Former Member
0 Likes
1,747

hi.

inspite of control break statement use following logic:

sort it_itab by belnr gjhar.

delete adjacent duplicates from it_itab comparing belnr gjhar.

it will give you your desired record in it_itab. than

LOOP AT it_itab INTO wa_itab.

your calculation.

ENDLOOP.

hope this will help you.