cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

"AT NEW" problem

former_member220801
Participant
0 Kudos
52

I have tried the following:

SORT ITAB BY FIELD1 FIELD2 FIELD3.

LOOP AT ITAB.

AT NEW FIELD1.

WRITE πŸ˜• FIELD1.

ENDAT.

(other fields are output here)

ENDLOOP.

However, FIELD1 is output for every record in itab.

When I tried,

LOOP AT ITAB.

IF ITAB-FIELD1 <> PREVIOUS_FIELD1_VALUE.

WRITE πŸ˜• FIELD1.

ENDIF.

(other fields are output here)

PREVIOUS_FIELD1_VALUE = ITAB-FIELD1.

ENDLOOP.

field1 is written only when there is a change in value of field1.

I wonder the field value comparison in "AT NEW" will be interrupt by my logic that output other field values...

Are there any functions that I need to avoid to use in order to have "AT NEW" works properly?

P.S. my codes under "AT NEW" are mainly "WRITE AT ..." and some logicial comparison like (IF...ENDIF)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

In "AT NEW" when u specify it on a field if any field on left of it changes it will trigger at new.

In your case u might have defined FIELD1 on 2,3 ...or any position.

Try to use ON CHANGE.

Thanks & Regards,

Ankur

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi ,

Your At new should work fine as long as u have sorted the table fine. there should be no difference in prnting the data in both cases. It should be the same. Pls check the data. See this code. Paste it and execute...

REPORT Z_SC_TEST_ATNEW .

data: begin of itab occurs 0,

field1,

field2,

field3,

end of itab.

data: PREVIOUS_FIELD1_VALUE.

start-of-selection.

itab-field1 = 1.

itab-field2 = 2.

itab-field3 = 1.

append itab.

itab-field2 = 1.

itab-field3 = 2.

append itab.

itab-field2 = 2.

itab-field3 = 3.

append itab.

itab-field1 = 2.

itab-field2 = 2.

itab-field3 = 4.

append itab.

SORT ITAB BY FIELD1 FIELD2 FIELD3.

LOOP AT ITAB.

AT NEW FIELD1.

WRITE πŸ˜• 'Field1', itab-FIELD1.

ENDAT.

WRITE πŸ˜• 'Field2', itab-FIELD2, 'Field3', itab-FIELD3.

ENDLOOP.

uline at /0(40).

WRITE :/'Another way'.

LOOP AT ITAB.

IF ITAB-FIELD1 <> PREVIOUS_FIELD1_VALUE.

WRITE πŸ˜• itab-FIELD1.

ENDIF.

WRITE πŸ˜• 'Field2', itab-FIELD2, 'Field3', itab-FIELD3.

PREVIOUS_FIELD1_VALUE = ITAB-FIELD1.

ENDLOOP.

Former Member
0 Kudos

HI

SORT ITAB BY FIELD1 FIELD2 FIELD3.

LOOP AT ITAB.

on change of FIELD1.

WRITE πŸ˜• FIELD1.

endon.

(other fields are output here)

ENDLOOP.

regards

kishore

Former Member
0 Kudos

Hi,

It also depends upon where is you field1 positioned in the declaration of ITAB. If you are using AT NEW field1, then ensure that it is the first field in the declaration.

Regards,

Srikanth

Former Member
0 Kudos

HI Gundam

AT new

in the loop will trigger in field1 if there is a change in field 1 and even if there is a change in the fields before field1 i.e to the left of field.

so you can use ON CHANGE of <field1>

this is work perfectly

regards

kishore

Former Member
0 Kudos

Hi,

Check in the ITAB definition the order in which your fields are.

Ex.

types: begin of t_itab

field2 like ..

field1 like ..

field3 like...

end of t_itab.

data: itab type standard table of t_itab with header line.

if you sort the table and then loop if you try AT NEW FIELD1 it will enter everytime field2 and field1 is changed because field2 is previous. Check it in debbuging mode.

Hope it helps.

Regards.

Former Member
0 Kudos

Hi,

Check the order of fields in your ITAB.

I think FIELD1 is not the first field in your ITAB.

Regards,

GSR.

Former Member
0 Kudos

Hi,

Instead of AT NEW i think you can try this.

ON CHANGE OF..

ENDON.

Thanks.

If this helps you reward with points.