Application Development 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: 

How to check two internal table fields

Former Member
0 Kudos

Hi all,

I need to check two internal table fields are equal or not means which statement i can use.

Not internal table ,table contents i need to check i.e

it1-pernr = it2-pernr.

like this

if i put loop it'll check one table field for one loop.

if i put two loop means some fields reflecting 2 in it1 then it'll pring 4 times like that.i want to print whatever in internal table only .

pernr(0001) two times there in it1 means

it1-pernr = it2-pernr then

it's printing

0001

0001

0001

0001

like this but actually in it1 only two records.

Anybody know solution.tell me.

Thanks

Regards,

Nandha

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Please,Any body can help me.Any way to get result according to my requirement.

Thanks

Nandha

17 REPLIES 17

former_member181962
Active Contributor
0 Kudos

Try the following,

loop at itab1.

read table itab2 index sy-tabix.

if itab1-field1 = itab2-field1.

  • Do something

endif.

endif.

Regards,

Ravi

Former Member
0 Kudos

Hi,

Loop at itab.

read table itab1 with key pernr = itab-pernr.

...........

...........

endloop.

Here it will read the records from itab1 where pernr equal to looping itab-pernr.

****************

Here in that loop you need to MOVE to another internal table.

With move command move to another internal table and the display from that internal table.

***********

Thanks.

If this helps you reward with points.

Message was edited by: Deepak333 k

suresh_datti
Active Contributor
0 Kudos

Hi Nadha,

try this..

sort: it1 by pernr, it2 by pernr.

loop at it1.

read table it2 with key pernr = it1-pernr

binary search.

if sy-subrc eq 0.

write: / it1-pernr.

endif.

endloop.

Regards,

Suresh Datti

former_member188685
Active Contributor
0 Kudos
loop at it1.

read table it2 with key pernr = it1-pernr.

if sy-subrc <> 0.
record not equal...
endif.

endloop.

Former Member
0 Kudos

Hi nandha,

1. what i understood is that

u want to print only those pernr

which are EQUAL/EXIST in both tables.

2. If that is so,

that just use one loop.

LOOP AT ITAB1.

READ TABLE ITAB2 WITH KEY PERNR = ITAB1.PERNR.

IF SY-SUBRC = 0.

WRITE ITAB1-PERNR.

ENDIF.

ENDLOOP.

3. NO NEED TO USE 2ND LOOP ON ITAB2.

(BCOS LOOP1 TAKES CARE OF ALL THE COMMON PERNR)

4. If ur requirement is different,

then pls let me know.

Regards,

Amit M.

0 Kudos

I want to check all fields not only one field in one table.

it1 having -- 0001

0001

0002

0003

it2 having--0001

0001

0002

I want to print it1 where it1-ernr equals it2 pernr

like

0001

0001

0002

here 0003 not equal so don't want to print

Thanks

REgards,

Nandha

0 Kudos

Hi Nadha,

Can you give the complete structure of it1 & it2 or paste ur code?

Suresh

0 Kudos

Hi again,

1. can u provide the code.

2. It seems u are missing something very small.

for eg.

READ TABLE ITAB2 WITH KEY PERNR = ITAB1-PERNR.

IF SY-SUBRC = 0. "<--- VERY IMPORTANT.

ENDIF.

regards,

amit m.

Former Member
0 Kudos

Hi,

All codes are triggering same result.

Thanks

Nandha

Former Member
0 Kudos

Please,Any body can help me.Any way to get result according to my requirement.

Thanks

Nandha

0 Kudos

Hi Nandha,

PL refer to my earlier post & pate the code or give the structure for the 2 itabs..

Suresh

0 Kudos

can you just give the structure fields and sample output..

vijay

0 Kudos

Hi,

code for your view

data : begin of it1 occurs 0,

z_pernr like pa9012-pernr,

z_fac_c like pa9012-zz_fac_c,

end of it1.

data : it2 like Zsc1 occurs 0 with header line,

It1 data

pernr FAC C

0001 5555

0001 5555

0002 4444

0003 3333

0006 8888

It2 data

pernr FAC C

0001 5555

0001 5555

0005 6666

0003 3333

output(My code)

loop at it2 .

loop at it1 where pernr = it2-pernr.

write:/01 it1-1pernr,

10 it1-z_fac_c.

endloop.

endloop.

out put i need.

0001 5555

0001 5555

0002 4444

0003 3333

Thanks,

Nandha

0 Kudos

Hi Nandha,

try this,,

sort: it1 , it2 ,

loop at it1.

read table it2 with key pernr = it1-pernr

FAC_C = it1-FAC_C

binary search.

if sy-subrc eq 0.

write: / it1-pernr, it1-fac_c.

endif.

endloop.

Former Member
0 Kudos

Hi Nandha Kumar,

Instead of printing in the list as soon as you find the answer.

You can follow this...

1. Declare a itab with the result field as it's structure.

2. Check whether itab1-field = itab2-field.

3. If they are equal then

check whether the field is present in the itab.

4. If present don't append it.

5. else append it.

6. At last display the itab contents for the result.

Hope this helps you.

Regards,

Maheswaran.B

Message was edited by: Maheswaran B

Former Member
0 Kudos

Hi suresh,

Thankyou for the reply.I got result finally.so,i have given full point to you.

Thanks

Regards,

Nandha

Former Member
0 Kudos

hi,

use the read statement in the loop.

loop at itab1.

read table itab2 with key xyz = itab1-xyz.

if sy-subrc = 0. " Both are matching

endif.

endloop.

Satish