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

comparing two internal tables.

Former Member
0 Likes
605

Hi All!

I have two int tables as below with the same columns and field names and values below..

<b>Item quan

mfg03 50

mfg04 100

mfg05 20.</b>

second IT is also having item numbers with different values.Now i want to figure out the line items which are not there in the second IT by comparing the first IT .Please advise.

Regards

Pavan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
565

Hi Kumar,

Take third internal table and do as follows.

<b>1)If you sure that you dont have more than one entry for each material in ITAB2 then do as follows.</b>

DATA ITAB3 TYPE ITAB OCCURS 0 WITH HEADERLINE.

loop at itab1.

read table itab2 with key item = itab1-item.

<b>if sy-subrc <> 0.</b>

wa_itab3-quan = itab1-quan - itab2-quan.

wa_itab3-item = itab1-item.

append wa_itab3 to itab3

<b>endif.</b>

endloop.

<b>2)If you more than one entry for each material in ITAB2 then do as follows.</b>

loop at itab1.

<b>loop at itab2 where item <> itab1-item.</b>

wa_itab3-quan = itab1-quan - itab2-quan.

wa_itab3-item = itab1-item.

append wa_itab3 to itab3

<b>endloop.</b>

endloop.

<b>The BOLD STATEMENTS will do comparision for the requirement.</b>

Thanks,

Vinay

Message was edited by: Vinaykumar G

5 REPLIES 5
Read only

Former Member
0 Likes
565

Hi Pavan,

Just go through this link on comparing internal tables..

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3841358411d1829f0000e829fbfe/content.htm

Regards,

SP.

Read only

Laxmana_Appana_
Active Contributor
0 Likes
565

Hi,

Check this code:

Loop at it1.

read table it2 with key fld1 = it1-fld1.

if sy-subrc ne 0.

-


which is in it1 and not in it2.

endif.

endloop.

Laxman

Read only

Former Member
0 Likes
566

Hi Kumar,

Take third internal table and do as follows.

<b>1)If you sure that you dont have more than one entry for each material in ITAB2 then do as follows.</b>

DATA ITAB3 TYPE ITAB OCCURS 0 WITH HEADERLINE.

loop at itab1.

read table itab2 with key item = itab1-item.

<b>if sy-subrc <> 0.</b>

wa_itab3-quan = itab1-quan - itab2-quan.

wa_itab3-item = itab1-item.

append wa_itab3 to itab3

<b>endif.</b>

endloop.

<b>2)If you more than one entry for each material in ITAB2 then do as follows.</b>

loop at itab1.

<b>loop at itab2 where item <> itab1-item.</b>

wa_itab3-quan = itab1-quan - itab2-quan.

wa_itab3-item = itab1-item.

append wa_itab3 to itab3

<b>endloop.</b>

endloop.

<b>The BOLD STATEMENTS will do comparision for the requirement.</b>

Thanks,

Vinay

Message was edited by: Vinaykumar G

Read only

Former Member
0 Likes
565

Hi Kumar,

Consider this code,


REPORT as.

TYPES : BEGIN OF tp_test,
        item(5),
        quan(2),
        END OF tp_test.
DATA : it_test1 TYPE STANDARD TABLE OF tp_test,
       wa_test1 TYPE tp_test,
       it_test2 TYPE STANDARD TABLE OF tp_test,
       wa_test2 TYPE tp_test,
       it_result TYPE STANDARD TABLE OF tp_test.



*Loop the second Table

LOOP AT it_test2 INTO wa_test2.

*Read the first table

  READ TABLE it_test1 INTO wa_test1 WITH KEY item = wa_test2-item
                                             quan = wa_test2-quan.


*If no entry present in the first table for entry in second table then append
*then append the second table entry.

  IF sy-subrc NE 0.
    APPEND wa_test2 TO it_result.
  ENDIF.

ENDLOOP.

Regards,

Arun Sambargi.

Read only

Former Member
0 Likes
565

Hi kumar pavan ,

loop at itab1.

read table itab2 with key Item quan = itab1-Item quan.

if sy-subrc <> 0.

move itab1 to itab_temp.

append itab_temp.

endif.

endloop.

Regards,

Kiran B

endloop.