Skip to Content
avatar image
Former Member

internal table control break processing

Hi all,

My internal table is like this.

ProjID DocNo Amount Currency Date

A007 t123 300 USD 20.09.2007

A007 t123 500 INR 23.09.2007

A007 t123 800 USD 01.10.2007

A008 t124 300 USD 20.09.2007

the out put should be

A007 t123 1100 USD 01.10.2007

A007 t123 500 INR 23.09.2007

A008 t124 300 USD 20.09.2007

I have to add those record which have same Proj Id,Doc no,and currecy and populate latest date.

I am using the follwing logic.

LOOP AT it_invoice3.

on change of it_invoice3-pspid or it_invoice3-xblnr or it_invoice3-waers.

move it_invoice3 to it_invoice5.

append it_invoice5.

endon.

endloop.

LOOP AT it_invoice3.

at new waers.

sum.

move it_invoice3-invcoll_amt to it_invoice5-invcoll_amt .

modify it_invoice5 transporting invcoll_amt where xblnr = it_invoice3-xblnr.

endat.

ENDLOOP.

I am not getting the requied output. pls any one can suggest me right way to have the required output.

Regards

reddy

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Oct 05, 2007 at 12:07 PM

    Hi

    keep the Currency field as 3rd field in ITAB and

    SOrt the itab by project id , Doc No,currency

    use Loop at ITAB,.

    at end of currency.

    sum.

    endat.

    endloop.

    see this and do accordingly

    All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used

    to calculate the TOTALS based on sertain key fields in that internal table

    FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.

    Some time you will get * when mopving data from this int table to other table using these commands

    so you have to use

    READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them

    DATA: sflight_tab TYPE SORTED TABLE OF sflight

    WITH UNIQUE KEY carrid connid fldate,

    sflight_wa LIKE LINE OF sflight_tab.

    SELECT *

    FROM sflight

    INTO TABLE sflight_tab.

    sort sflight by carrid connid.

    LOOP AT sflight_tab INTO sflight_wa.

    AT NEW connid.

    WRITE: / sflight_wa-carrid,

    sflight_wa-connid.

    ULINE.

    ENDAT.

    WRITE: / sflight_wa-fldate,

    sflight_wa-seatsocc.

    AT END OF connid.

    SUM.

    ULINE.

    WRITE: / 'Sum',

    sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

    SKIP.

    ENDAT.

    AT END OF carrid.

    SUM.

    ULINE.

    WRITE: / 'Carrier Sum',

    sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

    NEW-PAGE.

    ENDAT.

    AT LAST.

    SUM.

    WRITE: / 'Overall Sum',

    sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

    ENDAT.

    ENDLOOP.

    Regards

    Anji

    Message was edited by:

    Anji Reddy Vangala

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 05, 2007 at 12:14 PM

    Hi,

    Declare one more internal table ( i_output) with the same structure as it_invoice3.

    then

    loop at it_invoice3.

    collect it_invoice3 into i_output.

    endloop.

    This will solve ur requirement.

    Regards,

    ananth

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 05, 2007 at 12:31 PM

    sort it_invoice3 by projid docno curr

    read table it_invoice3 index 1.

    if sy-subrc EQ 0.

    docno = it_invoice3-docnum

    projid = it_invoice3-projid

    curr = it_invoice3-curr

    endif.

    loop at it_invoice3.

    if it_invoice3-projid = projid and

    it_invoice3-docno = docno and

    it_invoice3-curr = curr.

    l_index = sy-tabix.

    it_invoice4 = it_invoice3. " header line

    clear it_invoice4-amount. " just clear amount

    endif.

    loop at it_invoice3 from index l_index.

    if it_invoice3-projid = projid and

    it_invoice3-docno = docno and

    it_invoice3-curr = curr.

    it_invoice4-amount = it_invoice4-amount + it_invoice3-amount.

    else.

    docno = it_invoice3-docnum

    projid = it_invoice3-projid

    curr = it_invoice3-curr

    append it_invoice4.

    clear it_invoice4.

    exit.

    endif.

    endloop.

    endloop.

    Now int table it_invoice4 will have the values u need.

    *reward if solved ur problem*

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 05, 2007 at 01:04 PM

    Hi..

    Check this solution.

    Note : it works properly if the Internal table has the pspid xblnr waers as the First 3 fields

    Solution:

    Sort it_invoice3 by pspid xblnr waers ASCENDING date DESCENDING.

    LOOP AT it_invoice3 .

    move it_invoice3 to it_invoice5.

    at end of waers.

    SUM.

    move it_invoice3-invcoll_amt to it_invoice5-invcoll_amt .

    append it_invoice5.

    endat.

    ENDLOOP.

    reward if Helpful.

    Add comment
    10|10000 characters needed characters exceeded