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

loop events

Former Member
0 Likes
672

plz explain about at end of? and give me nice example?diff at new and at end of..

6 REPLIES 6
Read only

Former Member
0 Likes
636

Imagine if ur itab contains

NUMBER

100 -1st

100 -2nd

100 -3rd

200 -4th

200 -5th

AT NEW number - will be trigerred for 1st & 4th

AT END OF number - will be trigerred for 3rd & 5th

Read only

suresh_datti
Active Contributor
0 Likes
636

PL check this <a href="https://forums.sdn.sap.com/click.jspa?searchID=3171568&messageID=3369924">Thread</a>.

~Suresh

Read only

Former Member
0 Likes
636

Hi

At-new will trigger at the starting of a change and At-End-Of will trigger at the end of that change...Thats all..

See the Simple example given below..

it-f1.

aa -> at-new will trigger here

aa ->at-end-of will trigger here

ss ->at-new

ss

ss

ss ->at-end

dd ->at-new

dd

dd

dd->at-end.

Hope u understood.. Also if you give SUM. command after at-end-of you will get all sum of all integer and float type fields. You can try this also.

Reward All Helpfull Answers..

Read only

Former Member
0 Likes
636

See the example code :

DATA: sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate,

sflight_wa LIKE LINE OF sflight_tab.

SELECT *

FROM sflight

INTO TABLE sflight_tab.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

AT END OF carrid.

SUM.

ULINE.

WRITE: / 'Carrier Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

NEW-PAGE.

ENDAT.

AT LAST.

SUM.

WRITE: / 'Overall Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

ENDAT.

ENDLOOP.

Reward points if it is helpful

Thanks

Seshu

Read only

Former Member
0 Likes
636

Hi

Suppose if u are displaying report like material details. IF customer wants a total for each material then in this case u should use At end of.

FORM display_records2 .

SORT gt_ibrostmp1 BY zzasco.

CLEAR: gv_total_count, gv_total_amount.

  • Display the selected records from internal table gt_vvscpos.

LOOP AT gt_ibrostmp1 INTO gs_ibrostmp1.

  • If new ASCO company code comes then clear the gv_count and gv_total_amount

AT NEW zzasco.

CLEAR: gv_count,gv_total_amount.

gv_count = 0.

gv_total_amount = 0.

ENDAT.

  • Calculate the no.of records and total amount for each ASCO Company code

gv_count = gv_count + 1.

gv_total_amount = gv_total_amount + gs_ibrostmp1-total.

  • At end of each ASCO Company code, display the total no.of record and amount

AT END OF zzasco.

WRITE:/ sy-vline, 6 gs_ibrostmp1-zzasco COLOR COL_KEY,

30 sy-vline, 31 gv_count COLOR COL_NORMAL,

45 sy-vline, 46 gv_total_amount COLOR COL_NORMAL,

80 sy-vline.

  • calculate the total no.of records and total amount

gv_total_count = gv_total_count + gv_count.

gv_total_amount1 = gv_total_amount1 + gv_total_amount.

ENDAT.

  • At last display the total no.of records and total amount

AT LAST.

ULINE (80).

WRITE:/ sy-vline, 'Total'(001) COLOR COL_KEY,

30 sy-vline, 31 gv_total_count COLOR COL_TOTAL,

45 sy-vline, 46 gv_total_amount1 COLOR COL_TOTAL,

80 sy-vline.

ENDAT.

ENDLOOP.

ULINE (80).

ENDFORM. " display_records2

Reward me if its useful..

Regards

Ravi

Read only

Former Member
0 Likes
636

Hi Ram,

This is the SAP documentation on AT END OF and AT NEW.

AT NEW f.

AT END OF f.

Effect

f is a sub-field of an internal table or extract dataset (EXTRACT) which is being processed with LOOP, i.e. the variants 1 and 2 only make sense within a LOOP.

Both "AT NEW f." and "AT END OF f. " introduce processing blocks which are concluded by " ENDAT.".

These processing blocks are processed whenever the contents of a field f or a sub-field defined before f change as a result of processing with LOOP. "AT NEW f." begins a new group of (table) lines with the same contents as the field f while "AT END OF f." concludes such a group.

Within the AT ... ENDAT processing of internal tables, all argument fields following f are filled with "*".

Examples

1. AT for sub-fields of an internal table

DATA: BEGIN OF COMPANIES OCCURS 20,

NAME(30),

PRODUCT(20),

SALES TYPE I,

END OF COMPANIES.

...

LOOP AT COMPANIES.

AT NEW NAME.

NEW-PAGE.

WRITE / COMPANIES-NAME.

ENDAT.

WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.

AT END OF NAME.

SUM.

WRITE: / COMPANIES-NAME, COMPANIES-SALES.

ENDAT.

ENDLOOP.

The AT statements refer to the field COMPANIES-NAME.

Examples

2. AT for the field of an extract dataset

DATA: NAME(30),

SALES TYPE I.

FIELD-GROUPS: HEADER, INFOS.

INSERT: NAME INTO HEADER,

SALES INTO INFOS.

...

LOOP.

AT NEW NAME.

NEW-PAGE.

ENDAT.

...

AT END OF NAME.

WRITE: / NAME, SUM(SALES).

ENDAT.

ENDLOOP.

Notes

1.If the processing you want to perform on an internal table is fairly restricted (i.e. a WHERE addition with the LOOP statement), do not use the AT statements specified in variants 1 to 5, since the interaction of the WHERE addition and the AT statement is currently not defined.

2.When you use LOOP with an extract dataset, fields on hex zero are ignored during control level checking with AT NEW or AT END OF . This procedure is the same as the SORT statement. When sorting extracted datasets, this statement always sorts blank fields (i.e. fields on hex zero) regardless of the sequence (ascending or descending) before all fields that contain values.

3.Since fields addressed with AT are not set to an initial value when you enter a LOOP, the first new group of (table) lines in AT NEW f may not be processed, if f happens to be set to this value.

Regards

Anil Madhavan