‎2006 Nov 26 9:10 PM
In a FM I have to check records of two ITABs against each other. Most fields can be checked 1:1 but some must be checked according to some business logic.
I first want to check field-by-field and then I want to deal with exceptions.
Question: How can I loop over fields in an ITAB in such a manner that I can compare fields?
‎2006 Nov 26 10:01 PM
Hi, you can loop thru the columns(fields) of an internal table like so.
field-symbols: <fs>.
loop at itab.
do.
* Here you can use the field name instead of SY-INDEX
assign component sy-index of structure itab to <fs>.
if sy-subrc <>.
exit.
endif.
* Now that you have access to the field via field symbol, you can compare
* this value.
Write:/ <fs>.
enddo.
endloop.Regards,
Rich Heilman
‎2006 Nov 26 10:01 PM
Hi, you can loop thru the columns(fields) of an internal table like so.
field-symbols: <fs>.
loop at itab.
do.
* Here you can use the field name instead of SY-INDEX
assign component sy-index of structure itab to <fs>.
if sy-subrc <>.
exit.
endif.
* Now that you have access to the field via field symbol, you can compare
* this value.
Write:/ <fs>.
enddo.
endloop.Regards,
Rich Heilman
‎2006 Nov 27 4:09 AM
Suggestion:
Loop at Itab1.
Read itab2 with key XXX = itab2-field1 using index.
Comapre things.
Endloop.
Regards,
Mohan.
*Reward if helpful*
‎2006 Nov 27 4:20 AM
Hi Jans,
Consider that you have two internal tables ITAB1 & ITAB2.
If your table ITAB2 has got multiple entries for the same set of values for ITAB1 then you can use as under:
<b>LOOP AT ITAB1.
LOOP AT ITAB2 where <condition> EQ <ITAB1-->'Condition'>
ENDLOOP.
ENDLOOP.</b>
If ITAB2 has just got one corresponding entry for the value in ITAB1, then you can use the read statement as under:
<b>LOOP AT ITAB1.
READ TABLE ITAB2 WITH KEY <field for comaprison> EQ <>
IF SY-SUBRC EQ 0.
ELSE.
<You can treat your exception conditions here>
ENDIF.</b>
Regards,
Chetan.
PS: Reward points if this helps.