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: 

Use of nested AT NEW in a loop.

Former Member
0 Kudos

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.

6 REPLIES 6

Former Member
0 Kudos

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....

0 Kudos

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?

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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 "

former_member1245113
Active Contributor
0 Kudos

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