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

looping loop

Former Member
0 Likes
654

Suppose I have this statement

LOOP AT zpdplh_itab into zpdplh_line.

READ TABLE zpdpld_itab with KEY BUKRS = zpdplh_line-BUKRS BELNR = zpdplh_line-BELNR BUDAT = zpdplh_line-BUDAT TRANSPORTING NO FIELDS.

IF SY-SUBRC NE 0.

WRITE: /5 zpdplh_line-BUKRS

ENDIF.

ENDLOOP.

Basically what it does is to output the fields that does not match between the two table. How do I loop if?

1) I want to compare to internal table

2) which I will then get two fields (let's say A and B) from both tables and compare them with each other

3) if they are the same then I will compare yet another two fields (C and D )to each other from both tables then I will output them if they are not the same (note. diff fields.)

5 REPLIES 5
Read only

Former Member
0 Likes
620

Hi,

You can do in this way

LOOP AT zpdplh_itab into zpdplh_line.

READ TABLE zpdpld_itab into zpdld_line TRANSPORTING NO FIELDS.

if zpdplh_line-bukrs eq zpdld_line-bukrs.

if zpdplh_line-belnr ne zpdld_line-belnr.

WRITE: /5 zpdplh_line-BUKRS

endif.

endif.

ENDLOOP.

Read only

Former Member
0 Likes
620

Hi katrina,

When you use Loop at and Read Table stmt to compare two internal tables, there is no scope for finding multiple entries with the same value. I that case you can try the below code.

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

Let itab1 have two fields A, C & itab2 have two fields B,D.

Loop at itab1 into wa1.

Loop at itab2 into wa2.

If wa1-A NE wa2-B.

write:/ wa1-A 'NE' wa2-B.

else

if wa1-C NE wa2-D.

write:/ wa1-C 'NE' wa2-D.

endif.

endloop.

endloop.

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

Hope this is helpful to you. If you need further information, revert back.

Reward all the helpful answers.

Regards

Nagaraj T

Read only

Former Member
0 Likes
620

Hi,

Try this way,

READ TABLE zpdpld_itab into WA COMPARING ALL FIELDS.

Regards,

Sujit

Read only

Sidh_M
Participant
0 Likes
620

Hi,

suppose thier are two internal tables itab1 and itab2

loop at itab1.

read table itab2 with key <field> = itab1-<field>.

if sy-subrc = 0.

if itab2-A EQ itab1-B.

if itab2-C EQ itab1-D.

else.

(output fields which you want if C & D are not same )

endif.

endif.

endif.

clear itab1.

endloop.

Regards,

SUDHIR MANJAREKAR

Edited by: sudhir manjarekar on Jul 8, 2008 11:12 AM

Read only

bpawanchand
Active Contributor
0 Likes
620

hi

well if the record is fetched from the internal table by READ statement then SY-SUBRC value will be equal to zero and if SY-SUBRC value is 0 then it is wrting the outptu to list

Regards

Pavan