pdm和SAP创建BOM接口-创新互联
SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style. italic;
color: #808080;
}
.L0S32 {
color: #3399FF;
}
.L0S33 {
color: #4DA619;
}
.L0S52 {
color: #0000FF;
}
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(MATERIAL) TYPE CSAP_MBOM-MATNR OPTIONAL
*" VALUE(PLANT) TYPE CSAP_MBOM-WERKS OPTIONAL
*" VALUE(BOM_USAGE) TYPE CSAP_MBOM-STLAN OPTIONAL
*" VALUE(ALTERNATIVE) TYPE CSAP_MBOM-STLAL OPTIONAL
*" VALUE(VALID_FROM) TYPE CSAP_MBOM-DATUV OPTIONAL
*" VALUE(CHANGE_NO) TYPE CSAP_MBOM-AENNR OPTIONAL
*" VALUE(REVISION_LEVEL) TYPE CSAP_MBOM-REVLV OPTIONAL
*" VALUE(I_STKO) TYPE STKO_API01 OPTIONAL
*" VALUE(FL_NO_CHANGE_DOC) TYPE CAPIFLAG-NO_CHG_DOC DEFAULT SPACE
*" VALUE(FL_COMMIT_AND_WAIT) TYPE CAPIFLAG-COMM_WAIT DEFAULT 'X'
*" VALUE(FL_CAD) TYPE CSDATA-CHAR1 DEFAULT SPACE
*" VALUE(FL_BOM_CREATE) TYPE CSDATA-XFELD DEFAULT 'X'
*" VALUE(FL_NEW_ITEM) TYPE CSDATA-XFELD DEFAULT 'X'
*" VALUE(FL_COMPLETE) TYPE CSDATA-XFELD DEFAULT SPACE
*" VALUE(FL_DEFAULT_VALUES) TYPE CSDATA-XFELD DEFAULT 'X'
*" VALUE(FL_IDENTIFY_BY_GUID) TYPE CSDATA-XFELD DEFAULT SPACE
*" VALUE(IS_UPDATE_STATUS) TYPE CHAR1 DEFAULT ''
*" EXPORTING
*" VALUE(FL_WARNING) LIKE CAPIFLAG-FLWARNING
*" VALUE(O_STKO) LIKE STKO_API02 STRUCTURE STKO_API02
*" VALUE(MATERIAL1) LIKE CSAP_MBOM-MATNR
*" VALUE(RETURN) TYPE CHAR100
*" VALUE(RETURN2) TYPE CHAR100
*" VALUE(PRO_CODE) TYPE CHAR1
*" TABLES
*" T_STPO STRUCTURE STPO_API03 OPTIONAL
*" T_DEP_DATA STRUCTURE CSDEP_DAT OPTIONAL
*" T_DEP_DESCR STRUCTURE CSDEP_DESC OPTIONAL
*" T_DEP_ORDER STRUCTURE CSDEP_ORD OPTIONAL
*" T_DEP_SOURCE STRUCTURE CSDEP_SORC OPTIONAL
*" T_DEP_DOC STRUCTURE CSDEP_DOC OPTIONAL
*" T_DOC_LINK STRUCTURE CSDOC_LINK OPTIONAL
*" T_DMU_TMX STRUCTURE CSDMU_TMX OPTIONAL
*" T_LTX_LINE STRUCTURE CSLTX_LINE OPTIONAL
*" T_STPU STRUCTURE STPU_API01 OPTIONAL
*"----------------------------------------------------------------------
* 项目文本只放在项目文本1,项目文本2放替代组,,需要将项目文本2中的3位替代组转成一个2位的放入原有2位替代组
data: w_matnr like csap_mbom-matnr.
data w_stlan type mast-stlan.
clear w_stlan.
data wa_sbdkz like marc-sbdkz.
clear wa_sbdkz.
*取物料的生命周期状态。
data: w_mstae type mara-mstae.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = material
importing
output = material.
select single mstae into w_mstae
from mara where matnr = material.
if sy-subrc eq 0.
if w_mstae = '26' or w_mstae = '27' or w_mstae = '22' ."试产\生产\停产
bom_usage = '1'.
else.
if w_mstae = '25'. "开发
bom_usage = 'A'.
else.
concatenate '物料:' material+9(9) '生命周期状态不在范围内(22、25、26、27)' into
return.
pro_code = 3.
return..
endif.
endif.
else.
concatenate '物料:' material '没有找到生命周期状态' into
return.
pro_code = 3.
return..
endif.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = material
importing
output = w_matnr.
select single stlan into w_stlan
from mast
where werks = plant and matnr = w_matnr and stlan = bom_usage.
if sy-subrc eq 0 and w_stlan eq bom_usage.
return = 'BOM已经存在,不用创建'.
pro_code = 2.
if pro_code eq 2. "70检查
call function 'ZPDM_BOM_CHANGE_MAT'
exporting
matnr = material
plant_s = plant
stlan = '1'
* stlst = 1
p_d1 = 'X'
return_i = return
importing
return_e = return
pro_code = pro_code.
endif.
*
return.
endif.
*替代组中物料和BOM中的BOM物料要相同 MODIFY BY LU.X 2010.08.09
data i_stpo like table of stpo_api03 with header line.
data: i_zbomstd like table of zbomstd with header line.
"检查下层半品是否都有BOM.
data i_halb like table of stpo_api03 with header line."所有半品
data l_matnr like mara-matnr."
data l_count_halb type i.
data l_count_mast type i.
"检查下层半品是否都有BOM.
if t_stpo[] is not initial.
select matnr
into corresponding fields of table i_halb
from mara
for all entries in t_stpo
where matnr = t_stpo-component and mtart = 'ZHLB'.
if i_halb[] is not initial.
loop at i_halb.
select single matnr "查物料BOM是否存在
into l_matnr
from mast
where matnr = i_halb-component and werks = plant.
if sy-subrc ne 0.
* SELECT SINGLE matnr "查订单BOM是否存在
* INTO l_matnr
* FROM kdst
* WHERE matnr = i_halb-component AND werks = plant.
concatenate '子件:' i_halb-component+9(9) '的BOM不存在,不能创建BOM:' into return.
pro_code = 3.
return..
endif.
endloop.
endif.
endif.
clear i_zbomstd[].
i_stpo[] = t_stpo[].
delete i_stpo where item_text2 is initial.
delete adjacent duplicates from i_stpo comparing item_text2.
if i_stpo[] is not initial.
loop at i_stpo. "计算每一个替代组中的物料和替代库中是否完全相同
clear i_zbomstd[].
select alpgr matnr
into corresponding fields of table i_zbomstd
from zbomstd
where alpgr = i_stpo-item_text2 and xloek ne 'X'.
loop at i_zbomstd.
read table t_stpo with key component = i_zbomstd-matnr+9(9) item_text2 = i_zbomstd-alpgr.
if sy-subrc ne 0.
concatenate '替带库:' i_stpo-item_text2 '中的物料:' i_zbomstd-matnr+9(9)
'在BOM中不存在' into return.
pro_code = 3.
return..
endif.
endloop.
endloop.
endif.
*替代组中物料和BOM中的BOM物料要相同 MODIFY BY LU.X 2010.08.09
* 先将所有的项目文本二的值转成2位的替代组。
data: wa_item_text2 like stpo_api03-item_text2,wa_sortstring like stpo_api03-sortstring.
data: wa_ai_group type i.
wa_ai_group = 9.
sort t_stpo by item_text2 sortstring."当替代组号相同排序字符串也相同时才用相同的两位替代组 MODIFY BY LU.X 2010.08.20
wa_item_text2 = ''.
wa_sortstring = ''.
loop at t_stpo where item_text2 is not initial.
if ( wa_item_text2 ne t_stpo-item_text2 ) or ( wa_sortstring ne t_stpo-sortstring ).
wa_ai_group = wa_ai_group + 1.
wa_item_text2 = t_stpo-item_text2.
wa_sortstring = t_stpo-sortstring.
endif.
t_stpo-ai_group = wa_ai_group.
modify t_stpo.
endloop.
tables: msta.
i_stko-base_quan = 1.
* I_STKO-BOM_STATUS = '01'.
data: lt_zbomfix like table of zbomfix with header line ,lt_zbomstd like table of zbomstd with header line.
select * into corresponding fields of table lt_zbomfix
from zbomfix .
sort lt_zbomfix by matnr.
select * into corresponding fields of table lt_zbomstd
from zbomstd where xloek <>'X'..
sort lt_zbomstd by matnr.
if t_stpo[] is initial and is_update_status = ''.
concatenate '物料:' material '没有子件信息,不能创建BOM!' into return.
pro_code = 3.
return..
endif.
*检查母件MRP视图存在
* data W_DISMM TYPE MARc-DISMM.
* SELECT SINGLE DISMM INTO W_DISMM FROM MARC
* WHERE MATNR = MATERIAL AND WERKS = PLANT.
* IF SY-SUBRC NE 0.
*
* ENDIF.
*
* SELECT SINGLE * FROM msta WHERE matnr = material AND statm = 'D' AND werks = plant.
* IF sy-subrc NE 0.
* pro_code = 3.
* CONCATENATE material+9(9) '母件MRP视图未建立,不能建立BOM' INTO return.
* return2 = return.
* RETURN.
* ENDIF.
select single sbdkz into wa_sbdkz
from marc where matnr = material and werks = plant
and dismm is not null "MRP 类型
and beskz is not null "采购类型
and mtvfp = '02' "可用性检查
and sbdkz = '1' "独立/集中
and sfcpf is not null. "生产计划参数文件
if sy-subrc ne 0.
pro_code = 3.
concatenate material+9(9) '母件MRP视图未建立,不能建立BOM' into return.
return2 = return.
return.
endif.
*固定数量和替代组处理
loop at t_stpo.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = t_stpo-component
importing
output = t_stpo-component.
**子件MRP视图检查
* SELECT SINGLE * FROM msta WHERE matnr = t_stpo-component AND statm = 'D' AND werks = plant.
* IF sy-subrc NE 0.
* pro_code = 3.
* CONCATENATE t_stpo-component+9(9) '子件MRP视图未建立,不能建立BOM' INTO return.
* return2 = return.
* RETURN.
* ENDIF.
**子件MRP视图检查
select single sbdkz into wa_sbdkz
from marc where matnr = t_stpo-component and werks = plant
and dismm is not null "MRP 类型
and beskz is not null "采购类型
and mtvfp = '02' "可用性检查
and sbdkz is not null. "独立/集中
* AND sfcpf IS NOT NULL. "生产计划参数文件
if sy-subrc ne 0.
pro_code = 3.
concatenate t_stpo-component+9(9) '子件MRP视图未建立,不能建立BOM' into return.
return2 = return.
return.
endif.
*固定数量
read table lt_zbomfix with key matnr = t_stpo-component.
if sy-subrc = 0.
t_stpo-fixed_qty = 'X'.
* modify t_stpo.
endif.
*替代组处理
if t_stpo-ai_group is not initial.
* read table lt_ZBOMSTD with key matnr = t_stpo-COMPONENT ALPGR = t_stpo-ai_group.
*原来替代组放在了ITEM_TEXT2中,需要程序3位转成两位放入AI_GROUP
read table lt_zbomstd with key matnr = t_stpo-component alpgr =
t_stpo-item_text2.
if sy-subrc = 0.
* t_stpo-AI_GROUP = lt_ZBOMSTD-alpgr."替代项目:组
t_stpo-ai_prio = lt_zbomstd-alprf."替代项目(优先级)
t_stpo-usage_prob = lt_zbomstd-ewahr."使用可能性按
else.
concatenate '物料:' t_stpo-component+9(9) ' 替代组:' t_stpo-item_text2 'SAP未维护' into return.
pro_code = 3.
return..
endif.
endif.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = t_stpo-component
importing
output = t_stpo-component.
t_stpo-rel_cost = 'X'. "成本核算标识打钩
modify t_stpo.
endloop.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = material
importing
output = material.
if sy-datum <= '20100704'. "为上线后可以展工单BOM成功
call function 'CSAP_MAT_BOM_MAINTAIN'
exporting
material = material
plant = plant
bom_usage = bom_usage
valid_from = '20100501'
change_no = change_no
* REVISION_LEVEL =
i_stko = i_stko
fl_bom_create = fl_bom_create
fl_new_item = fl_new_item
* FL_NO_CHANGE_DOC = ' '
* FL_COMMIT_AND_WAIT = ' '
* FL_CAD = ' '
* FL_DEFAULT_VALUES = 'X'
* fl_commit_and_wait = 'X'
* fl_default_values = 'X'
importing
fl_warning = fl_warning
o_stko = o_stko
tables
t_stpo = t_stpo
* T_DEP_DATA =
* T_DEP_DESCR =
* T_DEP_ORDER =
* T_DEP_SOURCE =
* T_DEP_DOC =
* T_LTX_LINE =
t_stpu = t_stpu
exceptions
error = 1
others = 2.
else.
call function 'CSAP_MAT_BOM_MAINTAIN'
exporting
material = material
plant = plant
bom_usage = bom_usage
* valid_from = SY-DATUM
change_no = change_no
* REVISION_LEVEL =
i_stko = i_stko
fl_bom_create = fl_bom_create
fl_new_item = fl_new_item
* FL_NO_CHANGE_DOC = ' '
* FL_COMMIT_AND_WAIT = ' '
* FL_CAD = ' '
* FL_DEFAULT_VALUES = 'X'
* fl_commit_and_wait = 'X'
* fl_default_values = 'X'
importing
fl_warning = fl_warning
o_stko = o_stko
tables
t_stpo = t_stpo
* T_DEP_DATA =
* T_DEP_DESCR =
* T_DEP_ORDER =
* T_DEP_SOURCE =
* T_DEP_DOC =
* T_LTX_LINE =
t_stpu = t_stpu
exceptions
error = 1
others = 2.
endif.
commit work.
if sy-msgty ne 'S'.
pro_code = 3.
else.
pro_code = 2.
endif.
clear t_stpo[].
clear t_stpu[].
call function 'MESSAGE_TEXT_BUILD'
exporting
msgid = sy-msgid
msgnr = sy-msgno
msgv1 = sy-msgv1
msgv2 = sy-msgv2
msgv3 = sy-msgv3
msgv4 = sy-msgv4
importing
message_text_output = return.
if sy-subrc <> 0.
return2 = return+12(10).
write:/ '建立时错误信息:','工厂:',plant, return2 color col_negative.
* WRITE: return2.
else.
write:/ return2.
write:/ '建立时信息:','工厂:',plant,return color col_positive.
endif.
if pro_code eq 2.
call function 'ZPDM_BOM_CHANGE_MAT'
exporting
matnr = material
plant_s = plant
stlan = bom_usage
* stlst = 1
p_d1 = 'X'
* aennr = aennr
return_i = return
importing
return_e = return
pro_code = pro_code
.
endif.
data: plnnr_001 like bdcdata-fval,
matnr_001 like bdcdata-fval.
data: l_mstae like mara-mstae.
data: l_subrc like syst-subrc.
data: l_mtart like mara-mtart.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = material
importing
output = material.
select single mstae mtart
into (l_mstae,l_mtart)
from mara
where matnr eq material .
if l_mstae eq 27 or plant ne '1000'."当物料状态是生产或工厂不是1000时不执行分配参考工艺路线
exit.
endif.
if l_mtart eq 'ZFRT'.
plnnr_001 = '90000008'.
else.
plnnr_001 = '90000007'.
endif.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = material
importing
output = matnr_001.
call function 'ZCA12'
exporting
* CTU = 'X'
* MODE = 'N'
* UPDATE = 'L'
* GROUP = GROUP
* USER = USER
* KEEP = KEEP
* HOLDDATE = HOLDDATE
* NODATA = '/'
plnnr_001 = plnnr_001
* STTAG_002 = '2011.05.18'
* PLNAL_003 = '1'
* ENTRY_ACT_004 = '1'
matnr_01 = matnr_001
* WERKS_01 = '1000'
* ENTRY_ACT_008 = '1'
importing
subrc = l_subrc
* TABLES
* MESSTAB = MESSTAB
.
if l_subrc ne 0.
concatenate return '给物料分配参考工艺路线失败' into return.
else.
concatenate return '给物料分配参考工艺路线成功' into return.
endif.
endfunction.
SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
分享题目:pdm和SAP创建BOM接口-创新互联
地址分享:http://azwzsj.com/article/ddosjg.html