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: 

AT commands in abap

Former Member
0 Kudos

hi experts,

i m new to abap.

i've created an internal table of type LFA1 in which i've selected the data for column LIFNR NAME1 ORT01. i've to calculate total no. of cities.

i've written the following code:

sort it_lfa1.

loop at it_lfa1.

at new ort01.

count = count + 1.

endat.

endloop.

but i find in debugger that the control passes every time through at new statement and hence count gets every time incremented and not at new city (ORT01). in this case i've to take the dictionary type LFA1 and i can't create my local type so that i can pass to smartform. neither at new nor at end of is working.

plz help.

7 REPLIES 7

Former Member
0 Kudos

Hi Annie,

The AT NEW statement will get triggered whenever there is a change in the previous table fields also.

It is always better to have ORT01 as the first field in the internal table for the AT NEW to function as per your req.

Otherwise you could use ON CHANGE OF it_lfa1-ort01 instead of AT NEW.

sort it_lfa1.

loop at it_lfa1.

ON CHANGE OF it_lfa1-ort01.

count = count + 1.

endon.

endloop.

andreas_mann3
Active Contributor
0 Kudos

hi,

table must be sorted by ort01

(ort01 must be 1st row in your table)

A.

Former Member
0 Kudos

Annie ,

sort it_lfa1 by ort01 name1.

Hope your program will work.

Pls. mark if useful

Former Member
0 Kudos

Hi Annie,

When you use at new ort001, here in your itab, ORT01 is the third field. At new does consider the fields that are left to column ORT01. Hence evreytime it goes into the at new statement as fields that are left to ORT01 might be changing.

You can have ORT01 as first filed and count the number of cities.

Also have a look at below link.

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/at_itab.htm

I hope it helps.

Best Regards,

Vibha

*Please mark all the helpful answers

former_member181962
Active Contributor
0 Kudos

Hi Annie,

It wil not work if ORT01 is not the first field in the internal table.

Consider this work around.

sort it_lfa1.

loop at it_lfa1.

if lv_ort01 <> it_lfa1-ort01.

count = count + 1.

clear lv_ort01.

else.

clear count.

endif.

lv_ort01 = it_lfa1-ort01.

endloop.

Former Member
0 Kudos

AT NEW IS TRIGGERING FOR THE CONTROL FIELD AND ANY CHANGE IN KEY FIELD LEFT OF THAT CONTROL FIELD.

BY DEFAULT ITAB CONTAINS KEY FIELDS WHICH HAVE THE DATA TYPE C,N,D,T,X.

SO,

SUPPOSE YOUR ITAB

AT NEW F2.

F1 F2

A X-------TRIGGER(1ST ROW)

B X----


TRIGGER(LEFT VALUE CHANGE)

B X

C X----


TRIGGER(LEFT VALUE CHANGE)

C Y----


TRIGGER(CONTROL FIELD VALUE CHANGE)

HOPE IT WILL HELP.

REGARDS

SHIBA DUTTA

Former Member
0 Kudos

Hello,

Your internal table must be sorted on ort01 and also the column ort01 must be 1st column in your internal table. Because the AT command depends on the previous column. If the previous column changes for each then the AT NEW control command will be executed every time.

Regs,

Venkat Ramanan N