通过屏幕增强,我在MM01中增强两个字段
image.png
- 数据定义
* BAPI数据声明
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:LT_EXTENSION TYPE STANDARD TABLE OF BAPIPAREX , "参考结构
LS_EXTENSION TYPE BAPIPAREX,
LT_EXTENSIONX TYPE STANDARD TABLE OF BAPIPAREXX , "参考结构
LS_EXTENSIONX TYPE BAPIPAREXX.
DATA:WA_ZEXTEN LIKE BAPI_TE_MARA,
WA_ZEXTENX LIKE BAPI_TE_MARAX.
- 读取物料数据
CALL FUNCTION 'BAPI_MATERIAL_GET_ALL'
EXPORTING
MATERIAL = GS_TAB-MATNR
IMPORTING
CLIENTDATA = CLIDAINP
TABLES
RETURN = RETURNMES.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
BAPI_MATERIAL_GET_ALL 这个FUNCTION可以取出该物料下的基础数据
- 抬头数据 ,物料和视图维护
HEADDATA-MATERIAL = GS_TAB-MATNR.
HEADDATA-BASIC_VIEW = 'X'.
WA_ZEXTEN-MATERIAL = GS_TAB-MATNR.
"物料是必须要给的,不然报S类型的消息,但是不更新MARA表
WA_ZEXTEN-ZJPAUDIT = GS_TAB-JPAUDIT.
"要更新的字段
LS_EXTENSION-STRUCTURE = 'BAPI_TE_MARA'.
"扩展结构是系统标准的(敲重点)
LS_EXTENSION-VALUEPART1 = WA_ZEXTEN.
APPEND LS_EXTENSION TO LT_EXTENSION.
CLEAR LS_EXTENSION.
*给更新字段打上啊X标识
WA_ZEXTENX-MATERIAL = GS_TAB-MATNR.
WA_ZEXTENX-ZJPAUDIT = 'X'.
LS_EXTENSIONX-STRUCTURE = 'BAPI_TE_MARAX'.
LS_EXTENSIONX-VALUEPART1 = WA_ZEXTENX.
APPEND LS_EXTENSIONX TO LT_EXTENSIONX.
CLEAR LS_EXTENSIONX.
附加结构参考
image.png image.png
自己往标准结构,表里面插入数据,一般通过附加结构,新建一个结构插入,插入的结构不可以提前建好引用,我的理解是你通过点击结构的附加结构按钮,建立的会出现某种勾稽关系吧。
- CallBAPI
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
HEADDATA = HEADDATA
CLIENTDATA = CLIDAOUT
CLIENTDATAX = CLIDAOUTX
IMPORTING
RETURN = RETURN
TABLES
RETURNMESSAGES = RETURNMES
EXTENSIONIN = LT_EXTENSION "敲重点
EXTENSIONINX = LT_EXTENSIONX."敲重点
IF RETURN-TYPE = 'E'.
GS_TAB-TYPE = 'E'.
GS_TAB-MESS = RETURN-MESSAGE.
ROLLBACK WORK.
ELSE.
GS_TAB-MESS = TEXT-011.
GS_TAB-TYPE = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
MODIFY GT_TAB FROM GS_TAB.
CLEAR GS_TAB.
MESSAGE TEXT-011 TYPE 'S'.
ELSE.
GS_TAB-TYPE = 'E'.
GS_TAB-MESS = TEXT-012 .
MODIFY GT_TAB FROM GS_TAB.
CLEAR GS_TAB.
ENDIF.
先确定自己的前台可以跑通,在测试bapi
网友评论