2008 Jan 27 6:11 PM
As far as i understood, this command "AT NEW field" we use to process a block whenever the specified field is changed, but it's not working for me....
The content of the field is the same in the next loop and it keeps on processing this block....Why?
Can anyone explain it to me, please?
2008 Jan 28 11:14 AM
HI,
Misunderstandings about control statements:
The ON CHANGE OF statement can prove dangerous when not used correctly. Never compare it with AT NEW, while this context is strictly defined, the context of the ON CHANGE OF is not. It simply compares the content of the comparison field with its former content, at the exact location where it is executed. You can use the command anywhere in the program and it behaves complete independent from anything else. Better not to use it.
The LOOP AT itab statement in combination with control level statements (AT NEW) can also cause confusion. The processing is dependent on how the internal table is sorted and the order of the fields (use sorted table with sorting order is equal to the sort (key) fields in the table definition). The control level statement takes the field or all previous fields into account for checks on value change. It becomes even worse is you use the WHERE statement in the LOOP AT. So dont use control level statements if this is the case.
Regards,
Chaitanya.
HI,
Misunderstandings about control statements:
The ON CHANGE OF statement can prove dangerous when not used correctly. Never compare it with AT NEW, while this context is strictly defined, the context of the ON CHANGE OF is not. It simply compares the content of the comparison field with its former content, at the exact location where it is executed. You can use the command anywhere in the program and it behaves complete independent from anything else. Better not to use it.
The LOOP AT itab statement in combination with control level statements (AT NEW) can also cause confusion. The processing is dependent on how the internal table is sorted and the order of the fields (use sorted table with sorting order is equal to the sort (key) fields in the table definition). The control level statement takes the field or all previous fields into account for checks on value change. It becomes even worse is you use the WHERE statement in the LOOP AT. So dont use control level statements if this is the case.
Regards,
Chaitanya.
2008 Jan 27 6:16 PM
THAT FIELD SHOULD BE IN THE FIRST COLOUMN IN INTERNAL TABLE.
and it sould sorted on that field.
this is the pre-requisite for using AT NEW.
for ON CHANGE it is not required to be in first coloumn.
regsrds.
santhosh reddy
Reward if useful
Edited by: Santhosh Reddy on Jan 27, 2008 11:47 PM
2008 Jan 28 2:50 AM
Hi,
If you have 2 fields in the structure. ex:
begin of itab,
matnr type matnr,
werks type werks,
end of itab.
Sort itab by matnr werks.
Loop at itab.
AT NEW matnr.
END AT.
Endloop.
In the above logic, AT NEW is used on matnr value. it will be triggered when matnr value changes. (i.e., for every new material number it will be triggered.)
LOOP AT itab.
AT NEW werks.
ENDAT.
Endloop.
In the above logic, AT NEW is used on werks. This will be triggered for a new plant number. but as this field is the second field of the structure (matnr is the first field), hence even if plant is same for the next record, if material number changes, then also this will be triggered.
ex: matnr werks.
1001 700
1002 700
In the above case, during the second record execution also AT NEW werks will be triggered as matnr has been changed.
Hope its clear.
2008 Jan 28 3:04 AM
Hi Reethu,
In case of at new, it 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.
check this sample code.
data: begin of itab occurs 10,
no(5) type n,
id(10) type n,
name(20) type c,
F1(20) type c,
end of itab.
lets consider this IT has value like this,
No ID Name F1
1 100 abc hello
1 100 abc hi
3 300 abc test
4 400 lmn test1
at new name : it triggers for 1st and 4th record.
on chage of name : it triggers for 1st 3rd and 4th record since the values of combination for the fields no, id, name change inthose records.
hope it helps,
kindly reward if found helpful.
cheers.
Hema.
2008 Jan 28 3:45 AM
Hi
If you want the AT NEW logic for the field not in the first column of the structure .
Use On Change Of <field>
The code under this will be executed only when the content of field <field>
changes .
I hope it helps.
Praveen
2008 Jan 28 3:55 AM
Hi,
At new ll work only if the mentioned field is the first field of the int table......if it is the 4th field den
at new <4th fld> is same as at new<1st to 4th fld>
so use on change of as said above.
Cheers,
Will.
2008 Jan 28 4:02 AM
Hi Reethu,
1.Keep the field FIELD1 on which you have to do AT NEW in the last of your internal table structure.
2. Sort your internal Table keeping FIELD1 as the last field.
3. Now use AT NEW you will get perfect result.
2008 Jan 28 11:14 AM
HI,
Misunderstandings about control statements:
The ON CHANGE OF statement can prove dangerous when not used correctly. Never compare it with AT NEW, while this context is strictly defined, the context of the ON CHANGE OF is not. It simply compares the content of the comparison field with its former content, at the exact location where it is executed. You can use the command anywhere in the program and it behaves complete independent from anything else. Better not to use it.
The LOOP AT itab statement in combination with control level statements (AT NEW) can also cause confusion. The processing is dependent on how the internal table is sorted and the order of the fields (use sorted table with sorting order is equal to the sort (key) fields in the table definition). The control level statement takes the field or all previous fields into account for checks on value change. It becomes even worse is you use the WHERE statement in the LOOP AT. So dont use control level statements if this is the case.
Regards,
Chaitanya.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |