cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing internal tables

Former Member
0 Kudos

Hi,

I have to compare the workarea of 2 internal tables comparing all fields of the workareas. One work area has fields from the flat file and the other workarea has fields from the master table. If all the fields of the work areas are same then we do not update the master table. Each workarea has 15 fields without explicitly mentioning the field names is there a way of comparing all fields ??

Thanks in advance.

Accepted Solutions (0)

Answers (5)

Answers (5)

hymavathi_oruganti
Active Contributor
0 Kudos

let ITAB be the first internal table.WA BE THE WORK AREA

ITAB1 be the second internal table.WA1 BE THE WORK AREA

CREATE ATHIRD ITABLE , LET IT BE ITAB2.

ITAB2[] = ITAB[].

APPEND ITAB2.

U CAN USE THE FOLLOWING LOGIC.

LOOP AT ITAB1 TO WA1.

APPEND ITAB1 TO ITAB2.

ENDLOOP.

SORT ITAB2.

DELETE ADJACENT DUPLICATES FROM ITAB2 COMPARING ALL FIELDS.

DESCRIBE TABLE ITAB LINE V_LINE

DESCRIBE TABLE ITAB2 LINES V_LINE2.

IF V_LINE = V_LINE2.

"MEANS ALL THE RECORDS ARE SAME".

ELSE.

"DIFFERENT."

LOOP AT ITAB2.

IF SY-TAIX > V_LINE.

UPDATE DBTAB.

ENDIF.

ENDLOOP.

ENDIF.

Message was edited by: Hymavathi Oruganti

Former Member
0 Kudos

Hi Reshmi,

You can compare internal tables using the foll.concept.

Suppose itab1 and itab2 are two int.tables.

when you say

if itab1 < itab2.

1) no:of entries in both tables are compared.

2) if no: of entries are same, content of 1st entry of 1st table will be compared with that of 2nd table and so on.

3)Else , one with greater no: of entries will be greater.

I think same logic is applicable to their workareas also.

Just check the following link for more details.

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

Regards,

SP.

former_member188685
Active Contributor
0 Kudos

hi,

if itab1_wa <> itab2_wa .

"they are not equal.

else.

"they are equal.

endif.

naimesh_patel
Active Contributor
0 Kudos

Hello Rashmi,

If your fields are of same field definations and in same order, then you can directlry compare like,

if wa_file <> wa_master.

update...

endif.

regards,

Naimesh

Reward points, if it is useful..!

Former Member
0 Kudos

Hi Naimesh,

Both have the same field definitions and i tried comparing as you said but i get a sy-subrc eq 4 when all the fields are equal. Can you forsee any reason for this ??

Former Member
0 Kudos

Hi Reshmi

one of the best solution to do that is to add a field in the 2 tables where you'll store the concatenation of the 15 first fields.

ex :

data : begin of Tab1 occurs 0,
field1
field2
...
field15
field16(200) type c,
end of Tab1

data : Tab2 like tab1 occurs 0 with header line.

concatenate tab1-field1 tab1-field2 tab1-field3...
into tab1-field16.

concatenate tab2-field1 tab2-field2 tab2-field3...
into tab2-field16.

*AND you just have to loop on the table you want and *compare with the other one on the field 'field16'
loop at tab1.
if tab1-field16 <> tab2-field16
...
...

Hope this helps,

Erwan.

Former Member
0 Kudos

sort it_db.

LOOP AT it_itab1 into wa1.

READ TABLE it_db into wa2 binary search WITH KEY field = wa1-field

IF sy-subrc = 0.

wa_master = wa2.

append wa_master to it_master.

clear wa_master.

ENDIF.

ENDLOOP.

Message was edited by: kishan negi

naimesh_patel
Active Contributor
0 Kudos

Hello Rashmi,

May be there is some space in one field after the contains of the field from File. Try to debug the program, you will get to know where is the error.

Regards,

Naimesh

Former Member
0 Kudos

Hi Rashmi

Try like this...

LOOP AT it_ekko.

READ TABLE it_mseg WITH KEY ebeln = it_ekko-ebeln.

IF sy-subrc <> 0.

DELETE it_ekko.

continue.

ENDIF.

ENDLOOP.

Thanks