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

Regarding Control break events

Former Member
0 Likes
929

What is the difference between AT NEW & ON CHANGE OF events?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
727

When AT NEW occurs,

the alpha-numeric fields have ******* in their value,

b) where as in case of ON CHANGE,

the alpha-numeric fields have their corresponding value,

of that particular record,

where the Event gets fired.*----


Other differences are :

ON CHANGE OF can be used any where in the program..

on change of differs from at new in the following respects:

1.It can be used in any loop construct, not just loop at. For example, it can be used within select and endselect, do and enddo, or while and endwhile, as well as inside get events.

2.A single on change of can be triggered by a change within one or more fields named after of and separated by or. These fields can be elementary fields or field strings. If you are within a loop, these fields do not have to belong to the loop.

3.When used within a loop, a change in a field to the left of the control level does not trigger a control break.

4.When used within a loop, fields to the right still contain their original values; they are not changed to contain zeros or asterisks.

5.You can use else between on change of and endon.

6.You can use it with loop at it where . . ..

7.You can use sum with on change of. It sums all numeric fields except the one(s) named after of.

8.Any values changed within on change of remain changed after endon. The contents of the header line are not restored as they are for at and endat.

while

AT NEW can be used only within a loop of an INTERNAL TABLE..

*----


5. Sample program to get the taste of it

(just copy paste)

6.

REPORT ABC.

DATA : BEGIN OF ITAB OCCURS 0,

bukrs like t001-bukrs,

f1(10) type c,

end of itab.

itab-bukrs = '1000'.

itab-f1 = '1111111'.

append itab.

itab-bukrs = '1100'.

itab-f1 = '3333333'.

append itab.

itab-bukrs = '1200'.

itab-f1 = '555555'.

append itab.

AT NEW

loop at itab.

at new bukrs.

write 😕 itab-bukrs , itab-f1.

endat.

endloop.

AT ONCHANGE

loop at itab.

ON CHANGE OF ITAB-BUKRS.

write 😕 itab-bukrs , itab-f1.

ENDON.

endloop.

check these threads..

At New

1. When a new record comes at new triggers. Atnew only used inside loop and endloop.

2. At new is controlbreak statment on at new the left side field change, the event

trigers and the values become 0 and *

On Change

1. On change of works same like at-new but the diff is it can be used out side of a loop,like select and endselect,case endcase.

2.. on change of is not a control break statement and we can use onchange of out side the loop

and

The Major difference between the two is that AT NEW can be used ONLY for INTERNAL TABLES, while ON CHANGE OF can be used for any loop processing i.e do..enddo, while..endwhile and loop..endloop also.

At New

1. When a new record comes at new triggers. Atnew only used inside loop and endloop.

2. At new is controlbreak statment on at new the left side field change, the event

trigers and the values become 0 and *

On Change

1. On change of works same like at-new but the diff is it can be used out side of a loop,like select and endselect,case endcase.

2.. on change of is not a control break statement and we can use onchange of out side the loop

and

The Major difference between the two is that AT NEW can be used ONLY for INTERNAL TABLES, while ON CHANGE OF can be used for any loop processing i.e do..enddo, while..endwhile and loop..endloop also.

AT NEW <field>

The block will be executed when the SY-TABIX is 1 (or) when the SY-TABIX 1 value has a change with the SY-TABIX value.

With this block the field towards the right to the field are not accessable with in the block, and are shown with '*'. They can be accessed outside the block.

ON CHANGE OF <itab>-<field>

The block also works similar to the AT First. In this block all the fields are accesseble.

ON CHANGE OF triggers whenever there is a change in that particular field.

AT NEW triggers whenever there is a change in the fields before that particular field.ie. if there is a change in that combinations from the first field.

Please see the below link for your query :

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/at-new-vs-on-change-of-586600

rewards if helpful

3 REPLIES 3
Read only

Former Member
0 Likes
728

When AT NEW occurs,

the alpha-numeric fields have ******* in their value,

b) where as in case of ON CHANGE,

the alpha-numeric fields have their corresponding value,

of that particular record,

where the Event gets fired.*----


Other differences are :

