2008 Jul 08 9:53 AM
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.)
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
2008 Jul 08 10:03 AM
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.
2008 Jul 08 10:10 AM
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
2008 Jul 08 10:11 AM
Hi,
Try this way,
READ TABLE zpdpld_itab into WA COMPARING ALL FIELDS.
Regards,
Sujit
2008 Jul 08 10:12 AM
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
2008 Jul 08 10:14 AM
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
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |