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

At New

Former Member
0 Likes
536

Hi,

How does at new in the below code works? Thanks a lot!

LOOP AT i_sku_components1 FROM v_index3.

IF i_sku_components1-arbpl = i_link-arbpl.

v_index3 = v_index3 + 1.

AT NEW code.

sum.

x_alv_resource-arbpl = i_alv_sku-arbpl.

x_alv_resource-plnbez = i_alv_sku-plnbez.

x_alv_resource-code = i_alv_sku-code.

x_alv_resource-descr = i_alv_sku-descr.

x_alv_resource-uom = i_alv_sku-uom.

x_alv_resource-actqty = i_alv_sku-actqty.

x_alv_resource-actval = i_alv_sku-actval.

x_alv_resource-plnqty = i_alv_sku-plnqty.

x_alv_resource-plnval = i_alv_sku-plnval.

x_alv_resource-usage = i_alv_sku-usage.

x_alv_resource-cost = i_alv_sku-cost.

x_alv_resource-plnrte = i_alv_sku-plnrte.

x_alv_resource-vari = i_alv_sku-vari.

ENDAT.

ELSE.

EXIT.

ENDIF.

Rgds,

Mark

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
517

Hi Mark.

Assuming your internal table is sorted by CODE, what you're basically saying in your AT NEW clause is: everytime a value break is reached (from 1 to 2, for instance), the AT NEW..... ENDAT placed code will be executed.

Now, it is advisable that you separate your event handlings (AT....) from your logical handlings (IFs...).

For instance, in your case, you should place your "IF" condition inside the "AT NEW" event. That should make your code clearer, and prevent unexpected results.

An important point is: If your internal table is not sorted by COD, AT NEW won't have the expected effect...

Hope it may have helped!

Hi,

How does at new in the below code works? Thanks a lot!

LOOP AT i_sku_components1 FROM v_index3.

IF i_sku_components1-arbpl = i_link-arbpl.

v_index3 = v_index3 + 1.

AT NEW code.

sum.

x_alv_resource-arbpl = i_alv_sku-arbpl.

x_alv_resource-plnbez = i_alv_sku-plnbez.

x_alv_resource-code = i_alv_sku-code.

x_alv_resource-descr = i_alv_sku-descr.

x_alv_resource-uom = i_alv_sku-uom.

x_alv_resource-actqty = i_alv_sku-actqty.

x_alv_resource-actval = i_alv_sku-actval.

x_alv_resource-plnqty = i_alv_sku-plnqty.

x_alv_resource-plnval = i_alv_sku-plnval.

x_alv_resource-usage = i_alv_sku-usage.

x_alv_resource-cost = i_alv_sku-cost.

x_alv_resource-plnrte = i_alv_sku-plnrte.

x_alv_resource-vari = i_alv_sku-vari.

ENDAT.

ELSE.

EXIT.

ENDIF.

Rgds,

Mark

3 REPLIES 3
Read only

Former Member
0 Likes
517

check the simple example..

ztable has 2 columns one alph and neumeric.

alph------neu

a----


1

a----


5

b----


2

b----


4

c----


3

now.

data: it type standard table of ztable with header.

loop at it.

at new alph.

write: it-alph.

endat.

endloop.

the output is

1

2

3

For every new coloumn specified, the AT event is executed.

Reward if helpful.

Thanks.

Imran.

Read only

Sm1tje
Active Contributor
0 Likes
517

Mark,

I recommend NOT to use IF combined with AT NEW, this could give very unexpected results.

I can't reproduce your code here, but again, not recommended.

Additional info: I'm not saying it isn't going to work, but it is not recommended.

p.s. When using the EXIT in the LOOP you will exit the loop. In this case looks to me that a CONTINUE would be better. But of course, I don't know your requirement in detail.

Edited by: Micky Oestreich on Apr 17, 2008 3:45 PM

Read only

Former Member
0 Likes
518

Hi Mark.

Assuming your internal table is sorted by CODE, what you're basically saying in your AT NEW clause is: everytime a value break is reached (from 1 to 2, for instance), the AT NEW..... ENDAT placed code will be executed.

Now, it is advisable that you separate your event handlings (AT....) from your logical handlings (IFs...).

For instance, in your case, you should place your "IF" condition inside the "AT NEW" event. That should make your code clearer, and prevent unexpected results.

An important point is: If your internal table is not sorted by COD, AT NEW won't have the expected effect...

Hope it may have helped!