SAP-BAPI物料主数据修改毛重净重
使用BAPI_MATERIAL_SAVEDATA
但是在结构BAPI_MARA和BAPI_MARAX利没有毛重这个字段。所以我们需要在结构BAPI_TE_MARA和BAPI_TE_MARAX中追加毛重这个字段。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0172dc84565a5f76ab418d317ff916d7.png)
点击增加结构(使用类型CHAR)
同理
REPORT ZMM02_MZ.
-
数据声明
DATA: CLIDAINP LIKE BAPI_MARA_GA, "客户端层次物料数据
CLIDAOUT LIKE BAPI_MARA, "客户端层次物料数据
CLIDAOUTX LIKE BAPI_MARAX, "BAPI_MARA 的复选框结构
HEADDATA LIKE BAPIMATHEAD, "带有控制信息的表头段
RETURN LIKE BAPIRET2, "返回参数
RETURNMES LIKE BAPI_MATRETURN2 OCCURS 0 WITH HEADER LINE.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 ZZBAPI_TE_MARA LIKE BAPI_TE_MARA. "客户定义字段:客户级别的物料数据
DATA ZZBAPI_TE_MARAX LIKE BAPI_TE_MARAX. "客户定义字段:客户级别的物料数据 -
取出要处理的物料编号
PARAMETERS: MATERIAL LIKE BAPI_MARA_GA-MATERIAL, "物料
S_BRGEW LIKE BAPI_TE_MARA-BRGEW, "毛重
S_NTGEW LIKE BAPI_MARA-NET_WEIGHT, "净重
S_GEWEI LIKE BAPI_MARA-UNIT_OF_WT. "单位 -
读取物料数据
CALL FUNCTION ‘BAPI_MATERIAL_GET_ALL’
EXPORTING
MATERIAL = MATERIAL
IMPORTING
CLIENTDATA = CLIDAINP
TABLES
RETURN = RETURNMES. -
抬头数据 ,物料和视图维护
HEADDATA-MATERIAL = MATERIAL. "物料号
HEADDATA-BASIC_VIEW = ‘X’.
CLIDAOUT-NET_WEIGHT = S_NTGEW. "净重
CLIDAOUTX-NET_WEIGHT = ‘X’.
CLIDAOUT-UNIT_OF_WT = S_GEWEI. "单位
CLIDAOUTX-UNIT_OF_WT = ‘X’.
ZZBAPI_TE_MARA-MATERIAL = HEADDATA-MATERIAL.
ZZBAPI_TE_MARA-BRGEW = S_BRGEW. "毛重
ZZBAPI_TE_MARAX-MATERIAL = HEADDATA-MATERIAL.
ZZBAPI_TE_MARAX-BRGEW = ‘X’.
-
写入新的自定义字段值
-
CALL METHOD cl_abap_container_utilities=>fill_container_c
-
EXPORTING
-
im_value = ZZBAPI_TE_MARA
-
IMPORTING
-
ex_container = W_EXTENSIONIN+30
-
EXCEPTIONS
-
illegal_parameter_type = 1
-
OTHERS = 2.
W_EXTENSIONIN-STRUCTURE = ‘BAPI_TE_MARA’.
W_EXTENSIONIN+30 = ZZBAPI_TE_MARA.
APPEND W_EXTENSIONIN.
-
CALL METHOD cl_abap_container_utilities=>fill_container_c
-
EXPORTING
-
im_value = ZZBAPI_TE_MARAX
-
IMPORTING
-
ex_container = W_EXTENSIONINX+30
-
EXCEPTIONS
-
illegal_parameter_type = 1
-
OTHERS = 2.
W_EXTENSIONINX-STRUCTURE = ‘BAPI_TE_MARAX’.
W_EXTENSIONINX+30 = ZZBAPI_TE_MARAX.
APPEND W_EXTENSIONINX.
- CallBAPI
CALL FUNCTION ‘BAPI_MATERIAL_SAVEDATA’
EXPORTING
HEADDATA = HEADDATA
CLIENTDATA = CLIDAOUT
CLIENTDATAX = CLIDAOUTX
IMPORTING
RETURN = RETURN
TABLES
RETURNMESSAGES = RETURNMES
EXTENSIONIN = W_EXTENSIONIN
EXTENSIONINX = W_EXTENSIONINX.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
IF RETURN-TYPE = ‘E’.
LOOP AT RETURNMES.
WRITE: / RETURNMES-MESSAGE.
ENDLOOP.
ELSEIF RETURN-TYPE = ‘S’…
WRITE: / '修改成功 ', MATERIAL, ‘OK’.
ENDIF.
代码参考:https://www.xuebuyuan.com/1233687.html