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

Compare two internal tables

Former Member
0 Likes
784

Hi

Iam having two internal tables

data: begin of itab,

matnr like mara-matnr,

maktx like makt-maktx,

charg like mch1-charg,

end of itab.

data: itab1 like itab occurs 0 with header line,

itab2 like itab occurs 0 with header line,

data:begin of jtab,

matnr like mara-matnr,

charg like makt-charg,

end of jtab.

data: itab3 like jtab occurs 0 with header line,

itab4 like jtab occurs 0 with header line.

<b>[ both itab1 and itab3 contains records.they can be different or same records. now i have compare both the tables with matnr and charg.For one matnr number we can have multiple charg numbers.

1.when compared if the record is found in itab1 and not in itab3 then we have to pull out that record into itab2.

2.if the record is not found in itab1 and found in itab3 then we have to pull that record into itab4

3. if they are same nothing to be done.]</b>

CAN ANY ONE POST WITH EXAMPLE.

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
702

First loop at itab1 and read against itab3. Then reverse it.


Loop at itab1.
   
   read table itab3 with key matnr = itab1-matnr
                                       charg = itab1-charg.
   if sy-subrc <> 0.
     append itab1 to itab2.
   endif.

endloop.

Loop at itab3.
   
   read table itab1 with key matnr = itab3-matnr
                                       charg = itab3-charg.
   if sy-subrc <> 0.
     append itab3 to itab4.
   endif.

endloop.

Regards,

RIch Heilman

Read only

0 Likes
702

Is there any function module which can compare two internal tables

Read only

0 Likes
702

I don't think there are any function modules that can compare two tables.

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

0 Likes
702

Hello

CTVB_COMPARE_TABLES --- function module to compare tables

Here u should give 2 internal tables as input and 3 as output

Inputs: comparing tables

Output: modifications/changes, Additions and error tables

Read only

Former Member
0 Likes
702

Hi satya,

sort : itab1 by matnr charg,

itab3 by matnr charg.

Loop at itab1.

read table itab3 with key matnr = itab1-matnr

charg = itab1-charg bynary search.

if sy-subrc <> 0.

append itab1 to itab2.

clear itab2.

endif.

endloop.

Loop at itab3.

read table itab1 with key matnr = itab3-matnr

charg = itab3-charg bynary search.

if sy-subrc <> 0.

append itab3 to itab4.

clear itab4.

endif.

endloop.

Pls. reward points for useful answers.

Read only

Former Member
0 Likes
702

you can try like this.

loop at itab1.

read table itab3 with key matnr = itab1-matnr charg = itab1-charg.

if sy-subrc ne 0.

move-corresponding itab1 to itab2.

append itab2.

else.

delete itab3 index sy-tabix.

endif.

endloop.

<now your itab3 contains which are not common in itab1>

append lines of itab3 to itab4.

regards

shiba dutta

Read only

Former Member
0 Likes
702

SOLVED