Skip to Content

Internal Table process subset of entries

Hi ABAP Colleagues

I have an internal table as follows:

ORDER        COST ELEMENT           AMOUNT

921188         601123                         200

921188         601124                         100

921188         601124                         300

921188         601124                         300

921188         601125                         100

921188         601125                         200

921189         601123                         200

921189         601124                         100

921189         601124                         250

921189         601125                         400

Within any order number, if the cost element 601125 occurs more than once, I need to append a record underneath that 601125 record which is a total of the preceeding 601125 records. If within any order number the cost element 601125 only occurs once, then do not append any record. So the above should look like this after processing:

ORDER        COST ELEMENT           AMOUNT

921188         601123                         200

921188         601124                         100

921188         601124                         300

921188         601124                         300

921188         601125                         100

921188         601125                         200

921188         601125                         300  <<-- insert a record which is total of preceeding 2 601125 records

921189         601123                         200

921189         601124                         100

921189         601124                         250

921189         601125                         400  <<-- no need to insert/append a record here as only 1 601125 record exists.

Can you advise please how might I achieve this? We are not on 740 ABAP release.

Thanks and regards

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Oct 27, 2015 at 06:37 PM

    Hi

    Also when inserting a summary record under the 601125 records I need to blank out the target amount associated with preceeding 601125 records that have been summarized by the inserted 601125 record. See below.

    ORDER        COST ELEMENT           AMOUNT              TARGET

    921188         601123                         200                            80

    921188         601124                         100                            70

    921188         601124                         300                            50

    921188         601124                         300                            30

    921188         601125                         100                            55

    921188         601125                         200                            55

    921189         601123                         200                            60

    921189         601124                         100                            40

    921189         601124                         250                            40

    921189         601125                         400                            30

    Within any order number, if the cost element 601125 occurs more than once, I need to append a record underneath that 601125 record which is a total of the preceeding 601125 records. If within any order number the cost element 601125 only occurs once, then do not append any record. So the above should look like this after processing:

    ORDER        COST ELEMENT    TARGET    AMOUNT                   

    921188         601123                         80          200

    921188         601124                         70         100

    921188         601124                         50         300

    921188         601124                         30         300

    921188         601125                                       100  <--blank target amount

    921188         601125                                       200  <--blank target amount

    921188         601125                         55         300  <-- insert record which is total of preceeding 2 * 601125 records

    921189         601123                         60         200

    921189         601124                         40         100

    921189         601124                         40          250

    921189         601125                         30          400  <<-- no need to insert/append a record here as only 1 601125 record exists.

    Any help on how to achieve this would be appreciated.

    Thank you.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 28, 2015 at 02:54 AM

    Hi Michael,

    Sort the internal table by order and cost center, Create a another internal table.

    data it_sum like itab.

    loop at itab into wa.

    collect wa into it_sum.  "Values are summed.

    endloop.

    loop at itab into wa.

    read table it_sum into wa_sum with key order            = wa-order

                                                               cost center   = wa-costcenter.

    check sy-subrc is initial.

    if wa_sum-amount NE wa-amount.     "Checking the amount

    Append wa_Sum to itab.

    endif.

    endloop.

    Hope it helpful,

    Regards,

    Venkat.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 28, 2015 at 06:26 AM

    Hello, can you using at end of  COST ELEMENT field, fist you have to sort it_tab by ORDER, COST ELEMENT. and then at end of COST ELEMENT you can check previewous records if same, than you can do sum else you can skip and continue 😊 ( using sy-tabix - 1 )

    Hope it can help 😊

    Add comment
    10|10000 characters needed characters exceeded