Application Development 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: 

add the internal table fields

Former Member
0 Kudos

Hi

Following is my final internal table values

A/c  Ord.No  m/c cost mfg cost std cost raw cost  other  total
121  12-test  100.00    0.00        0.00       50.00    50.00 200.00
121  12-test    50.00    50.00     -10 .00     50.00   50.00 190.00
121   34-test  100.00     0.00       0.00       50.00   50.00 150.00
121   34-test    25.00     0.00       0.00       25.00   25.00  75.00

I want to change my output to (I want to add the costs using Ord. No field)
A/c  Ord.No  m/c cost mfg cost std cost raw cost  other  total
121  12-test  150.00    50.00    -10 .00   100.00   100.00  390.00
121  34-test   125.00     0.00       0.00      75.00    75.00  225.00

Please help me.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

write collect keyword in ur editor and press F1 u'l find full documentation, but in ur case u shud use it as

loop at itab into wa.

collect wa into itab.

endloop.

it would be better if u sort ur internal table before use.

Thanku,

Regards,

Pavani

11 REPLIES 11

Former Member
0 Kudos

hai,

use collect statement..

COLLECT wa INTO itab [result].

former_member188685
Active Contributor
0 Kudos

write the code....

Former Member
0 Kudos

Hi,

You want to sum numeric fields.

Loop the internal table and use 'COLLECT' statement with your workarea.

Try this

Regards,

R.Nagarajan

Former Member
0 Kudos

Hi Kumar,

Use COLLECT Statement.

Regards,

Chandra Sekhar

0 Kudos

Hi

I declared my internal table like following.

Anyone pls help me how to use collect statement

DATA : BEGIN OF IT_SUM OCCURS 0,
         BUDAT LIKE BSIS-BUDAT,
         PERIOD(6) TYPE C,
         HKONT LIKE BSIS-HKONT,
         AUFNR LIKE BSIS-AUFNR,
         SGTXT LIKE BSIS-SGTXT,
         BLART LIKE BSIS-BLART,
         DMBTR(16)  TYPE P DECIMALS 2,
         MACHINE(16)  TYPE P DECIMALS 2,
         EXTERNAL(16)  TYPE P DECIMALS 2,
         STANDARD(16)  TYPE P DECIMALS 2,
         RAW(16)  TYPE P DECIMALS 2,
         WAERS LIKE BSIS-WAERS,
         OTHERS(16)  TYPE P DECIMALS 2,
         TOTAL(16)  TYPE P DECIMALS 2,
       END OF IT_SUM.

0 Kudos

Hi...,

You can check this sample code..,

DATA: BEGIN OF itab, 
        carrid   TYPE sflight-carrid, 
        connid   TYPE sflight-connid, 
        seatsocc TYPE sflight-seatsocc, 
      END OF itab. 

DATA tab LIKE standard table of itab WITH UNIQUE KEY carrid connid. 
      

SELECT carrid connid seatsocc 
       FROM sflight 
       INTO itab. 
  COLLECT itab INTO tab. 
ENDSELECT.

Thanks,

Naveen.I

Former Member
0 Kudos

Hi,

write collect keyword in ur editor and press F1 u'l find full documentation, but in ur case u shud use it as

loop at itab into wa.

collect wa into itab.

endloop.

it would be better if u sort ur internal table before use.

Thanku,

Regards,

Pavani

0 Kudos

Hi

i tried collect statement. but it is not working. any one help me pls.

0 Kudos

I think SAP Statements work the same in all systems.

So if it works perfectly in mine, it should work fine in yours.

pk

0 Kudos

Hi

Use AT END OF statement as in below code.

LOOP at itab.
  
  lwa_temp-acoount = itab-account.
  lwa_temp-ord_no = itab-ord_no.
  ADD itab-mc_cost TO lv_mc_cost. " Do the same for all fields
  
  AT END OF ORD_NO.
    lwa_temp-mc_cost = lv_mc_cost " Do the same for all fields
    APPEND lwa_temp TO lt_temp.
  ENDAT.
  
ENDLOOP.

" Now lt_temp will have final vaues

Former Member
0 Kudos

firstly move these records to another internal table as it_final1[] = it_final[]

then sort the internal table it_final1 by ord.no

and then use delete adjust duplicate records then u will get the required output

syntax:-delete adjust duplicate records from it_final1 comparing ord.no