业务背景:需要从OA将物料的毛重,净重,单位这3项更新到SAP物料主数据中。
用到了BAPI_MATERIAL_SAVEDATA这个BAPI来做(前提是该BAPI中要有EXTENSIONIN这个参数),但是在结构BAPI_MARA和BAPI_MARAX利没有毛重这个字段。所以我们需要在结构BAPI_TE_MARA和BAPI_TE_MARAX中追加毛重这个字段。
REPORT Z_WUWEI_0012.* 数据声明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'EXPORTINGMATERIAL = MATERIALIMPORTINGCLIENTDATA = CLIDAINPTABLESRETURN = 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'.W_EXTENSIONIN-STRUCTURE = 'BAPI_TE_MARA'.W_EXTENSIONIN-VALUEPART1 = ZZBAPI_TE_MARA.APPEND W_EXTENSIONIN.W_EXTENSIONINX-STRUCTURE = 'BAPI_TE_MARAX'.W_EXTENSIONINX-VALUEPART1 = ZZBAPI_TE_MARAX.APPEND W_EXTENSIONINX.* CallBAPICALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'EXPORTINGHEADDATA = HEADDATACLIENTDATA = CLIDAOUTCLIENTDATAX= CLIDAOUTXIMPORTINGRETURN = RETURNTABLESRETURNMESSAGES = RETURNMESEXTENSIONIN= W_EXTENSIONINEXTENSIONINX= 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.