ON CHANGE OF can be used any where in the program..

on change of differs from at new in the following respects:

1.It can be used in any loop construct, not just loop at. For example, it can be used within select and endselect, do and enddo, or while and endwhile, as well as inside get events.

2.A single on change of can be triggered by a change within one or more fields named after of and separated by or. These fields can be elementary fields or field strings. If you are within a loop, these fields do not have to belong to the loop.

3.When used within a loop, a change in a field to the left of the control level does not trigger a control break.

4.When used within a loop, fields to the right still contain their original values; they are not changed to contain zeros or asterisks.

5.You can use else between on change of and endon.

6.You can use it with loop at it where . . ..

7.You can use sum with on change of. It sums all numeric fields except the one(s) named after of.

8.Any values changed within on change of remain changed after endon. The contents of the header line are not restored as they are for at and endat.

while

AT NEW can be used only within a loop of an INTERNAL TABLE..

*----


5. Sample program to get the taste of it

(just copy paste)

6.

REPORT ABC.

DATA : BEGIN OF ITAB OCCURS 0,

bukrs like t001-bukrs,

f1(10) type c,

end of itab.

itab-bukrs = '1000'.

itab-f1 = '1111111'.

append itab.

itab-bukrs = '1100'.

itab-f1 = '3333333'.

append itab.

itab-bukrs = '1200'.

itab-f1 = '555555'.

append itab.

AT NEW

loop at itab.

at new bukrs.

write 😕 itab-bukrs , itab-f1.

endat.

endloop.

AT ONCHANGE

loop at itab.

ON CHANGE OF ITAB-BUKRS.

write 😕 itab-bukrs , itab-f1.

ENDON.

endloop.

check these threads..

At New

1. When a new record comes at new triggers. Atnew only used inside loop and endloop.

2. At new is controlbreak statment on at new the left side field change, the event

trigers and the values become 0 and *

On Change

1. On change of works same like at-new but the diff is it can be used out side of a loop,like select and endselect,case endcase.

2.. on change of is not a control break statement and we can use onchange of out side the loop

and

The Major difference between the two is that AT NEW can be used ONLY for INTERNAL TABLES, while ON CHANGE OF can be used for any loop processing i.e do..enddo, while..endwhile and loop..endloop also.

At New

1. When a new record comes at new triggers. Atnew only used inside loop and endloop.

2. At new is controlbreak statment on at new the left side field change, the event

trigers and the values become 0 and *

On Change

1. On change of works same like at-new but the diff is it can be used out side of a loop,like select and endselect,case endcase.

2.. on change of is not a control break statement and we can use onchange of out side the loop

and

The Major difference between the two is that AT NEW can be used ONLY for INTERNAL TABLES, while ON CHANGE OF can be used for any loop processing i.e do..enddo, while..endwhile and loop..endloop also.

AT NEW <field>

The block will be executed when the SY-TABIX is 1 (or) when the SY-TABIX 1 value has a change with the SY-TABIX value.

With this block the field towards the right to the field are not accessable with in the block, and are shown with '*'. They can be accessed outside the block.

ON CHANGE OF <itab>-<field>

The block also works similar to the AT First. In this block all the fields are accesseble.

ON CHANGE OF triggers whenever there is a change in that particular field.

AT NEW triggers whenever there is a change in the fields before that particular field.ie. if there is a change in that combinations from the first field.

Please see the below link for your query :

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/at-new-vs-on-change-of-586600

rewards if helpful

Read only

0 Likes
727

Processing Control Levels

When you sort an extract dataset, control levels are defined in it. For general information about control levels, refer to Processing Internal Tables in Loops The control level hierarchy of an extract dataset corresponds to the sequence of the fields in the HEADER field group. After sorting, you can use the AT statement within a loop to program statement blocks that the system processes only at a control break, that is, when the control level changes.

AT NEW <f> | AT END OF <f>.

...

ENDAT.

A control break occurs when the value of the field <f> or a superior field in the current record has a different value from the previous record (AT NEW) or the subsequent record (AT END). Field <f> must be part of the HEADER field group.

