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 2 internal tables

Former Member
0 Likes
1,883

Hi,

i have 2 itabs.

itab2 contains:

174422070104 |0760 |000144200160|0000324482| 0321

174422070104 |0760 |000144200160|0000324482|1217

itab4 contains

174422070104 |0760 |000144200180|0000328602|0654

now when i compare as follows

LOOP AT ITAB2 .

READ TABLE ITAB4 WITH KEY MATNR = ITAB2-MATNR binary search.

IF SY-SUBRC <> 0.

MOVE ITAB2-MATNR TO IT_DEL-MATNR.

MOVE ITAB2-MAKTX TO IT_DEL-MAKTX.

MOVE ITAB2-VORNR TO IT_DEL-VORNR.

MOVE ITAB2-KZEAR TO IT_DEL-KZEAR.

MOVE ITAB2-ENMNG TO IT_DEL-ENMNG.

MOVE ITAB2-BDMNG TO IT_DEL-BDMNG.

APPEND IT_DEL.

ENDIF.

ENDLOOP.

1st record of itab2 match with itab4 but itab4 does not have 2nd record. so it append to it_del. but its not happening as header line not cleared.

25 REPLIES 25
Read only

Former Member
0 Likes
1,854

hi,

wht is ur doubt is not very clear.

If the problem is with header use work area for both the itabs.

If the issue is appending extra record in it_del thn loop at itab4 and read itab2.

Hope this helps

Read only

0 Likes
1,854

hi seema,

I tried work area also. but it is not working, i have to show this material in the deleted list.

Regards,

Read only

0 Likes
1,854

Khushi,

Its still not clear wht is the exact issue u r facing in the code. Can you please explain the same.

Read only

0 Likes
1,854

hi...

Clear header table after append .

Regards

Deepak

Read only

0 Likes
1,854

hi khushi ,

as i said clear your read table i.e it_tab4 which contains 1 record

loop at it_tab2 .

read table it_tab4 .....

your moving code here .

after append it_del .

clear it_tab4 .

endloop.

clear it_tab2 .

This will solve your problem .

your problem is that your header line does not get clear after reading .

Regards

Deepak .

Read only

Former Member
0 Likes
1,854

Hi,

LOOP AT ITAB2 .
READ TABLE ITAB4 WITH KEY MATNR = ITAB2-MATNR binary search.
IF SY-SUBRC NE 0.                                     " check this
MOVE ITAB2-MATNR TO IT_DEL-MATNR.
MOVE ITAB2-MAKTX TO IT_DEL-MAKTX.
MOVE ITAB2-VORNR TO IT_DEL-VORNR.
MOVE ITAB2-KZEAR TO IT_DEL-KZEAR.
MOVE ITAB2-ENMNG TO IT_DEL-ENMNG.
MOVE ITAB2-BDMNG TO IT_DEL-BDMNG.
APPEND IT_DEL.
ENDIF.
ENDLOOP.

Read only

Former Member
0 Likes
1,854

hi khushi,

can you explian me what is your code and what exact you want.

regards

raghava

Read only

Former Member
0 Likes
1,854

Hi Seema,

In itab2 , there are 2 records and in itab4 there are only 1 record. now when i compare these 2 itabs as above after 1st execution ,2nd time itab4 should not contain the material number and value of sy-subrc should be 4, but its not happening. i have used itab with header line. so 2nd time itab4 contain same material number.

Read only

Former Member
0 Likes
1,854

hi deepak,

no its not working.

Read only

0 Likes
1,854

PLEASE READ THIS PROPERLY .

when you are reading itab 4 to match with itab2 which has two records

loop will exectute two time .

read will execute one time .

according to your code when record will not match i.e sy-subrc NE 0 .

then you are moving your data to it_del aND APPENDING BUT YOUR RECORD IS RETURNING SY-SUBCR = 0 .

SO IT WILL NOT MOVE RECORDS TO IT_DEL TABLE .

IF YOU WANT TO TRANSFER DATA IF MATNR MATCH THEN USE SY-SUBRC = 0 AND THEN IT WILL MOVE DATA TO IT_DEL

THEN APPEND IT_DEL .

CLEAR ITAB4 .

ENDLOOP.

CLEAR ITAB2.

rEGARDS

DEEPAK .

Read only

Former Member
0 Likes
1,854

Hi deepak,

i want to transfer data in matnr not matches ie sy-subrc ne 0. the problem is due the same material is coming twise. if i took differnet materials then i works fine. Is there another way to comapre ie FM.

Read only

Former Member
0 Likes
1,854

Hi deepak,

i want to transfer data in matnr not matches ie sy-subrc ne 0. the problem is due the same material is coming twise. if i take differnet materials then i works fine. Is there another way to comapre ie FM.

Regards,

Read only

0 Likes
1,854

hi khushi ,

Now as code which is written will give you correct result according to what you said .

NOw you tell me what result you are expecting from records which you have show in itab2 and itab 4 .

according to you what result you are expecting .

as there can be more same matnr in itab2 so it will execute that many times .

when there will be another matnr which does not matches itab4 table record .

then only itab2 data will be moved to i it_del table .

if thios is not you are expecting .

then pls give dummy data of both table and expected result .

in this reply .

Regards

Deepak

Read only

Former Member
0 Likes
1,854

hi deepak,

i have given data and code above.

u guess right, but not getting the result as expected.

Regards,

Read only

0 Likes
1,854

Khushi,

I already mentioned this na that try to loop at itab4 and read itab2 thn see the results.

Read only

0 Likes
1,854

khushi ,

what is your expected result if matnr does not match

you want to move data to it_del

Redards

Deepak .

Read only

Former Member
0 Likes
1,854

Hi deepak,

yes, i want the same if material does not match , then append it_del.

Read only

0 Likes
1,854

Ok ..

Then listen , there is no data in your internal tables that is not matching .

your both table have data they are same i.e matnr are matching it returns sy-subrc = 0 .

so it will not append data .

that means now your code is working fine but you dont have different matnr to test .

It will be better if you test using more data using same code now .

It will work fine .

Regards

Deepak .

Read only

Former Member
0 Likes
1,854

Hi Deepak,

ya, both table have same data but in itab2 there are 2 records and itab4 contains only 1and qty is different . so i want the second record in itab2 in the deleted list.

Regards,

Read only

0 Likes
1,854

ok ...

how can you compare quantity field as there may be multiple records of different quantity with same matnr and all other filed .

how you will decide which to delete .

What is difference between itab4 and itab2 data can you explain .

as columns are same .

all fields data are same except last column i.e bdmng .

now from this data what result you are expecting .

Regards

Deepak .

Read only

Former Member
0 Likes
1,854

Hi Deepak,

I am working on network comparision, from one master network i have find which components are to be addeda and which are to be deleted. so this component is to be deleted as it appears more than once as compare to master network in another network. ie in master network it appears only once and in compared network it appeared twice , so i have to print that component in to be deleted list. hope u clear with the problem.

Regards,

Read only

0 Likes
1,854

hi khushi ,

Then do one thing also add this code in your read condition after comparing matnr .

read table itab4 with key itab4-matnr = itab2-matnr

itab4-bdmng = itab2-bdmng . add this line to compare qty .

Regards

Deepak .

Read only

0 Likes
1,854

Hi Khushi ,

Can you give me all field names and values in it , because you have given data of five fields .

regards

Deepak .

Read only

Former Member
0 Likes
1,854

thanks

Read only

0 Likes
1,854

ha hah haha,

Your thankx brought little smile on my face .

i think you are fedup with the solutions .

Now decide which quantity to keep and which to delete .

and act according .

Regards

Deepak .