11-21-2008 3:24 AM
Hi,
Is it a good practice to use NESTED 'AT NEW' command in a loop?
I have an internal table with fields say obj1, obj2, obj3, amount.
Now, for new obj1,
for every new obj2 in a obj1
for every new obj3 in obj2 , sum the amount
Please suggest if I can I use nested AT NEW for this?
Thanks.
11-21-2008 3:31 AM
Hi,
Nesting of Internal Table Control Level Processing events is not possible.
Any AT Statement has to be finished by ENDAT only.....you cannot write two AT without having an ENDAT between them....
11-21-2008 3:39 AM
Thanks for your reply.
In that case will sorting of internal table on obj1, obj2, obj3 and using AT NEW -ENDAT for obj3,
serve the purpose?
11-21-2008 3:40 AM
Hi,
It will not work.
One more thing Suppose you have three fields f1,f2,f3.
Now, for new f1,
for every new f2 in a f1
for every new f3 in f2 , sum the amount
then you write
AT NEW f3.
SUM.
END AT.
Regards
Sandipan
11-21-2008 5:28 AM
Hi.
suppose the internal table itab contains fields obj1 obj2 obj3 amount in order.
sort itab by obj1 obj2 obj3.
loop at itab into wa.
at new obj3.
sum.
endat.
endloop.
Check whether it works.
Regards,
chris Gu
11-21-2008 5:41 AM
Hi,
if you have three fields obj1,obj2,obj3 and provided they all are not the char fields then if you apply
AT NEW command at obj3 it will automatically consider all the previous fields i.e. obj1 and obj2 also
for ex. suppose you have
obj1 | obj2|obj3|
-
1|1|1
1|1|2
1|2|2
2|2|2
in this case although you have put AT NEW at obj3 but it will consider the combination of Three.
so in this case AT NEW will be executed 4 times because combination of all three is changing everytime.
So, no need to cide for
"Now, for new obj1,
for every new obj2 in a obj1
for every new obj3 in obj2 "
11-21-2008 5:45 AM
Hi vatsala,
to best of my knowlege,
once you used at new keyword all the char fields right of the fields become stars(asterick) so using nested will not work for you. as suggested by GU please sort by the order and use it.
regards
Ramchander Rao.K