‎2007 May 24 10:28 PM
hello abapers,
in my scenario,
there are two itabs, itab1, itab2.
itab1 has name, marks. as fields.
itab2 has name, marks, sid, fields.
now i have to loop at itab1 and for every name in itab1 i have to check for that name entry in itab2, if found change that marks of that name entry with the itab1 marks. and if not found make a new entry with that name and marks.
can some one help me with this.
does modify help here if entry not found and we have to create a new one.
thank you.
‎2007 May 24 10:34 PM
loop at itab2.
lv_tabix = sy-tabix.
read table itab1 with key name = itab2-name.
if sy-subrc = 0.
itab2-marks = itab1-marks.
modify itab2 index lv_tabix.
else.
itab2-marks = <new marks>.
insert itab2 index lv_tabix.
endif.
endloop.
Regards,
Ravi
‎2007 May 24 10:32 PM
loop at itab1.
loop at itab2 where name = itab1-name.
move itab1-marks to itab2-marks.
modify itab2.
endloop.
if sy-subrc <> 0.
move itab1-name to itab2-name.
move itab1-marks to itab2-marks.
append itab2.
clear itab2.
endloop.
‎2007 May 24 10:33 PM
Something like:
SORT: itab1 BY name,
itab2 BY name.
LOOP AT itab1.
READ TABLE itab2 WITH KEY
name = itab1-name
BINARY SEARCH.
IF sy-subrc = 0.
itab2-marks = itab1-marks.
MODIFY itab2 INDEX sy-tabix.
ELSE.
MOVE-CORRESPONDING itab1 TO itab2.
APPEND itab2.
ENDIF.
ENDLOOP.
Rob
Corrected READ
Message was edited by:
Rob Burbank
‎2007 May 24 10:34 PM
loop at itab2.
lv_tabix = sy-tabix.
read table itab1 with key name = itab2-name.
if sy-subrc = 0.
itab2-marks = itab1-marks.
modify itab2 index lv_tabix.
else.
itab2-marks = <new marks>.
insert itab2 index lv_tabix.
endif.
endloop.
Regards,
Ravi
‎2007 May 24 10:34 PM
See the logic,
you can use modify command..
data : begin of itab1 occurs 0,
name type c,
marks type c,
end of itab1.
data : begin of itab2 occurs 0,
name type c,
marks type c,
sid type c,
end of itab2.
start-of-selection.
loop at itab1.
read table itab2 with key name = itab1-name.
if sy-subrc ne 0.
fill your values
modify itab1.
endif.
endloop.
Reward Points if it is useful
Thanks
Seshu