如果增强字段在销售订单抬头(vbak)上,则要将增强字段一并append到如下四个表/结构中:
- VBAKKOZ
- VBAKKOZX
- BAPE_VBAK
- BAPE_VBAKX
在行项目(vbap)上:
- VBAPKOZ
- VBAPKOZX
- BAPE_VBAP
- BAPE_VBAPX
在运货计划行(VBEP)上:
- VBEPKOZ
- BEPKOZX
- BAPE_VBEP
- BAPE_VBEPX
下面介绍如何向bapi中extensionin参数赋值数据,具体代码如
* 接口调用日志
DATA: LT_LOG TYPE STANDARD TABLE OF ZZT_INFLOG,
LW_LOG TYPE ZZT_INFLOG. DATA: ORDER_HEADER_INX LIKE BAPISDH1X,
SCHEDULE_LINES LIKE BAPISCHDL OCCURS 0 WITH HEADER LINE,
SCHEDULE_LINESX LIKE BAPISCHDLX OCCURS 0 WITH HEADER LINE,
ORDER_ITEM_IN LIKE BAPISDITM OCCURS 0 WITH HEADER LINE,
ORDER_ITEM_INX LIKE BAPISDITMX OCCURS 0 WITH HEADER LINE,
RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE. DATA: LWA_BAPE_VBAK TYPE BAPE_VBAK,
LWA_BAPE_VBAKX TYPE BAPE_VBAKX, LWA_BAPE_VBAP TYPE BAPE_VBAP,
LWA_BAPE_VBAPX TYPE BAPE_VBAPX, LWA_VALUEPART(240),
LIT_PAREX LIKE TABLE OF BAPIPAREX WITH HEADER LINE. DATA: BEGIN OF IT_TAB OCCURS 0,
VBELN TYPE VBELN,
POSNR TYPE POSNR,
ETENR TYPE ETENR,
LIFSP TYPE LIFSP_EP,
END OF IT_TAB. RANGES: R_VBELN FOR VBAP-VBELN,
R_POSNR FOR VBAP-POSNR. IF SALESDOCUMENT IS INITIAL.
E_STATU = 'E'.
E_MESS = '单号为空!'.
EXIT.
ENDIF. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = SALESDOCUMENT
IMPORTING
OUTPUT = SALESDOCUMENT. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = SALESPOSNR
IMPORTING
OUTPUT = SALESPOSNR. IF SALESDOCUMENT IS NOT INITIAL.
R_VBELN-SIGN = 'I'.
R_VBELN-OPTION = 'EQ'.
R_VBELN-LOW = SALESDOCUMENT.
APPEND R_VBELN.
ENDIF.
IF SALESPOSNR IS NOT INITIAL.
R_POSNR-SIGN = 'I'.
R_POSNR-OPTION = 'EQ'.
R_POSNR-LOW = SALESPOSNR.
APPEND R_POSNR.
ENDIF. ***获得计划行号
SELECT VBELN POSNR ETENR LIFSP
INTO TABLE IT_TAB
FROM VBEP
WHERE VBELN IN R_VBELN
AND POSNR IN R_POSNR
AND ETENR = '0001'. IF IT_TAB[] IS INITIAL.
E_STATU = 'E'.
E_MESS = '订单项的计划行数据不存在!'.
EXIT.
ENDIF. ORDER_HEADER_INX-UPDATEFLAG = 'U'. LOOP AT IT_TAB.
SCHEDULE_LINES-ITM_NUMBER = IT_TAB-POSNR.
SCHEDULE_LINES-SCHED_LINE = IT_TAB-ETENR.
SCHEDULE_LINES-REQ_DLV_BL = REQ_DLV_BL. " Q1/Q2
IF REQ_DATE IS NOT INITIAL.
SCHEDULE_LINES-REQ_DATE = REQ_DATE . "原始需求日期
ENDIF.
APPEND SCHEDULE_LINES. SCHEDULE_LINESX-UPDATEFLAG = 'U'.
SCHEDULE_LINESX-ITM_NUMBER = IT_TAB-POSNR.
SCHEDULE_LINESX-SCHED_LINE = IT_TAB-ETENR.
SCHEDULE_LINESX-REQ_DLV_BL = 'X'.
IF REQ_DATE IS NOT INITIAL.
SCHEDULE_LINESX-REQ_DATE = 'X'.
ENDIF.
APPEND SCHEDULE_LINESX. *&-->增强字段
IF FDATU IS NOT INITIAL OR IM_BHDAT IS NOT INITIAL OR IM_BHTIM IS NOT INITIAL. CLEAR: LWA_BAPE_VBAP,LIT_PAREX.
LWA_BAPE_VBAP-VBELN = IT_TAB-VBELN.
LWA_BAPE_VBAP-POSNR = IT_TAB-POSNR.
IF FDATU IS NOT INITIAL.
LWA_BAPE_VBAP-FDATU = FDATU .
ENDIF.
IF IM_BHDAT IS NOT INITIAL.
LWA_BAPE_VBAP-Q1Q2DAT = IM_BHDAT .
ENDIF.
IF IM_BHTIM IS NOT INITIAL.
LWA_BAPE_VBAP-Q1Q2TIM = IM_BHTIM .
ENDIF. LIT_PAREX-STRUCTURE = 'BAPE_VBAP'.
LIT_PAREX+30 = LWA_BAPE_VBAP.
APPEND LIT_PAREX. CLEAR: LWA_BAPE_VBAPX,LIT_PAREX.
LWA_BAPE_VBAPX-VBELN = IT_TAB-VBELN.
LWA_BAPE_VBAPX-POSNR = IT_TAB-POSNR.
IF FDATU IS NOT INITIAL.
LWA_BAPE_VBAPX-FDATU = 'X' .
ENDIF.
IF IM_BHDAT IS NOT INITIAL.
LWA_BAPE_VBAPX-Q1Q2DAT = 'X' .
ENDIF.
IF IM_BHTIM IS NOT INITIAL.
LWA_BAPE_VBAPX-Q1Q2TIM = 'X' .
ENDIF. LIT_PAREX-STRUCTURE = 'BAPE_VBAPX'.
LIT_PAREX+30 = LWA_BAPE_VBAPX.
APPEND LIT_PAREX. ENDIF. *&-->日志
CLEAR: LW_LOG.
LW_LOG-INTTY = 'A1'.
LW_LOG-DIRECT = '2'.
LW_LOG-INFTX = '订单计划行标记,以及备货日期更新'.
LW_LOG-CAFUN = 'ZRFC_SO_CHANGE'. "调用函数
LW_LOG-IKEY1 = REQ_DLV_BL.
LW_LOG-IKEY2 = REQ_DATE.
LW_LOG-IKEY3 = IM_BHDAT.
LW_LOG-IKEY3 = FDATU.
CONCATENATE ZAUTL IM_ZXQBL INTO LW_LOG-LOGTX.
APPEND LW_LOG TO LT_LOG. *&-->行项目
CLEAR: ORDER_ITEM_IN,ORDER_ITEM_INX.
ORDER_ITEM_IN-ITM_NUMBER = IT_TAB-POSNR.
APPEND ORDER_ITEM_IN.
ORDER_ITEM_INX-ITM_NUMBER = IT_TAB-POSNR.
ORDER_ITEM_INX-UPDATEFLAG = 'U'.
APPEND ORDER_ITEM_INX. ENDLOOP. *&-->增强字段 抬头数据
IF ZAUTL IS NOT INITIAL OR IM_ZXQBL IS NOT INITIAL.
CLEAR:LWA_BAPE_VBAK,LWA_BAPE_VBAKX,LWA_VALUEPART.
LWA_BAPE_VBAK-VBELN = SALESDOCUMENT. IF ZAUTL IS NOT INITIAL.
LWA_BAPE_VBAK-ZAUTL = ZAUTL. "分批标记
ENDIF.
IF IM_ZXQBL IS NOT INITIAL.
LWA_BAPE_VBAK-ZXQBL = IM_ZXQBL. "保持原始需求标记
ENDIF.
* lwa_valuepart = lwa_bape_vbak.
LIT_PAREX-STRUCTURE = 'BAPE_VBAK'.
LIT_PAREX+30 = LWA_BAPE_VBAK.
APPEND LIT_PAREX. CLEAR:LWA_BAPE_VBAK,LWA_VALUEPART.
LWA_BAPE_VBAKX
-VBELN = SALESDOCUMENT. IF ZAUTL IS NOT INITIAL.
LWA_BAPE_VBAKX
-ZAUTL = 'X'. "分批标记
ENDIF.
IF IM_ZXQBL IS NOT INITIAL.
LWA_BAPE_VBAKX
-ZXQBL = 'X'. "保持原始需求标记
ENDIF.
* lwa_valuepart = lwa_bape_vbakx.
LIT_PAREX
-STRUCTURE = 'BAPE_VBAKX'.
LIT_PAREX+30
= LWA_BAPE_VBAKX.
APPEND LIT_PAREX. CLEAR:LWA_BAPE_VBAKX,LWA_VALUEPART. ENDIF. CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
SALESDOCUMENT
= SALESDOCUMENT
ORDER_HEADER_INX
= ORDER_HEADER_INX
TABLES
RETURN = RETURN
ORDER_ITEM_IN
= ORDER_ITEM_IN
ORDER_ITEM_INX
= ORDER_ITEM_INX
SCHEDULE_LINES
= SCHEDULE_LINES
SCHEDULE_LINESX
= SCHEDULE_LINESX
EXTENSIONIN
= LIT_PAREX[]. READ TABLE RETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'. E_STATU = 'S'.
E_MESS
= '更新成功!'. "保存日期
IF LT_LOG[] IS NOT INITIAL.
CALL FUNCTION 'ZF_SAVE_LOG'
TABLES
IT_LOG
= LT_LOG.
IF SY-SUBRC EQ 0.
COMMIT WORK.
ENDIF.
ENDIF. ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
E_STATU
= 'E'.
E_MESS
= RETURN-MESSAGE.
CLEAR: LT_LOG[].
ENDIF. CLEAR: SALESDOCUMENT,
ORDER_HEADER_INX
,
RETURN[]
,
SCHEDULE_LINES[]
,
SCHEDULE_LINESX[]
. ENDFUNCTION.