2007 Sep 11 12:50 PM
Hi,
i have few read statements within loop ...endloop as shown:
LOOP AT t_pbim INTO wa_pbim.
READ TABLE t_zpp_material
INTO wa_zpp_material
WITH KEY smatn_new = wa_pbim-matnr.
wa_final-product = wa_zpp_material-product.
wa_final-smatn_old = wa_zpp_material-smatn_old .
wa_final-smatn_new = wa_zpp_material-smatn_new .
wa_final-plant = wa_zpp_material-plant.
wa_final-zdate1 = wa_zpp_material-zdate1.
READ TABLE t_pbed
INTO wa_pbed
WITH KEY bdzei = wa_pbim-bdzei .
wa_final-perxx = wa_pbed-perxx.
READ TABLE t_mdbs
INTO wa_mdbs
WITH KEY matnr = wa_pbim-matnr.
wa_final-val = wa_mdbs-val.
wa_final-meins = wa_mdbs-meins.
append wa_final to t_final.
endloop.
The second read statement finds one matching records with the key value given.but as it is in the loop,that single entry is duplicated in t_final.
please mention how to resolve the issue.
Hi,
if you want to ensure the result is unique, do not use append but use COLLECT wa INTO itab.
Regards,
Gianpietro
2007 Sep 11 12:56 PM
Hi,
THe code is absolutely fine. But if you want unique data based on BDZEI, then delete duplicates from T_PBIM
<b>SORT T_PBIM by BDZEI.
DELETE ADJACENT DUPLICATES FROM T_PBIM COMPARING BDZEI.</b>
LOOP AT t_pbim INTO wa_pbim.
READ TABLE t_zpp_material
INTO wa_zpp_material
WITH KEY smatn_new = wa_pbim-matnr.
wa_final-product = wa_zpp_material-product.
wa_final-smatn_old = wa_zpp_material-smatn_old .
wa_final-smatn_new = wa_zpp_material-smatn_new .
wa_final-plant = wa_zpp_material-plant.
wa_final-zdate1 = wa_zpp_material-zdate1.
READ TABLE t_pbed
INTO wa_pbed
WITH KEY bdzei = wa_pbim-bdzei .
wa_final-perxx = wa_pbed-perxx.
READ TABLE t_mdbs
INTO wa_mdbs
WITH KEY matnr = wa_pbim-matnr.
wa_final-val = wa_mdbs-val.
wa_final-meins = wa_mdbs-meins.
append wa_final to t_final.
endloop.
2007 Sep 11 12:56 PM
Hi Deb,
clear the table headers before each READ.
<b><REMOVED BY MODERATOR></b>
Karthik
Message was edited by:
Alvaro Tejada Galindo
2007 Sep 11 1:00 PM
2007 Sep 11 1:05 PM
Hi,
if you want to ensure the result is unique, do not use append but use COLLECT wa INTO itab.
Regards,
Gianpietro
2007 Sep 11 12:56 PM
LOOP AT t_pbim INTO wa_pbim.
READ TABLE t_zpp_material
INTO wa_zpp_material
WITH KEY smatn_new = wa_pbim-matnr.
wa_final-product = wa_zpp_material-product.
wa_final-smatn_old = wa_zpp_material-smatn_old .
wa_final-smatn_new = wa_zpp_material-smatn_new .
wa_final-plant = wa_zpp_material-plant.
wa_final-zdate1 = wa_zpp_material-zdate1.
READ TABLE t_pbed
INTO wa_pbed
WITH KEY bdzei = wa_pbim-bdzei .
wa_final-perxx = wa_pbed-perxx.
READ TABLE t_mdbs
INTO wa_mdbs
WITH KEY matnr = wa_pbim-matnr.
wa_final-val = wa_mdbs-val.
wa_final-meins = wa_mdbs-meins.
append wa_final to t_final.
endloop.
add the following code to ur code...
delete the entry from second internal table after first occurance of the loop..
the syntax will be like this,,,
delete it_2 from wa_2 index sy-tabix.
ok
<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo
2007 Sep 11 12:58 PM
try the read statement with Binary search
or use DELETE ADJACENT DUPLICATES
2007 Sep 11 1:10 PM
Hi,
Whenever you use a read statement always check for sy-subrc .
modify the code as follows:
LOOP AT t_pbim INTO wa_pbim.
READ TABLE t_zpp_material
INTO wa_zpp_material
WITH KEY smatn_new = wa_pbim-matnr.
wa_final-product = wa_zpp_material-product.
wa_final-smatn_old = wa_zpp_material-smatn_old .
wa_final-smatn_new = wa_zpp_material-smatn_new .
wa_final-plant = wa_zpp_material-plant.
wa_final-zdate1 = wa_zpp_material-zdate1.
READ TABLE t_pbed
INTO wa_pbed
WITH KEY bdzei = wa_pbim-bdzei .
<b>if sy-subrc eq 0.</b>
wa_final-perxx = wa_pbed-perxx.
<b>endif.</b>
READ TABLE t_mdbs
INTO wa_mdbs
WITH KEY matnr = wa_pbim-matnr.
<b>if sy-subrc eq 0.</b>
wa_final-val = wa_mdbs-val.
wa_final-meins = wa_mdbs-meins.
<b>endif.</b>
append wa_final to t_final.
endloop.
regards,
Navneeth K.
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |