物料主数据集成在很多项目是比较常见的需求,在做系统实现之前我们需要明确涉及的业务流程和需求范围,并且对每个系统的业务边界进行明确:
如果是从SAP ERP 向其他系统推送数据,并且实时性要求高的情况下,我一般倾向于在增强出口里实时抓取系统新增,或修改,或删除的数据给外围系统。这里以物料主数据的BTE增强,增强事件00001250为例:
第一步:事务代码FIBF
第二步:点设置->产品->客户
第三步,配置事件、产品和函数的对应关系。点击设置->发布/订阅模块->客户的
ZSAMPLE_INTERFACE_00001250,需要先复制标准函数SAMPLE_INTERFACE_00001250
代码示例:
赋值
"生成唯一标识
* W_INPUT-GUID = CL_SYSTEM_UUID=>IF_SYSTEM_UUID_STATIC~CREATE_UUID_C22( ).
TRY .
CALL METHOD CL_SYSTEM_UUID=>IF_SYSTEM_UUID_STATIC~CREATE_UUID_C22
RECEIVING UUID = w_input-guid.
CATCH cx_uuid_error.
"获取失败ID,根据YYMMDDHHMMSS+序号拼接
w_input-guid = |{ sy-datum }{ sy-uzeit }{ 00001 }|.
ENDTRY.
READ TABLE t_makt_new INTO DATA(w_makt) WITH KEY spras = '1' .
IF i_marc_new-werks = '8100'."新扩充8100视图数据
w_input-matnr = i_mara_new-matnr."物料代码
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
input = w_input-MATNR
IMPORTING
output = w_input-MATNR.
w_input-zwlms = i_mara_new-zwlms."物料长描述
w_input-matkl = i_mara_new-matkl."物料组
w_input-mtart = i_mara_new-mtart."物料分类
w_input-meins = i_mara_new-meins."基本计量单位
w_input-werks = i_marc_new-werks."工厂代码
w_input-dispo = i_marc_new-dispo."MRP控制者
w_input-maabc = i_marc_new-maabc."ABC标识
w_input-fevor = i_marc_new-fevor."生成管理员
w_input-sobsl = i_marc_new-sobsl."特殊采购类型-虚拟物料标识
w_input-sbdkz = i_marc_new-SBDKZ."独立集中标识
w_input-eisbe = i_marc_new-eisbe."安全库存标识
w_input-plifz = i_marc_new-plifz."采购周期
w_input-beskz = i_marc_new-beskz."采购类型 " BESKZ--- ADD BY HX_FHJ 20210106
w_input-maktx = w_makt-maktx.
IF upd_marc IS INITIAL.
w_input-action = upd_mara.
ELSE.
w_input-action = upd_marc.
ENDIF.
w_input-ERSDA = sy-DATUM.
w_input-ERTIM = sy-UZEIT.
w_input-ERNAM = sy-UNAME.
IF w_input-maktx IS INITIAL.
SELECT SINGLE maktx
INTO @w_input-maktx
FROM makt
WHERE matnr = @i_mara_new-matnr
AND spras = '1'.
ENDIF.
APPEND w_input TO input.
CLEAR w_input.
ELSEIF ( upd_mara = 'U' AND i_marc_new-werks IS INITIAL ) OR w_makt-kz = 'U'."基本视图修改,需要判断是否存在工厂视图
SELECT SINGLE werks,dispo,maabc,fevor,sobsl,maktx,sbdkz,eisbe,plifz,beskz " BESKZ--- ADD BY HX_FHJ 20210106
INTO @DATA(lw_marc)
FROM marc INNER JOIN makt on marc~matnr = makt~matnr
WHERE marc~matnr = @i_mara_new-matnr
AND werks = '8100'
AND spras = '1'.
IF SY-SUBRC = 0.
w_input-matnr = i_mara_new-matnr."物料代码
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
input = w_input-MATNR
IMPORTING
output = w_input-MATNR.
w_input-mtart = i_mara_new-mtart."物料分类
w_input-zwlms = i_mara_new-zwlms."物料长描述
w_input-matkl = i_mara_new-matkl."物料组
w_input-meins = i_mara_new-meins."基本计量单位
w_input-werks = lw_marc-werks."工厂代码
w_input-dispo = lw_marc-dispo."MRP控制者
w_input-maabc = lw_marc-maabc."ABC标识
w_input-fevor = lw_marc-fevor."生成管理员
w_input-sobsl = lw_marc-sobsl."特殊采购类型-虚拟物料标识
w_input-sbdkz = lw_marc-sbdkz."独立集中标识
w_input-eisbe = lw_marc-eisbe."安全库存标识
w_input-plifz = lw_marc-plifz."采购周期
w_input-beskz = lw_marc-beskz."采购类型 " BESKZ--- ADD BY HX_FHJ 20210106
IF w_makt-maktx IS NOT INITIAL.
w_input-maktx = w_makt-maktx.
ELSE.
w_input-maktx = lw_marc-maktx.
ENDIF.
IF upd_marc IS INITIAL.
w_input-action = 'U'.
ELSEIF upd_mara IS NOT INITIAL.
w_input-action = upd_marc.
ENDIF.
w_input-ERSDA = sy-DATUM.
w_input-ERTIM = sy-UZEIT.
w_input-ERNAM = sy-UNAME.
APPEND w_input TO input.
CLEAR w_input.
ENDIF.
ENDIF.
CLEAR w_makt.
"调用APS接口,推送物料主数据
IF INPUT IS NOT INITIAL.
CALL FUNCTION 'ZDD_APS_001'
STARTING NEW TASK 'APS001' "防止接口连接时长影响SAP操作,采用这种方式调用接口
EXPORTING
INPUT = INPUT
* ARQ =
.
ENDIF.
BTE的资料大家网上可以搜一下,这里推荐一篇:BTEs – Business Transaction Events