If the extract dataset is not sorted, the AT... ENDAT block is never executed. Furthermore, all extract records with the value HEX 00 in the field <f> are ignored when the control breaks are determined.

The AT... ENDAT blocks in a loop are processed in the order in which they occur. This sequence should be the same as the sort sequence. This sequence must not necessarily be the sequence of the fields in the HEADER field group, but can also be the one determined in the SORT statement.

If you have sorted an extract dataset by the fields <f1>, <f2>, ..., the processing of the control levels should be written between the other control statements as follows:

LOOP.

AT FIRST.... ENDAT.

AT NEW <f1>....... ENDAT.

AT NEW <f2>....... ENDAT.

...

AT <fgi>..... ENDAT.

<single line processing without control statement>

...

AT END OF <f2>.... ENDAT.

AT END OF <f1>.... ENDAT.

AT LAST..... ENDAT.

ENDLOOP.

You do not have to use all of the statement blocks listed here, but only the ones you require.

REPORT DEMO.

DATA: T1(4), T2 TYPE I.

FIELD-GROUPS: HEADER.

INSERT T2 T1 INTO HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

T1 ='BBCC'. T2 = 2. EXTRACT HEADER.

T1 ='AAAA'. T2 = 2. EXTRACT HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

T1 ='BBBB'. T2 = 2. EXTRACT HEADER.

T1 ='BBCC'. T2 = 2. EXTRACT HEADER.

T1 ='AAAA'. T2 = 1. EXTRACT HEADER.

T1 ='BBBB'. T2 = 1. EXTRACT HEADER.

T1 ='AAAA'. T2 = 3. EXTRACT HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

SORT BY T1 T2.

LOOP.

AT FIRST.

WRITE 'Start of LOOP'.

ULINE.

ENDAT.

AT NEW T1.

WRITE / ' New T1:'.

ENDAT.

AT NEW T2.

WRITE / ' New T2:'.

ENDAT.

WRITE: /14 T1, T2.

AT END OF T2.

WRITE / 'End of T2'.

ENDAT.

AT END OF T1.

WRITE / 'End of T1'.

ENDAT.

AT LAST.

ULINE.

ENDAT.

ENDLOOP.

This program creates a sample extract, containing the fields of the HEADER field group only. After the sorting process, the extract dataset has several control breaks for the control levels T1 and T2, which are indicated in the following figure:

In the loop, the system displays the contents of the dataset and the control breaks it encountered as follows:

Below are the major differences between at new and on change of.

on change of differs from at new in the following respects:

It can be used in any loop construct, not just loop at. For example, it can be used within select and endselect, do and enddo, or while and endwhile, as well as inside get events.

A single on change of can be triggered by a change within one or more fields named after of and separated by or. These fields can be elementary fields or field strings. If you are within a loop, these fields do not have to belong to the loop.

When used within a loop, a change in a field to the left of the control level does not trigger a control break.

When used within a loop, fields to the right still contain their original values; they are not changed to contain zeros or asterisks.

You can use else between on change of and endon.

You can use it with loop at it where . . ..

You can use sum with on change of. It sums all numeric fields except the one(s) named after of.

Any values changed within on change of remain changed after endon. The contents of the header line are not restored as they are for at and endat.

Reward if helpful.

Read only

Former Member
0 Likes
727

Hi friend,

1.On change of can be used in any loop construct, not just loop at.

For example, it can be used within select and endselect, do

and enddo, or while and endwhile, as well as inside get events.

2. A single on change of can be triggered by a change within

one or more fields named after of and separated by or. These

fields can be elementary fields or field strings. If you are

within a loop, these fields do not have to belong to the loop.

3.When used within a loop, a change in a field to the left

of the control level does not trigger a control break.

4.When used within a loop, fields to the right still contain

their original values; they are not changed to contain zeros

or asterisks.

5.You can use else between on change of and endon.

6.You can use it with loop at it where . . ..

7. You can use sum with on change of. It sums all numeric

fields except the one(s) named after of.

8.Any values changed within on change of remain changed

after endon. The contents of the header line are not

restored as they are for at and endat.

Reward if useful.

Regards,

swetha.