Skip to Content
author's profile photo Former Member
Former Member

sort internal table

Hello All,

I am having a internal table with fields vbeln (1st field) and matnr(2nd field). which are sorted by

vbeln and matnr. Now there is a fresh requirement that i have to display a total on change on matnr.

How can i do it in the same loop 😔 i am restricted to use another loop for it?.

Is there any way?

Thanks

SDN

Add comment
10|10000 characters needed characters exceeded

9 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2006 at 01:41 PM

    Hai,

    Sort matnr(2nd field)--> First

    and then Vbeln(Ist Field) --> Second

    Thanks & regards

    Sreeni

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2006 at 01:41 PM

    You have to loop at the table and calculate the totals using the AT NEW event provided it is SORTED by MATNR.

    regards

    Ravi

    Note : Please mark all the helpful answers

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2006 at 01:42 PM

    loop at itab.

    at new matnr.

    sum.

    ...

    ...

    endloop.

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 02, 2006 at 01:42 PM
    data: xtab like line of itab.
    
    loop at itab.
    
    xtab = itab.
    
    total = total + xtab-kwmeng.
    
    at end of matnr.
    Write:/ total.
    clear total.
    endat.
    
    endloop.

    Regards,

    Rich Heilman

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2006 at 01:44 PM

    try this, just changing the SORT order

    sort itab by matnr vbeln.

    regards

    srikanth

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2006 at 01:46 PM

    ---If not wrong you wish to have the total on material and not document+material ..correct ---in that case

    please note AT Event wont work for MATNR since you have the first field in your table as VBELN. So even if the Matnr is same but different VBELN...the at event would be triggered.

    The only way is to SORT the table with MATNR and VBELN.

    and use the on change event...as shown below. Unfortunately you would need a separate loop.

    sort itab by matnr vbeln.

    loop at itab.

    l_sum = l_sum + qty.

    on change of matnr.

    write : / l_sum.

    clear l_sum.

    endon.

    endloop.

    Message was edited by: Anurag Bankley

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2006 at 01:46 PM

    Hi Sdn,

    Try with this code.

    <b>SORT ITAB BY MATNR VBELN.</b>

    <b>LOOP AT ITAB.</b>

    AT END OF MATNR.

    <b>SUM.</b>

    WRITE:/ ITAB-MATNR, ITAB-QTY.

    ENDAT.

    <b>ENDLOOP.</b>

    Thanks,

    Vinay

    Message was edited by: Vinaykumar G

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2006 at 01:54 PM

    Try this.

    Loop at itab.

    at new matnr.

    sum.

    write: itab-(field to be totaled)

    endat.

    Endloop.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 02, 2006 at 02:02 PM

    HI,

    Sort the second field first.

    Regards,

    Laxmi.

    Add comment
    10|10000 characters needed characters exceeded