2007 Jan 23 4:54 PM
I need to enhance a master data datasource with additional fields STPRS, PEINH from MBEW table and WAERS (currency for STPRS) from T001 table. Table T001 and MBEW table have no fields in common. So I took an indirect approach to this.I have a program for enhancing a BW DataSource in R/3. Here is the code:
**************************************************************************************
types: begin of zty_waers,
bukrs type bukrs,
waers type waers,
bwkey type bwkey,
end of zty_waers.
data: zit_waers type standard table of zty_waers,
wa_waers like line of zit_waers.
DATA : it_temp type standard table of biw_marc_s,
wa_temp like line of it_temp,
S_INDEX TYPE SY-TABIX,
z_index type sy-tabix.
DATA : BEGIN OF ITAB_MBEW OCCURS 0,
MATNR TYPE MATNR,
BWKEY TYPE BWKEY,
STPRS TYPE STPRS,
PEINH type PEINH,
WAERS type WAERS,
END OF ITAB_MBEW.
data: wa_mbew like line of itab_mbew.
DATA: BEGIN OF ITAB_CEPC OCCURS 0,
PRCTR LIKE CEPC-PRCTR,
KOKRS LIKE CEPC-KOKRS,
DATBI LIKE CEPC-DATBI,
SEGMENT LIKE CEPC-SEGMENT,
END OF ITAB_CEPC.
select abukrs awaers b~bwkey into table zit_waers
from t001 as a inner join t001k as b on
abukrs = bbukrs.
IF NOT I_T_DATA[] IS INITIAL.
IT_TEMP[] = I_T_DATA[].
SELECT MATNR BWKEY STPRS PEINH FROM MBEW INTO TABLE ITAB_MBEW FOR ALL ENTRIES IN IT_TEMP
WHERE MATNR = IT_TEMP-MATNR and BWKEY = IT_TEMP-WERKS.
SELECT PRCTR KOKRS DATBI SEGMENT FROM CEPC INTO TABLE ITAB_CEPC FOR ALL ENTRIES IN IT_TEMP
WHERE PRCTR = IT_TEMP-PRCTR AND KOKRS = IT_TEMP-KOKRS AND DATBI = '99991231'.
ELSE.
EXIT.
ENDIF.
loop at itab_mbew into wa_mbew.
z_index = sy-tabix.
read table zit_waers into wa_waers with key bwkey = wa_mbew-bwkey.
if sy-subrc = 0.
wa_mbew-waers = wa_waers-waers.
endif.
modify itab_mbew from wa_mbew transporting waers.
endloop.
sort itab_mbew by matnr.
loop at i_t_data into wa_temp.
s_index = sy-tabix.
Read Table itab_mbew with key matnr = wa_temp-matnr
into wa_mbew.
if sy-subrc = 0.
wa_temp-zzstprs = wa_mbew-stprs.
wa_temp-zzwaers = wa_mbew-waers.
wa_temp-zzpeinh = wa_mbew-peinh.
endif.
Sort itab_cepc.
Read Table itab_CEPC
with key PRCTR = wa_temp-PRCTR
KOKRS = wa_temp-KOKRS
binary search.
if sy-subrc = 0.
wa_temp-ZZSEGMENT = itab_CEPC-SEGMENT.
endif.
modify i_t_data from wa_temp.
clear wa_temp.
endloop.
*************************************************************************
I_T_DATA table has entries from the DataSource MAT_PLANT. But when I am testing the datasource for the new fields the data is coming out wrong. For example if I run the extractor checker RSA3 for material number 10000306 and plants 1017 - 1021 i extract 2 entries and the stprs values are same for both plants
But if I run RSA3 for 1021 alone then i get another value for 1021 plant. This means the STPRS value is getting overwritten for some reason. Debugging of this code is very difficult since it is embedded in another program.
Can anyone tell me wht is wrong with the logic?
Thanks
Deepthi
2007 Jan 23 5:17 PM
Hi,
In the read table itab_mbew..Try adding the bwkey also..changes marked in bold..
sort itab_mbew by matnr.
loop at i_t_data into wa_temp.
s_index = sy-tabix.
Read Table itab_mbew with key matnr = wa_temp-matnr
<b> bwkey = wa_temp-werks</b>.
into wa_mbew.
if sy-subrc = 0.
wa_temp-zzstprs = wa_mbew-stprs.
wa_temp-zzwaers = wa_mbew-waers.
wa_temp-zzpeinh = wa_mbew-peinh.
endif.
Thanks,
Naren
I need to enhance a master data datasource with additional fields STPRS, PEINH from MBEW table and WAERS (currency for STPRS) from T001 table. Table T001 and MBEW table have no fields in common. So I took an indirect approach to this.I have a program for enhancing a BW DataSource in R/3. Here is the code:
**************************************************************************************
types: begin of zty_waers,
bukrs type bukrs,
waers type waers,
bwkey type bwkey,
end of zty_waers.
data: zit_waers type standard table of zty_waers,
wa_waers like line of zit_waers.
DATA : it_temp type standard table of biw_marc_s,
wa_temp like line of it_temp,
S_INDEX TYPE SY-TABIX,
z_index type sy-tabix.
DATA : BEGIN OF ITAB_MBEW OCCURS 0,
MATNR TYPE MATNR,
BWKEY TYPE BWKEY,
STPRS TYPE STPRS,
PEINH type PEINH,
WAERS type WAERS,
END OF ITAB_MBEW.
data: wa_mbew like line of itab_mbew.
DATA: BEGIN OF ITAB_CEPC OCCURS 0,
PRCTR LIKE CEPC-PRCTR,
KOKRS LIKE CEPC-KOKRS,
DATBI LIKE CEPC-DATBI,
SEGMENT LIKE CEPC-SEGMENT,
END OF ITAB_CEPC.
select abukrs awaers b~bwkey into table zit_waers
from t001 as a inner join t001k as b on
abukrs = bbukrs.
IF NOT I_T_DATA[] IS INITIAL.
IT_TEMP[] = I_T_DATA[].
SELECT MATNR BWKEY STPRS PEINH FROM MBEW INTO TABLE ITAB_MBEW FOR ALL ENTRIES IN IT_TEMP
WHERE MATNR = IT_TEMP-MATNR and BWKEY = IT_TEMP-WERKS.
SELECT PRCTR KOKRS DATBI SEGMENT FROM CEPC INTO TABLE ITAB_CEPC FOR ALL ENTRIES IN IT_TEMP
WHERE PRCTR = IT_TEMP-PRCTR AND KOKRS = IT_TEMP-KOKRS AND DATBI = '99991231'.
ELSE.
EXIT.
ENDIF.
loop at itab_mbew into wa_mbew.
z_index = sy-tabix.
read table zit_waers into wa_waers with key bwkey = wa_mbew-bwkey.
if sy-subrc = 0.
wa_mbew-waers = wa_waers-waers.
endif.
modify itab_mbew from wa_mbew transporting waers.
endloop.
sort itab_mbew by matnr.
loop at i_t_data into wa_temp.
s_index = sy-tabix.
Read Table itab_mbew with key matnr = wa_temp-matnr
into wa_mbew.
if sy-subrc = 0.
wa_temp-zzstprs = wa_mbew-stprs.
wa_temp-zzwaers = wa_mbew-waers.
wa_temp-zzpeinh = wa_mbew-peinh.
endif.
Sort itab_cepc.
Read Table itab_CEPC
with key PRCTR = wa_temp-PRCTR
KOKRS = wa_temp-KOKRS
binary search.
if sy-subrc = 0.
wa_temp-ZZSEGMENT = itab_CEPC-SEGMENT.
endif.
modify i_t_data from wa_temp.
clear wa_temp.
endloop.
*************************************************************************
I_T_DATA table has entries from the DataSource MAT_PLANT. But when I am testing the datasource for the new fields the data is coming out wrong. For example if I run the extractor checker RSA3 for material number 10000306 and plants 1017 - 1021 i extract 2 entries and the stprs values are same for both plants
But if I run RSA3 for 1021 alone then i get another value for 1021 plant. This means the STPRS value is getting overwritten for some reason. Debugging of this code is very difficult since it is embedded in another program.
Can anyone tell me wht is wrong with the logic?
Thanks
Deepthi
2007 Jan 23 5:17 PM
Hi,
In the read table itab_mbew..Try adding the bwkey also..changes marked in bold..
sort itab_mbew by matnr.
loop at i_t_data into wa_temp.
s_index = sy-tabix.
Read Table itab_mbew with key matnr = wa_temp-matnr
<b> bwkey = wa_temp-werks</b>.
into wa_mbew.
if sy-subrc = 0.
wa_temp-zzstprs = wa_mbew-stprs.
wa_temp-zzwaers = wa_mbew-waers.
wa_temp-zzpeinh = wa_mbew-peinh.
endif.
Thanks,
Naren
2007 Jan 23 5:24 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |