‎2007 Jul 05 12:29 PM
Hi, I have 2 internaltables (each has 1 column). They have different content but some fields are equal. Now I want to make 3-rd internaltable (with 2 columns) in which records will contain equal values from itab1 abd itab2 in upper part of itab3, and those which are not equal will be further. So it should look like:
a | a
b | b
c | c
d | d
e | e
f |
g |
How to achieve that? Greetings. P.
‎2007 Jul 05 12:35 PM
""this code will give you the matching values....
loop at itab1.
clear wa_itab3.
loop at itab2 where <field> = itab1-<field>
wa_itab3-<field1>= "your value here"
wa_itab3-<field2>= "your value here"
if wa_itab3 is not initial.
append wa_itab3 to itab_3.
endif.
endloop.
endloop.
one way to find the non. matching values could be that (if possible) you keep deleting the rows of itab 1 and itab2 for the matches you have found above.....the remaining rows now will be the ones which you need at the end of your third internal table....if you don't want to delete, probably you can go for another internal table...
regards,
PJ
‎2007 Jul 05 12:33 PM
Hi,
Use loop and then use read table and move the data from this table to that
finally move the records which are not there in table and which not in other table
by checking the sy-subrc value after read table
Regards
Shiva
‎2007 Jul 05 12:35 PM
""this code will give you the matching values....
loop at itab1.
clear wa_itab3.
loop at itab2 where <field> = itab1-<field>
wa_itab3-<field1>= "your value here"
wa_itab3-<field2>= "your value here"
if wa_itab3 is not initial.
append wa_itab3 to itab_3.
endif.
endloop.
endloop.
one way to find the non. matching values could be that (if possible) you keep deleting the rows of itab 1 and itab2 for the matches you have found above.....the remaining rows now will be the ones which you need at the end of your third internal table....if you don't want to delete, probably you can go for another internal table...
regards,
PJ
‎2007 Jul 05 12:35 PM
HI,
let fields of itab1 and itab2 be fld1
Loop at itab1 into wa1.
read table itab2 into wa2 where fld1 = wa1-fld1.
if sy-subrc = 0.
wafinal-fld1 = wa1-fld1.
wafinal-fld2 = wa2-fld1.
else.
wafinalfld1 = wa1-fld1.
endif.
endloop.
the above logic will workout
rewards if useful,
regards,
nazeer.
‎2007 Jul 05 12:38 PM
Hello friend,
Try this and reward if found helpfull.
Regards
Rakesh.
loop at itab1 into wrk_area1.
read table itab2 with key wrk_field = wrk_area1-field.
if sy-subrc = 0.
append wrk_area to itab3.
else.
append wrk_area to itab4.
endif.
endloop.
Loop at itab4 into wrk_area2.
append wrk_area2 to itab3.
endloop.
‎2007 Jul 05 12:45 PM
Use this code:
LOOP AT itab1 INTO wa_itab1.
READ itab2 INTO wa_itab2 WITH KEY field = wa_itab1-field.
IF sy-subrc = 0.
CLEAR wa_itab3.
wa_itab3-field1 = wa_itab1-field.
wa_itab3-field2 = wa_itab2-field.
APPEND wa_itab3 TO itab3.
ELSE.
wa_itab3-field1 = wa_itab1-field.
APPEND wa_itab3 TP wa_itab3temp.
ELSEIF.
ENDLOOP.
APPEND LINES OF itab3temp TO itab3.
null
‎2007 Jul 05 12:50 PM
Hi,
see this simple code.
loop at itab1.
read TABLE itab2 from itab1.
if sy-subrc = 0.
insert itab1 into itab3 index 1.
else.
append itab1 to itab3.
endif.
ENDLOOP.
rgds,
bharat.
‎2007 Jul 05 1:14 PM
REPORT ZTEST3.
DATA:
BEGIN OF ITAB1 OCCURS 0,
VALUE(1),
END OF ITAB1,
ITAB2 LIKE TABLE OF ITAB1 WITH HEADER LINE,
ITAB3 LIKE TABLE OF ITAB1 WITH HEADER LINE,
ITAB4 LIKE TABLE OF ITAB1 WITH HEADER LINE.
ITAB1-VALUE = 'a'.
APPEND ITAB1.
ITAB1-VALUE = 'b'.
APPEND ITAB1.
ITAB1-VALUE = 'c'.
APPEND ITAB1.
ITAB1-VALUE = 'd'.
APPEND ITAB1.
ITAB1-VALUE = 'e'.
APPEND ITAB1.
ITAB1-VALUE = 'f'.
APPEND ITAB1.
ITAB1-VALUE = 'g'.
APPEND ITAB1.
ITAB2-VALUE = 'a'.
APPEND ITAB2.
ITAB2-VALUE = 'b'.
APPEND ITAB2.
ITAB2-VALUE = 'c'.
APPEND ITAB2.
ITAB2-VALUE = 'd'.
APPEND ITAB2.
ITAB2-VALUE = 'e'.
APPEND ITAB2.
sort ITAB1.
sort ITAB2.
loop at ITAB1.
read table ITAB2 with key VALUE = ITAB1-VALUE binary search.
if sy-subrc eq 0.
ITAB3-VALUE = ITAB1-VALUE.
APPEND ITAB3.
DELETE TABLE ITAB2 FROM ITAB1.
else.
ITAB4-VALUE = ITAB1-VALUE.
APPEND ITAB4.
endif.
endloop.
*ITAB2 AND ITAB4 NOW CONTAINS VALUES NOT MATCHING IN ITAB1 AND ITAB2
*AND ITAB3 CONTAINS MATCHING VALUES
APPEND LINES OF ITAB2 TO ITAB3.
APPEND LINES OF ITAB4 TO ITAB3.
LOOP AT ITAB3.
WRITE:/ ITAB3-VALUE.
ENDLOOP.