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

CONTROL BREAK EVENTS

Former Member
0 Likes
943

Hi Experts,

Could you please Explain me below questions.

1.What is the difference between AT NEW and ON CHANGE OF?

2.What is the problem we are getting when we use At NEW?

Thanks & Regards,

Gopi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
899

Hi

When we use At new for a field, it will trigger whenever there is any change in al lthe fields from the left to that of the particular field. But when we use On change of it triggers only when there is any change in the particular field.

At new can only be used inside loop. On change of can used outside the loop.

No logical Expressions can be added with at new. Logical expressions like AND OR can be used with on change of.

When AT NEW occurs, the alpha-numeric fields have * in their value,where as in case of On Change, the alphanumeric fields have their Corresponding value, of that particular record, where the Event gets fired.

On Change of executes for the first value of field too, this is not the case with At New.

On change of cannot be used in ABAP objects At new can be used in this.

here are the differences...

1 .On change of can use in any LOOP Construct...

For Ex.

Select...Endselect, Do...Enddo, While..Endwhile ,as well

as inside Get Events....

At new can use only with loop...endloop.

2 .When On change of used within loop a change in a field to

the left end of control level does not trigger a control break,

which is opposite to At new.

3. Can use Else in On change of, not in at new.

4. can use where condition with On change of, not in at new

5. can use sum with On change of. It sums all numeric field

expect the one(s) named after of.

7 REPLIES 7
Read only

ak_upadhyay
Contributor
0 Likes
899

Hi,

the difference between at new and on change of is when you specify the field name in at new <fieldname> and if there are fields to the left of the fieldname specified in at new then the code will be excuted below the at new even if teh value of <fieldname> does not changes. where as in case of on change of <fieldname> even if you have fields towardsleft of the fieldname specified in on change of then the change of value in left of fields will not trigger the code below on change of , only the <fieldname> values has to changed to trigger the code below the on change of.

you can make use of EXIT command to skip the inner loops based on condition.

Reward points if useful....

Regards

AK

Read only

Former Member
0 Likes
899

hi

see this program you can understand very easily

  • Using AT FIRST , AT NEW, AT THE END OF , AT LAST.

DATA: BEGIN OF ITAB OCCURS 0,

F1 TYPE I,

F2(6) TYPE C,

F3(10) TYPE N,

F4(16) TYPE P DECIMALS 2,

END OF ITAB.

DATA: SUB_TOT(10) TYPE P DECIMALS 3.

**--1

ITAB-F1 = 1.

ITAB-F2 = 'ONE'.

ITAB-F3 = 10.

ITAB-F4 = '1000.00'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 1.

ITAB-F2 = 'ONE'.

ITAB-F3 = 20.

ITAB-F4 = '2000.00'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 1.

ITAB-F2 = 'ONE'.

ITAB-F3 = 30.

ITAB-F4 = '3000.00'.

APPEND ITAB.

CLEAR ITAB.

*--2

ITAB-F1 = 2.

ITAB-F2 = 'TWO'.

ITAB-F3 = 10.

ITAB-F4 = '1000.00'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 2.

ITAB-F2 = 'TWO'.

ITAB-F3 = 20.

ITAB-F4 = '2000.00'.

APPEND ITAB.

CLEAR ITAB.

*-- 3

ITAB-F1 = 3.

ITAB-F2 = 'THREE'.

ITAB-F3 = 10.

ITAB-F4 = '1000.00'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 3.

ITAB-F2 = 'THREE'.

ITAB-F3 = 20.

ITAB-F4 = '2000.00'.

APPEND ITAB.

CLEAR ITAB.

SORT ITAB BY F1.

LOOP AT ITAB.

AT FIRST.

WRITE: /35 ' MATERIAL DETAILS:'.

ULINE.

ENDAT.

AT NEW F1.

WRITE: / 'DETAILS OF MATERIAL:' COLOR 7 , ITAB-F1.

ULINE.

ENDAT.

WRITE: / ITAB-F1, ITAB-F2, ITAB-F3, ITAB-F4.

SUB_TOT = SUB_TOT + ITAB-F4.

AT END OF F1.

