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 new picking even the same values

Former Member
0 Kudos
216

hi all,

my code is as follows:

LOOP AT gt_bseg INTO gs_bseg.

AT NEW xref1.

gv_count = gv_count + 1.

ENDAT.

ENDLOOP.

Note : the field xref1 is not the first field of the internal table. even for the same value of xref1 the count is getting incremented.

What can be the solution.

Any help will be appriciated with points.

Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos
196

hi,

If the at NEW field is not the first one, for example if it is second field then it consider the <b>combination</b> <b>of first two fields</b> and checks its is new or not.

sudheer.A

16 REPLIES 16

Former Member
0 Kudos
196

i thnk u need to sort it before looping into it.

Hope this will solve ur problem..

<b><u>Dont forget to reward all the useful replies</u></b>

Sudheer

alex_m
Active Contributor
0 Kudos
196

Because the left fields of xref1 changes this AT New will execute, so change like this.

SORT gt_bseg by xref1.

LOOP AT gt_bseg INTO gs_bseg.

AT LAST xref1.

gv_count = gv_count + 1.

ENDAT.

ENDLOOP.

Former Member
0 Kudos
197

hi,

If the at NEW field is not the first one, for example if it is second field then it consider the <b>combination</b> <b>of first two fields</b> and checks its is new or not.

sudheer.A

0 Kudos
196

hi sudheer,

i have sorted the table based on xref1.

can u elaborate on combination of two fields??

0 Kudos
196

Hi,

According to me, he means the all the field including field on which AT NEW is used & previous fields in internal table.

Thanks

Sandeep

0 Kudos
196

Hello..

No need of any sorting...Change your Internal Table Structure by making xref1 as the first field..Then use your old code..this will work..i am sure...Read my previous query carefully..

Reward All helpfull answers....

0 Kudos
196

internal table structure is just as the same of bseg.

ie. data : gt_bseg type standard table of bseg,

and i cant this structure by declaring my own types also.

Moreover, while selecting i have to select the fields in order as they are in table bseg.

So how shall i make xref1 as first field??

0 Kudos
196

have you tried my solution?.

0 Kudos
196

Hi..

u dont have to sort the table, instead make that field as the first field in ur internal table or try using ON CHANGE OF instead of AT NEW.this works..

Thanks and Regards,

Kamal Kumar.

0 Kudos
196

Hi

I got your problem..Just try with On Change Of gt_bseg-xref1 instead of at-new.

Anyway u can't use at-new in this condition...If On change of is working its ok..Ur problem solved..If this is not working write back with your error..

Regards

Biju

0 Kudos
196

hi alexander,

i tried ur code.

Its incrementing the gv_count only at last.

that means always it will have 1 ie. always gv_count will be 1.

Moreover, at last xref1, is not correct.

it has to be only at last. and not as at last xref1.

Thanks for ur concern. any other way out??

0 Kudos
196

Try to use ON CHANGE OF and see the result.

Former Member
0 Kudos
196

Hi,

if the previous field in itab changes, AT NEW event gets triggered. try to use at last.

Thanks

sandeep

Reward if helpful

Former Member
0 Kudos
196

Hi

The problem is At-New will trigger whenever the control level will changes..As per u told xref1 is not the first field in th internal table, gv_count will increment whenever any of the field will change that coming before xref1..

ex..

matnr werks xref1

suppose this is thestructure of ur itab..then whenever matnr or werks or xref1 changes at-new will trigger..

hope u got the problem..

Reward All the Helpfull Answers..........

Former Member
0 Kudos
196

hi,

then give on change of 'field name' instead of at new.

for at new to work properly the fld should be the 1st field oterwise it wont work properly.

change code as

LOOP AT gt_bseg INTO gs_bseg.

on change of xref1.

gv_count = gv_count + 1.

ENDAT.

ENDLOOP.

if helpful reward some points.

with regards,

suresh babu aluri.

Former Member
0 Kudos
196

thanks to all for ur help extended.

The problem got solved using on-change of...

But still this is going to create an issue for Extended Program Check as this is obsolute statement.