2006 Oct 30 10:48 PM
Hi Experts,
I need to append data from one internal table to another.
The 1st Itab is:
data: begin of itab occurs 0,
vbeln like lips-vbeln,
matnr like lips-matnr,
werks like lips-werks,
charg like lips-charg,
......................
......................
......................
......................
end of itab.
it has data like this:
vbeln matnr werks charg
80004 1045 p157 5789
80005 1042 p157 5789
80005 1098 p157 5789
80005 1065 p157 5789
80005 1030 p157 5789
2nd itab:
data: begin of itab_detail occurs 0,
vbeln like lips-vbeln,
posnr like lips-posnr,
matnr like mara-matnr,
charg like mcha-charg,
werks like marc-werks,
.....................
.....................
.....................
end of itab_detail.
it has data like this:
charg werks vbeln posnr matnr
5656 p157
5789 p157
now i would want to append all the data of itab to itab_detail for the records that exist in itab_detail.
I have tried to look into couple of similar issues posted but could not found to get solution
could anybody of you please help me.
Thanks much.
Message was edited by: sey ni
2006 Oct 30 11:52 PM
Hi,
Try this..I missed the sy-subrc check..
DATA: ITAB_DETAIL_TMP LIKE ITAB_DETAIL OCCURS 0 WITH HEADER LINE.
LOOP AT ITAB_DETAIL.
MOVE-CORRESPONDING ITAB_DETAIL TO ITAB_DETAIL_TMP.
LOOP AT ITAB WHERE CHARG = ITAB_DETAIL-CHARG
AND WERKS = ITAB_DETAIL-WERKS.
MOVE-CORRESPONDING ITAB TO ITAB_DETAIL_TMP.
APPEND ITAB_DETAIL_TMP.
ENDLOOP.
<b>IF SY-SUBRC <> 0.
APPEND ITAB_DETAIL_TMP.
ENDIF.</b>
ENDLOOP.
Thanks,
Naren
2006 Oct 30 11:03 PM
Hi,
Try this..
DATA: ITAB_DETAIL_TMP LIKE ITAB_DETAIL OCCURS 0 WITH HEADER LINE.
LOOP AT ITAB_DETAIL.
MOVE-CORRESPONDING ITAB_DETAIL TO ITAB_DETAIL_TMP.
LOOP AT ITAB WHERE CHARG = ITAB_DETAIL-CHARG
AND WERKS = ITAB_DETAIL-WERKS.
MOVE-CORRESPONDING ITAB TO ITAB_DETAIL_TMP.
APPEND ITAB_DETAIL_TMP.
ENDLOOP.
ENDLOOP.
The internal table ITAB_DETAIL_TMP will contain all the data..
Thanks,
Naren
2006 Oct 30 11:42 PM
Thanks Narendran,
It worked!!!
But 1 record did not transported to itab_detail_tmp.
i.e, charg = 5656
werks = p157.
Could you please suggest what might be the reason?
Thanks,
2006 Oct 30 11:49 PM
Hi,
Please try like this.
data: wa_idx like sy-tabix,
wa_itab like itab,
wa_itab_detail like itab_detail .
loop at itab into wa_itab.
read table itab_detail
with key charg = wa_itab-charg
werks = wa_itab-werks
transporting no fields.
if sy-subrc = 0.
wa_idx = sy-tabix.
wa_itab_detail-vbeln = wa_itab-vbeln.
wa_itab_detail-matnr = wa_itab-matnr.
modify itab_detail index wa_idx from wa_itab_detail
transporting vbeln matnr.
else.
move-correponding wa_itab to wa_itab_detail.
append wa_itab_detail to itab_detail.
endif.
endloop.
Hope this will help.
Regards,
Ferry Lianto
2006 Oct 30 11:52 PM
Hi,
Try this..I missed the sy-subrc check..
DATA: ITAB_DETAIL_TMP LIKE ITAB_DETAIL OCCURS 0 WITH HEADER LINE.
LOOP AT ITAB_DETAIL.
MOVE-CORRESPONDING ITAB_DETAIL TO ITAB_DETAIL_TMP.
LOOP AT ITAB WHERE CHARG = ITAB_DETAIL-CHARG
AND WERKS = ITAB_DETAIL-WERKS.
MOVE-CORRESPONDING ITAB TO ITAB_DETAIL_TMP.
APPEND ITAB_DETAIL_TMP.
ENDLOOP.
<b>IF SY-SUBRC <> 0.
APPEND ITAB_DETAIL_TMP.
ENDIF.</b>
ENDLOOP.
Thanks,
Naren