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 new and on change of

Former Member
0 Kudos

Hi Friends,

can any one explain ,

1) what is main difference between at new and on change of

control break statements...

2) in which situation we are supposed use on change of control beark.

cheers,

9 REPLIES 9

Former Member
0 Kudos

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

Former Member
0 Kudos

hi vijay,

if u use 'at-new' statement , basically it dont pick first record of the itab where as 'on chage of' can pick from first record.

all these control brake statements can work with header line except 'on change of' event.

regards..

seshu.

Former Member
0 Kudos

Hi,

At New.

Effect

Beginning or end of a group of lines with the same content in the component comp1 comp2 ... and in the components to the left of comp1 comp2 .... The components comp1 comp2 ... can be specified, as described in the section Specification of Components, with the limitation that access to object attributes is not possible here.

Example:

LOOP AT itab result ... 
    [AT NEW comp1. 
       ... 
     ENDAT. 
endloop.

On Change of:

Effect:

The statements ON CHANGE OF and ENDON, which are forbidden in classes, define a control structure that can contain a statement block statement_block. After ON CHANGE OF, any number of data objects dobj1, dobj2... of any data type can be added..

Example:

In a SELECT loop, a statement block should only be executed if the content of the column CARRID has changed.

DATA spfli_wa TYPE spfli. 
SELECT * 
       FROM spfli 
       INTO spfli_wa 
       ORDER BY carrid. 
  ... 
  ON CHANGE OF spfli_wa-carrid. 
    ... 
  ENDON. 
  ... 
ENDSELECT.

Former Member
0 Kudos

Hi,

plz refer this thread

Regards

Nilesh

Former Member
0 Kudos

hi vijay...

AT NEW used to display the fields.

ON CHANGE OF it creates one more variable internally and check with the variable of the internal table. if different event is triggered,initial value should mis-match. Used in DO, WHILE, LOOP AT..

generally we dont go for on change of.

Former Member
0 Kudos

Following are the basic differences between at new and on change of.

1.at new can be written inside loop and endloop where as on change of can be used in any loops like select --endselect,do enddo,case endcase.

2.whenever the left side records of variable on which we placed at new are changed at new triggers

where as it won't be triggered unless that particular variable value changed.

ex: data:begin of itab occurs 0,

v1 type string,

v2 type i,

v3 type string,

end of itab.

itab-v1 = '123'.

itab-v2 = '1000'.

itab-v3 = 'xyz'.

append itab.

itab-v1 = 'abc'.

itab-v2 = '2000'.

itab-v3 = 'xyz'.

append itab.

itab-v1 = 'def'.

itab-v2 = '2000'.

itab-v3 = 'ghi'.

append itab.

loop at itab.

write: itab-v1,

itab-v2,

itab-v3.

at new v2.

write: 'Value changed'.

endat.

on change of itab-v2.

write:'onchange of result'.

endon.

endloop.

*output is:123 1,000 xyz at new result

onchange of result

abc 2,000 xyz

at new result

def 2,000 ghi

3.at new is control break statement where as onchnge of not

4.In on change of for every variable one auxiliary variable will be created in memory.

If any thing not understood or u want any further info let me know

Regards,

Sri Ramya G.

Former Member
0 Kudos

Hi Vijay,

Let us understand these events by an example.

suppose you are displaying some records from mara.. Material no, material type , palnt etc.

Now when we use AT-NEW event for matnr, this event will be triggered, whenever there is any change in any of the fields we have selected for output like material no, material type, plant

while in case of ' change of matnr' this event will be invoked only when there is a change in material no or new material has been inserted

regards

Vinod

Former Member
0 Kudos

Hello Vijay,

At new only used inside loop and endloop.

On change of works same like at-new but the difference is it can

be used out side of a loop,like select and endselect,case

endcase.

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

Ref below link to see the sequence & more details-

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/content.htm

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/5ac31178-0701-0010-469a-b4d7fa27...

search for word 'on change of'

Thank You,

Nishikant.

Former Member
0 Kudos

Vijay ,

Control Break Event AT- NEW :

Event AT-NEW will be triggered whenever the control level changes or any field prior to the control level changes.

For Example:

DATA : BEGIN OF IT_TAB OCCURS 0,

A(5),

B(5),

C(5),

END OF ITAB.

Insert some Values to the internal table.

SORT IT_TAB.

LOOP AT IT_TAB,

AT NEW A.

<Only when value of A Changes.>

ENDAT

AT NEW B.

<When Combined vales of A & B Changes i.e either A or B Or both>.

ENDAT.

1) Sorting of the INTERNAL TABLE is necessary.

2) You cannot use multiple fields in AT-NEW statement.

3) Between AT-NEW and ENDAT the content of work area will not contain any value

4) If you change the value of a work area within AT-NEW and ENDAT your changes will be lost after the ENDAT statement.

5) When AT NEW occurs, the alpha-numeric fields have ******* in their value

6) Can be used in ABAP objects

ON-CHANGE-OF :

On Change of will be triggered whenever the control level changes.

It won't be triggered when the field prior to the control level change.

For Example:

DATA : BEGIN OF IT_TAB OCCURS 0,

A(5),

B(5),

C(5),

END OF ITAB.

Insert some Values to the Internal table.

LOOP AT IT_TAB,

On CHANGE OF B.

< Every time a value of B changes >

ENDON.

ENDLOOP.

1) Sorting of the INTERNAL TABLE is NOT necessary.

2) Mutilpe Fields are used in ON-CHANGE-OF

3) 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.

4) In ON CHANGE,the alpha-numeric fields have their corresponding value, of that particular record, where the Event gets fired.

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

6) You can use else between on change of and endon.

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

8) cannot be used in ABAP objects

Regards,

Shiv.G.Sethu