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: 

Internal table value addition

former_member248300
Participant
0 Kudos

Hello Friends,

This I my internal table:

VBELN POSNR NETPR

10009901 000010 10.00

10009901 000020 12.00

10009903 000010 20.00

10009903 000020 10.00

I want my internal table like this

VBELN POSNR NETPR

10009901 000010 22.00

10009901 000020 22.00

10009903 000010 30.00

10009903 000020 30.00

Please let me know how to achieve this.

Thanks,

Shreekant

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Do it like this:


data:
  W_NETPR like NETPR,
  ITAB1 like ITAB.

loop at ITAB into WA.

  at new VBELN.
    sum.
    W_NETPR = ITAB-NETPR.
  endat.
   
   WA-NETPR = W_NETPR.   
   append WA to ITAB1.
endloop.

With luck,

Pritam

5 REPLIES 5

Former Member
0 Kudos

hi,

You can go for On change of vbeln and make the calculations.

use the concept of on change.

it will work.

Former Member
0 Kudos

Do it like this:


data:
  W_NETPR like NETPR,
  ITAB1 like ITAB.

loop at ITAB into WA.

  at new VBELN.
    sum.
    W_NETPR = ITAB-NETPR.
  endat.
   
   WA-NETPR = W_NETPR.   
   append WA to ITAB1.
endloop.

With luck,

Pritam

Former Member
0 Kudos

Hi,

In such case we use control break statements i.e. AT NEW...

Within an AT...ENDAT block, you can calculate the contents of the numeric fields of the corresponding control level using the SUM statement.

You can only use this statement within a LOOP. If you use SUM in an AT - ENDAT block, the system calculates totals for the numeric fields of all lines in the current line group and writes

them to the corresponding fields in the work area (see example in ). If you use the SUM statement outside an AT - ENDAT block (single entry processing), the system calculates totals

for the numeric fields of all lines of the internal table in each loop pass and writes them to the corresponding fields of the work area. It therefore only makes sense to use the SUM statement in AT...ENDAT blocks.

loop...

at new VBELN.

sum.

W_NETPR = ITAB-NETPR.

endat.

WA-NETPR = W_NETPR.

append wa_itab to ITAB1.

endloop.

Edited by: Dhanashri Pawar on Aug 22, 2008 11:08 AM

Edited by: Dhanashri Pawar on Aug 22, 2008 11:10 AM

Former Member
0 Kudos

Hi,

Try using AT END OF control break stmt.

loop at itab1 into wa_itab.

sum = sum + wa_itab-NETPR.

at end of POSNR.

wa_itab-NETPR = sum.

append wa_itab to itab2.

clear: wa_itab, sum.

endat.

endloop.

The itab2 will satisfy your requirement.

Sharin.

Former Member
0 Kudos

Create one new internal table with the same structure

suppose your first table is itab1 and second is itab2 then.

and declare tables like this

DATA itab1 LIKE SORTED TABLE OF <your structure>

WITH NON-UNIQUE KEY col1 col2.

loop at itab1.

COLLECT itab1 INTO itab2.

endloop.

this will create only one line item in your second internal table. And in the internal table declaration the NON-UNIQUE KEY would be all the fields except the field you want to add data.

Edited by: Digvijay Singh Pawar on Aug 22, 2008 12:08 PM