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: 

hai everybody

Former Member
0 Kudos

what is the difference between 'at new' & 'on change of'

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi

at new is used only in loop....endloop.

but on change of is used in any where like select...endselect and do...enddo and while.....endwhile.

regards,

uttam.

6 REPLIES 6

Former Member
0 Kudos

hi

at new is used only in loop....endloop.

but on change of is used in any where like select...endselect and do...enddo and while.....endwhile.

regards,

uttam.

Former Member
0 Kudos

Hi,

Here's the difference between At-new and On-change of...

At-New will trigger for every change in the values of the fields to the left of the field and the field it self where as On-change of will trigger only when there is change of the field value for that field.

For eg:

ITAB -- FLD1 FLD2 FLD3 FLD4

A B C D

A BB C D

A BB CC D

AA BB C D

AA BB CC DD

AA BBB CC DD

In the above example, On change of FLD2 is triggered for 3 times i.e

for ROW 1 --- when value of FLD2 is 'B',

ROW 2 --- when the value of FLD2 is 'BB' ( The field value for FLD2

was changed in this case)

ROW 6 - when the value of FLD2 was again changed to 'BBB'

Always, On-change of triggers whenever there is a change in the field value.

Coming to At-New of FLD2... this is triggered 4 times . At-New considers the change in the field FLD2 as well as the change in the FLD1 value. At new considers any changes to that field and any field to the left of it i.e..

ROW1 -- FLD1 = 'A' , FLD2 = 'B'

ROW2 -- FLD1 = 'A', FLD2 = 'BB',

ROW4 -- FLD1 = 'AA', FLD2 = 'BB',

ROW6 -- FLD1 = 'AA', FLD2 = 'BBB'

To understand in a better way , you can consider all the fields to the left of the AT-NEW field and the AT-NEW field as a string and can compare the value.

Refer these threads to know the difference

Regards,

Sankar

Former Member
0 Kudos

Hi,

when a new record comes at new triggers.

atnew only used inside loop and endloop.

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.

Regards

Sudheer

former_member404244
Active Contributor
0 Kudos

hI,

'On change off' works on variabels. The 1st time the statement is reached a memory copy is made of the value. The next time the statement is reached, the current value is compared to the stored value. If there is a difference, the coding between ON... and ENDON. is executed. You can use this for a table workarea field, but if you have the table loop in a routine and the routine called several times, you can get unwanted results. (Check the value of the last loop with the value of the first new loop.)

The AT NEW (and others like AT END OF...) are specially for table loop processing. The coding between AT new FIELD and ANDAT is triggerd whenever a the field or any field defined to the left is changed. Your table should be sorted by all fields from the left up to the considered FIELD. Btw all fields to the right contain *, so it can be usefull to have a second workarea filled to be printed or what ever you want.

REGARDS,

Nagaraj

Former Member
0 Kudos

Hi,

<b>on change of</b> differs from <b>at new</b> in the following respects:

<b>on change of</b> 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 <b>on change of</b> 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.

Hope this helps.

Reward if helpful.

Regards,

Sipra

Former Member
0 Kudos

Hi

at new f: processed when f changes or one of the preceeding fields has just been changed

on change of:

SELECT * FROM T100

WHERE SPRSL = SY-LANGU

AND MSGNR < '010'

ORDER BY PRIMARY KEY.

ON CHANGE OF T100-ARBGB.

ULINE.

WRITE: / '**', T100-ARBGB, '**'.

ENDON.

WRITE: / T100-MSGNR, T100-TEXT.

ENDSELECT.

An example is provided on the top. Here all the records are selected from table T100 which meet the condition specified in WHERE clause. But before the ENDSELECT a lot of processing is done. Here when ever there is a change in the value of the ARBGB column, an Underline is written and also the value is written in a new line and then the next records are written.

The individual clauses and the way in which they combine are very important factors in the SELECT statement. Although it is a single statement like any other, beginning with the SELECT keyword and ending with a period, its division into clauses, and the ways in which they combine, make it more powerful than other statements. A single SELECT statement can perform functions ranging from simply reading a single line to executing a very complicated database query.