ULINE.

WRITE: / 'SUB TOTAL :' COLOR 3 INVERSE ON, SUB_TOT COLOR 3 INVERSE ON.

CLEAR SUB_TOT.

ENDAT.

AT LAST.

SUM.

ULINE.

WRITE: 'SUM:', ITAB-F4.

ULINE.

ENDAT.

ENDLOOP.

Read only

Former Member
0 Likes
900

Hi

When we use At new for a field, it will trigger whenever there is any change in al lthe fields from the left to that of the particular field. But when we use On change of it triggers only when there is any change in the particular field.

At new can only be used inside loop. On change of can used outside the loop.

No logical Expressions can be added with at new. Logical expressions like AND OR can be used with on change of.

When AT NEW occurs, the alpha-numeric fields have * in their value,where as in case of On Change, the alphanumeric fields have their Corresponding value, of that particular record, where the Event gets fired.

On Change of executes for the first value of field too, this is not the case with At New.

On change of cannot be used in ABAP objects At new can be used in this.

here are the differences...

1 .On change of can use in any LOOP Construct...

For Ex.

Select...Endselect, Do...Enddo, While..Endwhile ,as well

as inside Get Events....

At new can use only with loop...endloop.

2 .When On change of used within loop a change in a field to

the left end of control level does not trigger a control break,

which is opposite to At new.

3. Can use Else in On change of, not in at new.

4. can use where condition with On change of, not in at new

5. can use sum with On change of. It sums all numeric field

expect the one(s) named after of.

Read only

Former Member
0 Likes
899

hi,

Select Single * from and select Upto 1 rows

At new - on change of difference: In case if you want calculate sub totals for same values in a field you can use the atnew statement.ie:

For example in a table sflight, there are 2 fields carrid ( airline id) and seatsmax( seat available). In case if you want calculate the total number of seats available for each carrrid you can sort the table first and using the at new and sum you can claculate the total seats for each carrid. Atnew will be triggered whenever there is a change in the carrid and the total seats will be returned for each carrid.

In the same scenario if you use onchange of it will not return the total seats for each carrid, instead it will return the total seat count for the entire table( ie: for all the carrids in the table. Another diffrence is atnew can be used only between loop and end loop whereas on change of can also be used in select- endselect , do -enddo. Another diffrence is while using atnew in case if you code any write statements between atnew and end at the value for the numeric fields will be returned as 0 and that of no numeric fields will be returned as *(asteriks). But in on change of the orginal values will be returned. Select single * and select upto 1 row diffrence.

The select single * from stmt selects only one row form the database table and puts it in to the work area(internal table). The select upto n(where n stands for a integer number) rows stmt selects all the rows from the database table but writes only the specified number of rows specified by the n into the internal table. If its given as upto 1 rows only 1 row is written in to the internal table.

Thank u,

Manjula Devi.D

Read only

Former Member
0 Likes
899

AT NEW ....

1. The field for which u want the break ... it should be the first field else ... the fields above it will also cause breaks at every change in their value ...

for example.

u have 3 fields ....

emp no 11 12 12

emp cd 21 21 22

emp id 31 31 31

if we write ...

at new emp id

endat.

even if emp id is not changing AT NEW will be triggered thrice ...

BUT THIS NOT THE CASE FOR " ON CHANGE " .

2. If we mention the write statement in the at new block mentioning fields that are towards the right of it .... just contains ***** (astris) or spaces ....

so for this we need to use a read statement just after atnew statement ...

this is not the case of ON CHANGE OF ...

emp no

emp cd

emp id

emp name

at new empid

WRIte emp id.

write emp name.

endat.

emp name will come in the form of " ASTRICS " .

3. We can use ON CHANGE for more than one field ...

WHich is not possible in AT NEW ...

for eg ....

At new emp id.

endat.

on change empid emp cd ....

endon.

Read only

Former Member
0 Likes
899

to detect a change on a perticular field and left side of that field then only AT NEW triggered

where in case of ON CHANGE OF, to detect a change on a perticular field then only it can triggered

Read only

Former Member
0 Likes
899

How can i find which smartforms are using a particular smart style