1、BAPI_MATERIAL_SAVEDATA 修改物料信息
参考:https://blog.csdn.net/zhongguomao/article/details/51917696
clientdata-matl_group = ls_in-matkl."物料组
clientdata-base_uom = ls_in-meins."基本计量单位
clientdata-extmatlgrp = ls_in-extwg."外部物料组
clientdata-item_cat = ls_in-mtpos_mara."普通项目类别组
clientdata-net_weight = ls_in-ntgew."净重
clientdata-unit_of_wt = ls_in-gewei."重量单位
clientdata-size_dim = ls_in-groes."产品费用率(大小/量纲)
clientdata-old_mat_no = ls_in-bismt."旧物料号
clientdata-division = ls_in-spart."产品组
clientdata-po_unit = ls_in-bstme."订单单位
clientdata-var_ord_un = ls_in-vabme."可变采购订单单位活动
clientdata-batch_mgmt = ls_in-xchpf."批次管理
clientdata-period_ind_expiration_date = ls_in-iprkz."货架寿命到期日的期间标识
clientdata-allowed_wt = ls_in-brgew."毛重
clientdata-trans_grp = ls_in-tragr."运输组
clientdata-allwd_vol = ls_in-volum."体积
clientdata-pack_vo_un = ls_in-voleh."体积单位
clientdata-pur_status = ls_in-mstae."
clientdata-minremlife = ls_in-mhdrz."最短剩余货架寿命
clientdata-shelf_life = ls_in-mhdhb."总货架寿命
CLEAR clientdatax.
clientdatax-matl_group = 'X'."物料组
clientdatax-base_uom = 'X'."基本计量单位
clientdatax-extmatlgrp = 'X'."外部物料组
clientdatax-item_cat = 'X'."普通项目类别组
clientdatax-net_weight = 'X'."净重
clientdatax-unit_of_wt = 'X'."重量单位
clientdatax-allowed_wt = 'X'."毛重
clientdatax-trans_grp = 'X'."运输组
clientdatax-size_dim = 'X'."产品费用率(大小/量纲)
clientdatax-old_mat_no = 'X'."旧物料号
clientdatax-division = 'X'."产品组
clientdatax-po_unit = 'X'."订单单位
clientdatax-allwd_vol = 'X'."体积
clientdatax-pack_vo_un = 'X'."体积单位
clientdatax-pur_status = 'X'."
clientdatax-var_ord_un = 'X'."可变采购订单单位活动
clientdatax-batch_mgmt = 'X'."批次管理
clientdatax-minremlife = 'X'."最短剩余货架寿命*
clientdatax-shelf_life = 'X'."总货架寿命
clientdatax-period_ind_expiration_date = 'X'."货架寿命到期日的期间标识
"物料描述
CLEAR:materialdescription,materialdescription[].
materialdescription-langu_iso = 'ZH'.
materialdescription-matl_desc = ls_in-maktx.
APPEND materialdescription.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = headdata
clientdata = clientdata
clientdatax = clientdatax
IMPORTING
return = return
TABLES
materialdescription = materialdescription[].
这样写满足创建物料的基本视图和其中的字段,但是有一个问题,虽然写了毛重,但是实际传入的毛重没有生效。
2、毛重的字段增强
概述:对结构BAPI_TE_MARA和BAPI_TE_MARAX进行字段增强。
参考:ABAP增强开发:更新物料主数据毛重,净重,单位的BAPI使用方法(经典)_bapi_material_savedata增强字段写入-CSDN博客SAP-BAPI物料主数据修改毛重净重_料号毛重参数设置-CSDN博客
操作步骤:
(1)SE11 输入 BAPI_TE_MARA
(2)点击附加结构
(3)填写附加结构名称:一般以Z打头,加原结构名称,例如:ZBAPI_TE_MARA
(4)填写描述,可以和原结构描述相同,也可以自由填写。
填写组件,选择内置类型,CHAR,20,描述写毛重。
注意:数据类型比如是CHAR,如果使用,MARA-BRGEW,这个类型是QUAN,在后面BAPI扩展赋值时,会报错。
扩展类型里面都是CHAR,为了确保传输数据类型一致,定义组件的数据类型必须是CHAR.
(5)保存、激活后,返回BAPI_TE_MARA,展示如下图
(6)同理,对BAPI_TE_MARAX进行扩展组件,扩展后如下:
这里注意一下ZBAPI_TE_MARAX中的BRGEW的组件类型为 BAPIUPDATE
3、程序修改,加入扩展字段
DATA: BEGIN OF w_extensionin OCCURS 0.
INCLUDE STRUCTURE bapiparex. "BAPI 参数 ExtensionIn/ExtensionOut 的参考结构
DATA: END OF w_extensionin.
DATA: BEGIN OF w_extensioninx OCCURS 0.
INCLUDE STRUCTURE bapiparexx. "Extension In/Extension Out 的复选框结构
DATA: END OF w_extensioninx.
DATA: zbapi_te_mara LIKE bapi_te_mara. "客户定义字段:客户级别的物料数据
DATA: zbapi_te_marax LIKE bapi_te_marax. "客户定义字段:客户级别的物料数据
clientdata-matl_group = ls_in-matkl."物料组
clientdata-base_uom = ls_in-meins."基本计量单位
clientdata-extmatlgrp = ls_in-extwg."外部物料组
clientdata-item_cat = ls_in-mtpos_mara."普通项目类别组
clientdata-net_weight = ls_in-ntgew."净重
clientdata-unit_of_wt = ls_in-gewei."重量单位
clientdata-size_dim = ls_in-groes."产品费用率(大小/量纲)
clientdata-old_mat_no = ls_in-bismt."旧物料号
clientdata-division = ls_in-spart."产品组
clientdata-po_unit = ls_in-bstme."订单单位
clientdata-var_ord_un = ls_in-vabme."可变采购订单单位活动
clientdata-batch_mgmt = ls_in-xchpf."批次管理
clientdata-period_ind_expiration_date = ls_in-iprkz."货架寿命到期日的期间标识
clientdata-allowed_wt = ls_in-brgew."毛重
clientdata-trans_grp = ls_in-tragr."运输组
clientdata-allwd_vol = ls_in-volum."体积
clientdata-pack_vo_un = ls_in-voleh."体积单位
clientdata-pur_status = ls_in-mstae."
clientdata-minremlife = ls_in-mhdrz."最短剩余货架寿命
clientdata-shelf_life = ls_in-mhdhb."总货架寿命
CLEAR clientdatax.
clientdatax-matl_group = 'X'."物料组
clientdatax-base_uom = 'X'."基本计量单位
clientdatax-extmatlgrp = 'X'."外部物料组
clientdatax-item_cat = 'X'."普通项目类别组
clientdatax-net_weight = 'X'."净重
clientdatax-unit_of_wt = 'X'."重量单位
clientdatax-allowed_wt = 'X'."毛重
clientdatax-trans_grp = 'X'."运输组
clientdatax-size_dim = 'X'."产品费用率(大小/量纲)
clientdatax-old_mat_no = 'X'."旧物料号
clientdatax-division = 'X'."产品组
clientdatax-po_unit = 'X'."订单单位
clientdatax-allwd_vol = 'X'."体积
clientdatax-pack_vo_un = 'X'."体积单位
clientdatax-pur_status = 'X'."
clientdatax-var_ord_un = 'X'."可变采购订单单位活动
clientdatax-batch_mgmt = 'X'."批次管理
clientdatax-minremlife = 'X'."最短剩余货架寿命*
clientdatax-shelf_life = 'X'."总货架寿命
clientdatax-period_ind_expiration_date = 'X'."货架寿命到期日的期间标识
"物料描述
CLEAR:materialdescription,materialdescription[].
materialdescription-langu_iso = 'ZH'.
materialdescription-matl_desc = ls_in-maktx.
APPEND materialdescription.
"扩展字段
zbapi_te_mara-material = ls_in-matnr.
zbapi_te_mara-brgew = ls_in-brgew. "毛重
zbapi_te_marax-material = ls_in-matnr.
zbapi_te_marax-brgew = 'X'.
w_extensionin-structure = 'BAPI_TE_MARA'.
w_extensionin-valuepart1 = zbapi_te_mara.
APPEND w_extensionin.
w_extensioninx-structure = 'BAPI_TE_MARAX'.
w_extensioninx-valuepart1 = zbapi_te_marax.
APPEND w_extensioninx.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = headdata
clientdata = clientdata
clientdatax = clientdatax
IMPORTING
return = return
TABLES
materialdescription = materialdescription[]
extensionin = w_extensionin
extensioninx = w_extensioninx.
4、总结
在直接使用BAPI_MATERIAL_SAVEDATA 创建、修改物料信息时,毛重字段不生效。此时需要进行增强开发,先对字段进行扩展,再在程序中增加扩展字段的赋值。