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

problem on itab

Former Member
0 Likes
514

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
495

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

4 REPLIES 4
Read only

Former Member
0 Likes
495

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.

Read only

Former Member
0 Likes
495

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

Read only

Former Member
0 Likes
496

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

Read only

Former Member
0 Likes
495

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