Former Member

# How to subract two internal table

Hi Experts

I have Two internal table itab1,itba2

itab1

MATNR  Material no

ZZSTWRT  Currency field

Itab2

MATNR Material no

ZZSTWRT Currency field

In both internal table Material field are SAME but currency field may be DIFFERERNCE

I have to display what Difference currency amount between two tables..

How to subtract between two tables ..give me logic idea

output lfollowing ike this..

Material Value itab1 : Material Value tabb2 :currency difference between two tables

10|10000 characters needed characters exceeded

### Related questions

• Posted on Feb 02, 2007 at 07:14 AM

HI,

Use the following code.

Loop at itab1 into wa_1.

read table itab2 into wa_2with key matnr = wa_1-matnr .

diff = wa_2-ZZSTWRT - wa_1-ZZSTWRT.

write: diff.

endloop.

Regards,

Sesh.

10|10000 characters needed characters exceeded
• Former Member
Posted on Feb 02, 2007 at 07:14 AM
```sort itab1.
sort itab2.
loop at itab1.
read table itab2 binary search with key matnr = itab1-matnr.
itab3-matnr = itab2-matnr.
itab3-diff = itab1-ZZSTWRT - itab2-ZZSTWRT.
append itab3.
endloop.```

kishan negi

10|10000 characters needed characters exceeded
• Former Member
Posted on Feb 02, 2007 at 07:14 AM

Write code as below:

DATA: d_ZZSTWRT like ZZSTWRT.

Loop at itab1.

Read table itab2 with key matnr = itab1-matnr.

d_ZZSTWRT = itab1-ZZSTWRT - itab2-ZZSTWRT.

write : / itab1-ZZSTWRT, itab2-ZZSTWRT, p_ZZSTWRT.

Endloop.

10|10000 characters needed characters exceeded
• Former Member
Posted on Feb 02, 2007 at 07:15 AM

Hi,

loop at itab1 and read itab2

subtract the amount and move the same to a variable

modify the itab1 or it_final transporting the amount

Regards

Shiva

10|10000 characters needed characters exceeded
• Posted on Feb 02, 2007 at 07:15 AM
```LOOP AT itab1.
LOOP AT itab2 where matnr = itab1-matnr.
curr = itab1-curr - itab2-curr.
WRITE:/ itab1-matnr,
itab2-matnr,
curr.
ENDLOOP.
ENDLOOP.```

Try similarly.

10|10000 characters needed characters exceeded
• Former Member
Posted on Feb 02, 2007 at 07:16 AM

use logic like this -

loop at itab1.

read table itab2 with key MATNR = itab1-MATNR.

if sy-subrc = 0.

itab-difference = abs( itab1-ZZSTWRT - itab2-ZZSTWRT ).

append itab.

endif.

endloop.

amit

10|10000 characters needed characters exceeded
• Former Member
Posted on Feb 02, 2007 at 07:18 AM

try this...

loop at it1.

read table it2 with key MATNR = it1-MATNR.

if sy-subrc = 0.

it-difference = it1-ZZSTWRT - it2-ZZSTWRT.

append it.

endif.

endloop.