物料主数据业务视图扩充
BAPI:BAPI_MATERIAL_SAVEDATA
FORM frm_view_ex
USING
uv_beskz TYPE beskz
ut_xchpf TYPE typ_t_xchpf
us_werks TYPE werks_d
us_matnr TYPE matnr.
DATA:
ls_plantdata TYPE bapi_marc,
ls_plantdatax TYPE bapi_marcx,
ls_zexten LIKE bapi_te_marc,
ls_zextenx LIKE bapi_te_marcx,
lt_extensionin TYPE TABLE OF bapiparex,
ls_extensionin TYPE bapiparex,
lt_extensioninx TYPE TABLE OF bapiparexx,
ls_extensioninx TYPE bapiparexx,
ls_return TYPE bapiret2, "用来判断返回情况
ls_header TYPE bapimathead. "带有控制信息的表头段,也就是各视图
* 采购视图
ls_header-purchase_view = 'X'.
* 存储视图
ls_header-storage_view = 'X'.
* 基本视图
ls_header-material = us_matnr. "物料编码
ls_plantdata-plant = us_werks. "工厂
ls_plantdatax-plant = us_werks. "工厂
ls_plantdata-pur_status = 'Z0'. "工厂特定的物料状态
ls_plantdatax-pur_status = 'X '. "工厂特定的物料状态
ls_plantdata-pvalidfrom = sy-datum. "工厂特定物料状态有效的起始日期
ls_plantdatax-pvalidfrom = 'X '.
READ TABLE ut_xchpf TRANSPORTING NO FIELDS
WITH KEY matnr = us_matnr
xchpf = 'X'.
IF sy-subrc = 0.
ls_plantdata-batch_mgmt = 'X'. "批次管理需求的标识
ls_plantdatax-batch_mgmt = 'X '.
ENDIF.
* 基本数据视图2
ls_zexten-plant = us_werks. "需要修改的物料编码
ls_zexten-zzbeskz = uv_beskz. "采购类型
* LS_ZEXTEN-ZZSOBSL = US_ZTMDG000D-SOBSL. "特殊采购类型
ls_extensionin-structure = 'BAPI_TE_MARC'.
ls_extensionin-valuepart1 = ls_zexten.
APPEND ls_extensionin TO lt_extensionin.
CLEAR ls_extensionin.
ls_extensionin-valuepart1 = ls_zexten.
ls_zextenx-plant = us_werks. "需要修改的物料编码
ls_zextenx-zzbeskz = 'X' . "采购类型
* LS_ZEXTENX-ZZSOBSL = 'X' . "特殊采购类型
ls_extensioninx-structure = 'BAPI_TE_MARCX'.
ls_extensioninx-valuepart1 = ls_zextenx.
APPEND ls_extensioninx TO lt_extensioninx.
CLEAR ls_extensioninx.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = ls_header
plantdata = ls_plantdata
plantdatax = ls_plantdatax
IMPORTING
return = ls_return
TABLES
extensionin = lt_extensionin
extensioninx = lt_extensioninx.
IF ls_return-type = 'E' OR ls_return-type = 'A'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
sy-subrc = 4.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
CLEAR:
ls_return,
ls_header,
ls_plantdata ,
ls_plantdatax .
ENDFORM.