Skip to Content
-2

How to get data profit centre wise from an internal table?

Hi all ,

Internal table having customer code ,amount and profit centre.

requirement is to dislplay data profit centre wise.

i have used onchange control break statement its working when profit centre get changes not for when it will remain unchange.

i want if profit centre remain same against customer then sum the amount and comes in one line and if profit centre changes then it should comes in multiple lines

my code :

loop at it_final into wa_final.

on change of wa_final-prctr.

append wa_final to gt_final.

endon.

endloop.

internal-table.png (25.2 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Oct 13, 2017 at 07:43 AM
    -1

    I'am looking output like this

    when Prctr get changed with respect to kunnr should come in next line.

    when prctr remain same with respect to kunnr should sum wrbtr and comes in one line

    Like 10008 having 2 profit centres so it is in 2 line

    and 10010 having only 1 profit centre 40647 so it sum the wrbtr and give 203,000.30 amount.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 14, 2017 at 02:23 AM

    Hi,

    Just change the code above a little bit, adding the customer code (kunnr) in sorting:

    * I prefer to use field-symbols, so I'll declare them now
    field-symbols: <fs_final1> like line of it_final,
                   <fs_final2> like line of it_final.
    
    * suppose that IT_FINAL and GT_FINAL have the same structure, copy data from IT_FINAL to GT_FINAL
    gt_final = it_final.
    
    sort gt_final by kunnr prctr. " sort GT_FINAL by customer code & profit center
    delete adjacent duplicate from gt_final comparing kunnr prctr. " remove duplicate entries to get unique combination of customer code & profit center
    
    loop at gt_final assigning <fs_final1>.
      clear: <fs_final1>-wrbtr, <fs_final1>-dmbtr " clear initial values
      loop at it_final assigning <fs_final2> where kunnr eq <fs_final1>-kunnr
                                               and prctr eq <fs_final1>-prctr.
        add <fs_final2>-wrbtr to <fs_final1>-wrbtr.
        add <fs_final2>-dmbtr to <fs_final1>-dmbtr.
      endloop.
    endloop.
    
    * the internal table GT_FINAL now holds the sum for the fields WRBTR and DMBTR per KUNNR (customer code) & PRCTR (profit center).
    Add comment
    10|10000 characters needed characters exceeded

  • Oct 14, 2017 at 05:58 AM

    Hi,

    Change internal table sequence like kunnr,prctr and use control break statements at end of prctr.

    data: lv_wrbtr type wrbtr.loopat it_final into wa_final1.
    lv_wrbtr  = wa_final1-wrbtr + lv_wrbtr.
    
    at end of  prctr.
    wa_final1-wrbtr = lv_wrbtr .
    
    append wa_final1 to lt_final_tmp.
    
    clear: wa_final1,lv_wrbtr.
    
    endat.
    
    endloop.

    Regards,

    K.Pradeep Reddy.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 16, 2017 at 01:10 PM

    If your system is quite new (>= 7.40 SP8) you can also use "new ABAP":

        DATA(sums) = VALUE ltt_table(
          FOR GROUPS <group> OF <line> IN it_final
            GROUP BY ( kunnr = <line>-kunnr prctr = <line>-prctr )
            (
              kunnr = <group>-kunnr
              prctr = <group>-prctr
              dmbtr = REDUCE #( INIT sum = 0
                                FOR <sum> IN GROUP <group>
                                NEXT sum = sum + <sum>-dmbtr )
              wrbtr = REDUCE #( INIT sum = 0
                                FOR <sum> IN GROUP <group>
                                NEXT sum = sum + <sum>-wrbtr )
            )
        ).
    Add comment
    10|10000 characters needed characters exceeded

  • Oct 13, 2017 at 07:07 AM

    Either use a COLLECT statement or perform a sum somewhere in your code...

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 13, 2017 at 07:13 AM

    Hi,

    Please try the following code

    * I prefer to use field-symbols, so I'll declare them now
    field-symbols: <fs_final1> like line of it_final,
                   <fs_final2> like line of it_final.
    
    * suppose that IT_FINAL and GT_FINAL have the same structure, copy data from IT_FINAL to GT_FINAL
    gt_final = it_final.
    
    sort gt_final by prctr. " sort GT_FINAL by profit center
    delete adjacent duplicate from gt_final comparing prctr. " remove duplicate entries based on profit center
    
    loop at gt_final assigning <fs_final1>.
      clear: <fs_final1>-wrbtr, <fs_final1>-dmbtr " clear initial values
      loop at it_final assigning <fs_final2> where prctr eq <fs_final1>-prctr.
        add <fs_final2>-wrbtr to <fs_final1>-wrbtr.
        add <fs_final2>-dmbtr to <fs_final1>-dmbtr.
      endloop.
    endloop.
    
    * the internal table GT_FINAL now holds the sum for the fields WRBTR and DMBTR per PRCTR (profit center).
    Add comment
    10|10000 characters needed characters exceeded