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

Problem in Control break statement

Former Member
0 Likes
898

hi all,

i have a doubt regarding AT NEW and ON CHANGE. i have an ITAB and i have to calculate subtotal with respect to MATNR..

WERKS MATNR MENGE

BILF AB 4

BILF AB 2

DLFF AB 6

DLFF XY 5

BILR XY 5

BILR EF 5

can anyone plz tell me that what shud i use AT NEW or ON CHANGE and which will trigger how much times?

Regards saurabh.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
867

Hi Saurabh,

on change of will trigger 3 times..

when matnr is AB, XY,EF.

on change of is an obsolete control structure..

AT NEW will also consider the fields to the left of MATNR in the given structure.

it takes combination of WERKS MATNR & triggers 5 times..

BILF AB

DLFF AB

DLFF XY

BILR XY

BILR EF

Regards,

Mdi.Deeba

6 REPLIES 6
Read only

Former Member
0 Likes
867

Hi,

In respect to the internal table structure that you had provided try like below:



loop at itab.<<<same structure and data as you provided 
at end of matnr.
sum.
 write:/ itab-mantr, itab-menge.    <<<this will write the subtotal for the material.
endat.
endloop.

Regards,

Himanshu

Read only

Former Member
0 Likes
867

Hi,

AT END Or AT NEW trigeres when any field (including tat field) on the left of that field changes.

That is in ur case if u use at new it wil get trigered if werks or matnr changes..

but that is not ur requirement..

so for ur requirement u need to use on change of matnr..

but on change is obsolete..

so wht u can do is chagne the order of the internal table such that matnr becomes the first field. and then use AT NEW or AT END

Regards

Ansari

Read only

Former Member
0 Likes
867

HI,

MAKE use of AT-NEW.

SORT the internal table by werks and matnr and then use AT NEW.

But within AT NEW the MENGE will have value as '*' in the work area.

So before AT NEW pass the contents into a separate work area.

You can make use of COLLECT statement instead.

Sort your internal table on the basis of werks and matnr.

Then LOOP on it and COLLECT into another internal table of the same type.

Regards,

Ankur Parab

Read only

Former Member
0 Likes
867

You can use At new or At end statement in this situation. But you need to keep one this in mind if you are workin on ECC then at new or at end statement chnage all the content on workarea as ***** so avoid this situation either use field symbols or take another workarea and move the content of orignal workarea into the new one and use this new work area fro printing.

Loop at itab assign to <wa_itab>.

at new.....

endat.

endloop.

Loop at itab into wa_itab.

wa_itab1 = wa_itab.

at new.......

use the value of wa_itab1 to avoid *****

endat.

endloop

Also keep the thing suggested by Ansari in mind while using these statements.

You can also use collect statement, collect statement sum all the numeric fields on the basis on key fields. For more information on collect see F1 help.

Read only

Former Member
0 Likes
868

Hi Saurabh,

on change of will trigger 3 times..

when matnr is AB, XY,EF.

on change of is an obsolete control structure..

AT NEW will also consider the fields to the left of MATNR in the given structure.

it takes combination of WERKS MATNR & triggers 5 times..

BILF AB

DLFF AB

DLFF XY

BILR XY

BILR EF

Regards,

Mdi.Deeba

Read only

venkat_o
Active Contributor
0 Likes
867

Hi, <li> If you want to have subtotal of MATNR , You should not use AT NEW and ON CHANGE OF. ON CHANGE OF is obsolete. <li> You need to use AT END OF statement. <li> Before that , Table needs to be sorted. <li>Try this way


DATA: BEGIN OF it_marc OCCURS 0,
        werks TYPE marc-werks,
        matnr TYPE marc-matnr,
        eisbe TYPE marc-eisbe,
        mabst TYPE marc-mabst,
      END OF it_marc.

START-OF-SELECTION.
  SELECT * FROM marc INTO CORRESPONDING FIELDS OF TABLE it_marc UP TO 2000 ROWS.
  SORT it_marc BY werks matnr.
  LOOP AT it_marc.
    AT END OF matnr.
      SUM.
      WRITE:/ it_marc-werks, it_marc-matnr, it_marc-eisbe, it_marc-mabst.
    ENDAT.
  ENDLOOP.
Thanks Venkat.O