‎2007 Oct 24 11:24 AM
Hi frnds,
I have 2 internal tables, i_kna1 and i_knvh.
in i_kna1 i have kunnr and name1 are fields. In i_knvh i have kunnr. i want to read the of i_knvh kunnr records from i_kna1 table, because i want to merge the i_knvh kunnr into kna1 name plz advice it. and how to store this in a new internal table.
‎2007 Oct 24 11:35 AM
Hi Gowri sankar,
loop at i_knvh.
read table i_kna1 with key kunnr = i_knvh-kunnr.
itabfinal-kunnr = i_knvh -kunnr.
itabfinal-name = i_kna1-name.
append itabfinal.
clear itabfinal.
endloop.
‎2007 Oct 24 11:26 AM
LOOP AT i_knvh into wa_knvh.
LOOP AT i_kna1 INTO wa_kna1 WHERE kunnr = wa_knvh-kunnr.
your logic.
ENDLOOP.
ENDLOOP.
Regards,
Raghavendra
‎2007 Oct 24 11:28 AM
Hi
You can modify i_kna1 using the loop.
sort: i_kna1 by kunnr,
i_knvh by kunnr.
loop at i_kna1.
READ TABLE i_knvh INTO wa_knvh WITH KEY kunnr = wa_kna1-kunnr
BINARY SEARCH.
if sy-subrc = 0.
*move fields
modify i_kna1 from wa_kna1 index lv_index
transporting f1 f2 f3
endif.
regards
Shiva
‎2007 Oct 24 11:29 AM
loop at i_knvh.
read table i_kna1 with key kunnr = i_knvh-kunnr.
*Move the data from i_knvh and i_kna1 to new table
*append consolidated data into new table.
endloop.
‎2007 Oct 24 11:31 AM
‎2007 Oct 24 11:30 AM
Hi
Try like this
read table i_kna1 WITH KEY kunnr = i_knvh-kunnr.
Regards
Pavan
‎2007 Oct 24 11:34 AM
Hi Gowri,
U can write like this:
sort i_kna1 by kunnr.
sort i_knvh by kunnr.
LOOP AT i_kna1 into wa_kna1.
* This part of code if i_knvh has more than 1 entry for * i_kna1-kunnr.
LOOP AT i_knvh into wa_knvh WHERE kunnr = wa_kna1-kunnr.
concatenate lv_kunnr wa_knvh-kunnr into lv_kunnr.
AT LAST.
wa_knv1-kunnr = wa_kna1-kunnr.
wa_knv1-name1 = lv_kunnr.
append wa_knv1 to i_knv1.
* Lets hope that i_knv1 is ur new internal table
clear wa_knv1.
ENDAT.
ENDLOOP.
* This part of code if i_knvh has more than 1 entry for * i_kna1-kunnr.
* This part of code if i_knvh has 1 entry for
* i_kna1-kunnr.
READ TABLE i_knvh with key kunnr = wa_kna1-kunnr binary search.
IF sy-subrc = 0.
concatenate lv_kunnr wa_knvh-kunnr into lv_kunnr.
wa_knv1-kunnr = wa_kna1-kunnr.
wa_knv1-name1 = lv_kunnr.
append wa_knv1 to i_knv1.
* Lets hope that i_knv1 is ur new internal table
clear wa_knv1.
ENDIF.
* This part of code if i_knvh has 1 entry for
* i_kna1-kunnr.
ENDLOOP.
Hope it works.
Regards,
Phani.<b></b><b></b><b></b>
Message was edited by:
Sivapuram Phani Kumar
‎2007 Oct 24 11:35 AM
Hi Gowri sankar,
loop at i_knvh.
read table i_kna1 with key kunnr = i_knvh-kunnr.
itabfinal-kunnr = i_knvh -kunnr.
itabfinal-name = i_kna1-name.
append itabfinal.
clear itabfinal.
endloop.
‎2007 Oct 24 1:48 PM
Hello Gowri,
For efficiency I would take a look at this code and see if you can use the same type of design for your needs:
DATA: s_ekko TYPE ekko.
DATA: v_tabix TYPE sytabix.
FIELD-SYMBOLS: <fs_item> TYPE ekpo.
SORT: t_ekko BY ebeln,
t_ekpo BY ebeln ebelp.
LOOP AT t_ekko INTO s_ekko.
AT NEW ebeln.
WRITE: / s_ekko-ebeln,
s_ekko-lifnr.
SKIP.
CLEAR v_tabix.
READ TABLE t_ekpo WITH KEY ebeln = s_ekko-ebeln
BINARY SEARCH
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
v_tabix = sy-tabix.
LOOP AT t_ekpo ASSIGNING <fs_item> FROM v_tabix.
IF <fs_item>-ebeln <> s_ekko-ebeln.
EXIT.
ENDIF.
WRITE: / <fs_item>-ebelp,
<fs_item>-matnr,
<fs_item>-menge,
<fs_item>-meins,
<fs_item>-netpr.
ENDLOOP.
ENDIF.
ENDAT.
AT END OF ebeln.
SKIP.
ULINE.
ENDAT.
ENDLOOP.
‎2007 Oct 24 2:10 PM
You question is very unclear, what do you want to read and where do you want to merge it.
Anyway, you must check whether the table are standard tables or could be sorted tables, if they are standard tables, then do it that way:
sort itab1 by ...
loop at itab2
read itab1 .... binary search
endloop.
A loop loop at where coding will cause <b>serious performance problems</b>, same with read without binary search. And only the table with the binary search must be sorted the other one not.
If itab1 is sorted table, then loop at where or read with key are o.k.
Siegfried