‎2007 Jun 26 12:00 PM
Hi,
What is the difference between the statements AT FIRST AT NEW and mainly ON CHANGE OF.
Thanks
Uma
‎2007 Jun 26 12:02 PM
Hi..,
AT FIRST, AT NEW, AT END OF are group based operations.... work on group of fields...
<b>data :
begin of tab occurs 0,
f1,
f2,
f3,
end of tab.
</b>
Now ... fill the table tab with some data.
<b>loop at tab.
at new f3.
-
block----
endat.
endloop.</b>
The block will get executed either of the three fields changes...
But....
<b>loop at tab.
on change of f3.
-
block----
endon.
endloop.</b>
The block will get executed only when the field f3 changes...
ON CHANGE OF works on the single fields ....
regards,
sai ramesh
‎2007 Jun 26 12:02 PM
Hi..,
AT FIRST, AT NEW, AT END OF are group based operations.... work on group of fields...
<b>data :
begin of tab occurs 0,
f1,
f2,
f3,
end of tab.
</b>
Now ... fill the table tab with some data.
<b>loop at tab.
at new f3.
-
block----
endat.
endloop.</b>
The block will get executed either of the three fields changes...
But....
<b>loop at tab.
on change of f3.
-
block----
endon.
endloop.</b>
The block will get executed only when the field f3 changes...
ON CHANGE OF works on the single fields ....
regards,
sai ramesh
‎2007 Jun 26 12:02 PM
Hi,
please have a look at the below link.
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/at_itab.htm
Regards,
Nagaraj
‎2007 Jun 26 12:02 PM
hi,
chk this from help....
LOOP AT itab result ...
[AT FIRST.
...
ENDAT.]
[AT NEW comp1.
...
ENDAT.
[AT NEW comp2.
...
ENDAT.
[...]]]
[ ... ]
[[[...]
AT END OF comp2.
...
ENDAT.]
AT END OF comp1.
...
ENDAT.]
[AT LAST.
...
ENDAT.]
ENDLOOP.
Extras:
1. ... FIRST
2. ... |{END OF} comp 3. ... LAST Effect The statement block of a LOOP loop can contain control structures for control level processing. The respective control statement is AT. The statements AT and ENDAT define statement blocks that are executed at control breaks. Within these statement blocks, the statement SUM can be specified to total numeric components of a group level. In the case of output behavior result, the same applies as for LOOP AT. So that group level processing can be executed correctly, the following rules should be noted: After LOOP there should be no limiting condition cond specified. The internal table must not be modified within the LOOP loop. The work area wa specified in the LOOP statement after the INTO addition must be compatible with the line type of the table. The content of a work area wa specified in the LOOP statement after the INTO addition must not be modified. The prerequisite for control level processing is that the internal table is sorted in exactly the same sequence as the component of its line type - that is, first in accordance with the first component, then in accordance with the second component, and so on. The line structure and the corresponding sorting sequence gives a group structure of the content of the internal table, whose levels can be evaluated using AT statements. The AT-ENDAT control structures must be aligned one after the other, in accordance with the group structure. The statement blocks within the AT-ENDAT control structures are listed if an appropriate control break is made in the current table line. Statements in the LOOP-ENDLOOP control structure that are not executed within an AT-ENDAT control structure are executed each time the loop is run through. If the INTO addition is used in the LOOP statement to assign the content of the current line to a work area wa, its content is changed upon entry into the AT-ENDAT control structure as follows: The components of the current group key will remain unchanged. All components with a character-type, flat data type to the right of the current group key are set to character "*" at that position. All the other components to the right of the current group key are set to their initial value. When the AT-ENDAT control structure is exited, the content of the current table line is assigned to the entire work area wa. Note If the INTO addition is used in the LOOP statement, a field symbol can be specified outside of the classes after AT |{END OF}. The appropriate component of the work area wa is assigned to this field symbol.
Addition 1
... FIRST
Effect
First line of the internal table.
Addition 2
... |{END OF} comp
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.
Addition 3
... LAST
Effect
The last line of the internal table.
regards,
priya.
‎2007 Jun 26 12:03 PM
AT First - will triger only once in a loop
AT New - will triger whenever new value is coming(difference bet all old and this new)
On change of - will triger whenever the old value is changing( difference between previous val and new val) this u can use inside any loop not only in control break.
‎2007 Jun 26 12:03 PM
Hi Shri Ram,
a) 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..
Thanks,
Reward If Helpful.
‎2007 Jun 26 12:04 PM
at first is triggered in the first loop pass.
At New <field1> is triggered when a new value of field is found including all fields to the left of field1.
on change of can be used any where in the code like do enddo while etc but At new is used only inside a loop at <itab>.
Reward if useful.
Regards abhi
‎2007 Jun 26 12:05 PM
HI,
AT FIRST WILL DISPLAY THE CHANGES MADE TO A FIELD MADE AT THE SATARTING OF A REPORT LIKE HEADER DATA OF A REPORT
AT NEW WILL DISPLAY THE CHANGES MADE TO A FIELD IN A TABLE AND IT WILL GREY OUT THE REMAINING FIELDS
THESE BOTH WILL WORK ONLY IN LOOP CONDITION.
ON CHANGE OF WILL DISPLAY ALL THE CHANGED RECORDS IT WILL NOT GREAY OUT THE OTHER RECORDS AND IT WILL WORK OUTSIDE THE LOOP ALSO.
‎2007 Jun 26 12:07 PM
Hi,
AT FIRST - First line of the internal table
AT NEW and ON CHANGE OF have another critical differance between them other than what are replied so far.
and it is...
in a table's key....while using AT NEW <temp> if any of the field on the left side of temp changes...though temp is the same AT NEW will trigger...
It will make key of feilds starting from leftmost field till the <temp> field and it will mark all the fields on right of <temp> with an asteric (*).
means...say for example these are the records in itab...
Field1 Field2 Field3 Field4
A P X V
A G M N
B G K L
no suppose i use AT NEW Field2.
then on 3rd record also thi will trigegr as the key of all the fields on left of Field2 has changes .
and in case of using ON CHANGE OF Field2 it will just see for the specified filed not other fields on left side of it in key..
Some other info:
Both of them are triggeredwhile the control break level changes, but he functionality changes for both depending on the situation.
1. On change of unlike at new can be used inside any loop construct.
2. Suppose if we trigger the event based on the second field , on change of will not respond to the changes int he first record. It only triggers for changes in the specific field unlike at new which also triggers for every change in the left hand side field of the record also.
3. Also for on change of does not trigger if the first record in the loop is empty unlike at new.
These are the main and useful differences.
Regards,
Padmam.
‎2007 Jun 26 12:07 PM
Hi Shri,
<b>AT NEW f.</b> 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 within 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.
<b>AT FIRST</b>
The processing block between AT FIRST and ENDAT is executed before the individual lines are processed; the processing block between AT LAST and ENDAT is executed after all the individual lines have been processed.
When you are processing extract datasets, a control total SUM(n) can only be processed with AT END OF or AT LAST.
<b>ON CHANGE OF f</b>
Executes the processing block enclosed by the "ON CHANGE OF f" and "ENDON" statements whenever the contents of the field f change (control break processing).
Normally, you use the statement to manipulate database fields during GET events or SELECT/ENDSELECT processing.
Regards,
Sree.
PS: Reward points if Useful.