Application Development and Automation 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: 
Read only

How to subract two internal table

Former Member
0 Likes
1,656

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

7 REPLIES 7
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,222

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.

Read only

Former Member
0 Likes
1,222
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

Read only

Former Member
0 Likes
1,222

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.

Read only

Former Member
0 Likes
1,222

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

Read only

Former Member
0 Likes
1,222
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.

Read only

Former Member
0 Likes
1,222

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

Read only

Former Member
0 Likes
1,222

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.