在BAPI_CONTRACT_CREATEFROMDATA中使用扩展结构EXTENSIONIN
需要将字段加到4个结构中去,
DATA:LV_SALEDOC TYPE BAPIVBELN-VBELN,
LV_ITEMNO TYPE POSNR_VA,
LS_HEADER_IN TYPE BAPISDHD1,
LS_HEADER_INX TYPE BAPISDHD1X,
LS_ITEMS_IN TYPE BAPISDITM,
LT_ITEMS_IN TYPE STANDARD TABLE OF BAPISDITM,
LS_ITEMS_INX TYPE BAPISDITMX,
LT_ITEMS_INX TYPE STANDARD TABLE OF BAPISDITMX,
LS_PARNR TYPE BAPIPARNR,
LT_PARNR TYPE STANDARD TABLE OF BAPIPARNR,
LS_COND TYPE BAPICOND,
LT_COND TYPE STANDARD TABLE OF BAPICOND,
LS_CONDX TYPE BAPICONDX,
LT_CONDX TYPE STANDARD TABLE OF BAPICONDX,
LS_RETURN TYPE BAPIRET2,
LT_RETURN TYPE STANDARD TABLE OF BAPIRET2,
LS_BAPE_VBAP TYPE BAPE_VBAP,
LS_BAPE_VBAK TYPE BAPE_VBAK,
LS_BAPE_VBAPX TYPE BAPE_VBAPX,
LS_BAPE_VBAKX TYPE BAPE_VBAKX,
LS_EXTEN TYPE BAPIPAREX,
LT_EXTEN TYPE STANDARD TABLE OF BAPIPAREX,
LS_EXTENX TYPE BAPIPAREX,
LT_EXTENX TYPE STANDARD TABLE OF BAPIPAREX,
LT_MSG TYPE SCP1_GENERAL_ERRORS,
LS_MSG TYPE SCP1_GENERAL_ERROR,
LT_ZSD0013T TYPE STANDARD TABLE OF ZSD0013T,
LT_ZSD0013T_C TYPE STANDARD TABLE OF ZSD0013T,
LS_ZSD0013T TYPE ZSD0013T.
"DELETE GT_CON INDEX 2.
IF GT_CON IS NOT INITIAL.
SELECT *
FROM ZSD0013T
FOR ALL ENTRIES IN @GT_CON
WHERE BSTKD = @GT_CON-BSTKD
INTO TABLE @LT_ZSD0013T.
SORT GT_CON BY BSTKD POSEX.
LOOP AT GT_CON INTO GS_CON.
ADD 10 TO LV_ITEMNO.
* 关联CRM行项目 与 BAPI产色的行项目
LOOP AT LT_ZSD0013T INTO LS_ZSD0013T WHERE BSTKD = GS_CON-BSTKD
AND POSEX = GS_CON-POSEX.
LS_ZSD0013T-POSNR = LV_ITEMNO.
MODIFY LT_ZSD0013T FROM LS_ZSD0013T.
CLEAR:LS_ZSD0013T.
ENDLOOP.
* ITEM
LS_ITEMS_IN-ITM_NUMBER = LV_ITEMNO. "序号 增量10
LS_ITEMS_IN-PO_ITM_NO = GS_CON-POSEX ."CRM行项目序号
LS_ITEMS_IN-MATERIAL = GS_CON-MATNR ."物料编码
LS_ITEMS_IN-CUST_MAT35 = GS_CON-KDMAT ."客户物料描述
LS_ITEMS_IN-TARGET_QTY = GS_CON-ZMENG ."数量
LS_ITEMS_IN-PLANT = GS_CON-WERKS ."工厂
LS_ITEMS_IN-WBS_ELEM = GS_CON-POSID ."WBS
LS_ITEMS_IN-SHIP_POINT = GS_CON-WERKS ."装运点
APPEND LS_ITEMS_IN TO LT_ITEMS_IN.
* ITEMX
LS_ITEMS_INX-ITM_NUMBER = LV_ITEMNO. "序号 增量10
LS_ITEMS_INX-PO_ITM_NO = 'X' ."CRM行项目序号
LS_ITEMS_INX-MATERIAL = 'X' ."物料编码
LS_ITEMS_INX-CUST_MAT35 = 'X' ."客户物料描述
LS_ITEMS_INX-TARGET_QTY = 'X' ."数量
LS_ITEMS_INX-PLANT = 'X' ."工厂
LS_ITEMS_INX-WBS_ELEM = 'X' ."WBS
LS_ITEMS_INX-SHIP_POINT = 'X' ."装运点
APPEND LS_ITEMS_IN TO LT_ITEMS_IN.
* VALUE
LS_COND-ITM_NUMBER = LV_ITEMNO.
LS_COND-COND_VALUE = GS_CON-ZDJ. "单价
LS_COND-COND_TYPE = GS_CON-PSTYV. "条件类型
APPEND LS_COND TO LT_COND.
* VALUEX
LS_CONDX-ITM_NUMBER = LV_ITEMNO.
LS_CONDX-COND_VALUE = 'X'. "单价
LS_CONDX-COND_TYPE = 'X'. "条件类型
APPEND LS_CONDX TO LT_CONDX.
* EXTENSIONIN VBAP
LS_BAPE_VBAP-POSNR = LV_ITEMNO.
LS_BAPE_VBAP-ZYYHY = GS_CON-ZYYHY. "产品应用行业
LS_BAPE_VBAP-ZYJKHJE = GS_CON-ZYJKHJE."业绩考核金额
LS_EXTEN-STRUCTURE = 'BAPE_VBAP'.
LS_EXTEN+30(960) = LS_BAPE_VBAP.
APPEND LS_EXTEN TO LT_EXTEN.
CLEAR:LS_EXTEN.
AT END OF BSTKD.
READ TABLE GT_CON INTO GS_CON INDEX SY-TABIX.
IF SY-SUBRC = 0.
* PARNR
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GS_CON-KUNNR
IMPORTING
OUTPUT = GS_CON-KUNNR.
LS_PARNR-PARTN_ROLE = 'AG'.
LS_PARNR-PARTN_NUMB = GS_CON-KUNNR. "客户编码
APPEND LS_PARNR TO LT_PARNR.
* HEAD
LS_HEADER_IN-DOC_TYPE = GS_CON-AUART. "ERP合同类型
LS_HEADER_IN-PURCH_NO_C = GS_CON-BSTKD. "CRM合同号
LS_HEADER_IN-PP_SEARCH = GS_CON-KTEXT. "合同描述
LS_HEADER_IN-SALES_ORG = GS_CON-VKORG. "销售组织
LS_HEADER_IN-DISTR_CHAN = GS_CON-VTWEG ."分销渠道
LS_HEADER_IN-SALES_OFF = GS_CON-VKBUR. "销售部门
LS_HEADER_IN-SALES_GRP = GS_CON-VKGRP. "销售组
LS_HEADER_IN-CURRENCY = GS_CON-WAERK ."货币码
LS_HEADER_IN-CT_VALID_F = GS_CON-GUEBG. "有效期从
LS_HEADER_IN-CT_VALID_T = GS_CON-GUEEN. "有效期到
* HEADX
LS_HEADER_INX-DOC_TYPE = 'X'. "ERP合同类型
LS_HEADER_INX-PURCH_NO_C = 'X'. "CRM合同号
LS_HEADER_INX-PP_SEARCH = 'X'. "合同描述
LS_HEADER_INX-SALES_ORG = 'X'. "销售组织
LS_HEADER_INX-DISTR_CHAN = 'X' ."分销渠道
LS_HEADER_INX-SALES_OFF = 'X'. "销售部门
LS_HEADER_INX-SALES_GRP = 'X'. "销售组
LS_HEADER_INX-CURRENCY = 'X' ."货币码
LS_HEADER_INX-CT_VALID_F = 'X'. "有效期从
LS_HEADER_INX-CT_VALID_T = 'X'. "有效期到
* EXTENSIONIN VBAK
LS_BAPE_VBAK-ZCRMLX = GS_CON-ZCRMLX. "CRM合同类型
LS_BAPE_VBAK-ZHY = GS_CON-ZHY. "行业
LS_BAPE_VBAK-ZHTZT = GS_CON-ZHTZT. "合同状态
LS_BAPE_VBAK-ZYWY = GS_CON-ZYWY. "业务负责人
LS_BAPE_VBAK-ZQYR = GS_CON-ZQYR. "签约人
LS_BAPE_VBAK-ZHKFZR = GS_CON-ZHKFZR. "回款负责人
LS_BAPE_VBAK-ZQYRQ = GS_CON-ZQYRQ. "签约日期
LS_BAPE_VBAK-ZYJQRRQ = GS_CON-ZYJQRRQ. "业绩确认日期
LS_EXTEN-STRUCTURE = 'BAPE_VBAK'.
LS_EXTEN+30(960) = LS_BAPE_VBAK.
APPEND LS_EXTEN TO LT_EXTEN.
CLEAR:LS_EXTEN.
* EXTENSIONIN VBAKX
LS_BAPE_VBAKX-ZCRMLX = 'X'. "CRM合同类型
LS_BAPE_VBAKX-ZHY = 'X'. "行业
LS_BAPE_VBAKX-ZHTZT = 'X'. "合同状态
LS_BAPE_VBAKX-ZYWY = 'X'. "业务负责人
LS_BAPE_VBAKX-ZQYR = 'X'. "签约人
LS_BAPE_VBAKX-ZHKFZR = 'X'. "回款负责人
LS_BAPE_VBAKX-ZQYRQ = 'X'. "签约日期
LS_BAPE_VBAKX-ZYJQRRQ = 'X'. "业绩确认日期
LS_EXTEN-STRUCTURE = 'BAPE_VBAKX'.
LS_EXTEN+30(960) = LS_BAPE_VBAKX.
APPEND LS_EXTENX TO LT_EXTENX.
CLEAR:LS_EXTENX.
ENDIF.
CALL FUNCTION 'BAPI_CONTRACT_CREATEFROMDATA'
EXPORTING
* SALESDOCUMENTIN =
CONTRACT_HEADER_IN = LS_HEADER_IN
CONTRACT_HEADER_INX = LS_HEADER_INX
* SENDER =
* BINARY_RELATIONSHIPTYPE = ' '
* INT_NUMBER_ASSIGNMENT = ' '
* BEHAVE_WHEN_ERROR = ' '
* LOGIC_SWITCH =
* TESTRUN =
* CONVERT = ' '
IMPORTING
SALESDOCUMENT = LV_SALEDOC
TABLES
RETURN = LT_RETURN
CONTRACT_ITEMS_IN = LT_ITEMS_IN
CONTRACT_ITEMS_INX = LT_ITEMS_INX
CONTRACT_PARTNERS = LT_PARNR
CONTRACT_CONDITIONS_IN = LT_COND
CONTRACT_CONDITIONS_INX = LT_CONDX
* CONTRACT_CFGS_REF =
* CONTRACT_CFGS_INST =
* CONTRACT_CFGS_PART_OF =
* CONTRACT_CFGS_VALUE =
* CONTRACT_CFGS_BLOB =
* CONTRACT_CFGS_VK =
* CONTRACT_CFGS_REFINST =
* CONTRACT_DATA_IN =
* CONTRACT_DATA_INX =
* CONTRACT_TEXT =
* CONTRACT_KEYS =
EXTENSIONIN = LT_EXTEN
* PARTNERADDRESSES =
EXTENSIONEX = LT_EXTENX.
LOOP AT LT_RETURN INTO LS_RETURN
WHERE TYPE = 'A'
OR TYPE = 'E'.
EXIT.
ENDLOOP.
IF LS_RETURN IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
COMMIT WORK AND WAIT.
LS_MSG-MSGID = '00'.
LS_MSG-MSGTY = 'E'.
LS_MSG-MSGNO = '001'.
LS_MSG-MSGV1 = GS_CON-BSTKD.
LS_MSG-MSGV2 = '过账失败'.
LS_MSG-MSGV3 = LS_RETURN-MESSAGE.
APPEND LS_MSG TO LT_MSG.
UPDATE ZSD0012T SET ZRZLB1 = 'E'
ZRZTEXT1 = LS_RETURN-MESSAGE
WHERE BSTKD = GS_CON-BSTKD.
COMMIT WORK AND WAIT.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
COMMIT WORK AND WAIT .
LS_MSG-MSGID = '00'.
LS_MSG-MSGTY = 'S'.
LS_MSG-MSGNO = '001'.
LS_MSG-MSGV1 = GS_CON-BSTKD.
LS_MSG-MSGV2 = '过账成功,凭证号:'.
LS_MSG-MSGV3 = LV_SALEDOC .
APPEND LS_MSG TO LT_MSG.
UPDATE ZSD0012T SET ZRZLB1 = 'S'
VBELN = LV_SALEDOC
WHERE BSTKD = GS_CON-BSTKD.
LOOP AT LT_ZSD0013T INTO LS_ZSD0013T WHERE BSTKD = GS_CON-BSTKD.
LS_ZSD0013T-VBELN = LV_SALEDOC.
APPEND LS_ZSD0013T TO LT_ZSD0013T_C.
CLEAR:LS_ZSD0013T.
ENDLOOP.
MODIFY ZSD0013T FROM TABLE LT_ZSD0013T_C.
COMMIT WORK AND WAIT.
ENDIF.
CLEAR:LV_ITEMNO,
LS_RETURN,
LT_ZSD0013T_C,
LT_ITEMS_IN,
LT_ITEMS_INX,
LT_COND,
LT_CONDX,
LT_EXTEN,
LT_EXTENX,
LT_PARNR,
LV_SALEDOC.
ENDAT.
CLEAR:GS_CON,
LS_ITEMS_IN,
LS_ITEMS_INX,
LS_PARNR,
LS_COND,
LS_CONDX,
LS_BAPE_VBAP,
LS_BAPE_VBAK,
LS_EXTEN,
LS_EXTENX,
LT_RETURN,
LS_RETURN.
ENDLOOP.
CLEAR:LT_ZSD0013T,
LS_ZSD0013T.
ENDIF.
CALL FUNCTION 'SCPR_SV_SHOW_MESSAGE_LIST'
EXPORTING
TITLE_TEXT = '过账'
MESSAGE_LIST = LT_MSG.
CLEAR:LT_MSG.