一、概述
越来越多的公司在数字化转型项目中不仅只上线SAP系统,而是将各模块外围系统同步上线,因此对于业务顾问来说,不只要写增强&报表的FS,还要提供外围系统集成的接口规范,以及集成方案,本文分享一下在某项目中的接口规范以及源码。
1.集成方案
本次项目中,由于客户要求价格必须由财务严格把控,因此通过CRM调用BAPI获取财务在SAP系统中维护的价格主数据的方式。
集成方式大致有:
1、CRM创建订单,设置利润率计算公式,并计算利润率,根据不同利润率触发OA审批,并设置分级审批。
2、财务统计发布建议售价,在建议售价基础上打折,根据折扣和业务员折扣权限触发审批,并设置分级审批。
…
本项目中采用的集成形式为,销售人员在CRM系统中创建销售订单,并将订单数据同步至SAP,SAP调用BAPI模拟创建销售订单,在内表中获取定价过程中的价格主数据,并将其作为基准价返回CRM,销售根据基准价填写给客户的实际售价,CRM系统计算实际售价与基准价的差额,并设置差额审批流程,触发OA审批。审批后返回审批状态,若为审批通过,CRM系统自动触发与SAP的接口,将销售订单数据同步至SAP,SAP创建销售凭证,并返回凭证编号。流程图如下:
2. 接口规范
接口规范即为SAP系统的字段名、类型以及用途
3.接口函数
FUNCTION Z_SD_SO_CREATE.
*“----------------------------------------------------------------------
"“本地接口:
*” EXPORTING
*” LV(ET_RETURN) TYPE ZSDT_SO_RETURN
*" TABLES
*" IT_SOHEAD STRUCTURE ZSDS_SOHEAD_INTF OPTIONAL
*" IT_SOITEM STRUCTURE ZSDS_SOITEM_INTF OPTIONAL
*"----------------------------------------------------------------------
DATA:LS_HEADER TYPE BAPISDHD1,
LS_HEADERX TYPE BAPISDHD1X,
LS_LOGIC_SWITCH TYPE BAPISDLS,
LT_ITEM TYPE TABLE OF BAPISDITM,
LS_ITEM TYPE BAPISDITM,
LT_ITEMX TYPE TABLE OF BAPISDITMX,
LS_ITEMX TYPE BAPISDITMX,
LT_PARTS TYPE TABLE OF BAPIPARNR,
LS_PARTS TYPE BAPIPARNR,
LT_SCH TYPE TABLE OF BAPISCHDL,
LS_SCH TYPE BAPISCHDL,
LT_SCHX TYPE TABLE OF BAPISCHDLX,
LS_SCHX TYPE BAPISCHDLX,
LT_COND TYPE TABLE OF BAPICOND,
LS_COND TYPE BAPICOND,
LT_CONDX TYPE TABLE OF BAPICONDX,
LS_CONDX TYPE BAPICONDX,
LT_TEXT_TMP TYPE TABLE OF BAPISDTEXT,
LT_TEXT TYPE TABLE OF BAPISDTEXT,
LS_TEXT TYPE BAPISDTEXT,
LS_BAPE_VBAK TYPE BAPE_VBAK,
LS_BAPE_VBAKX TYPE BAPE_VBAKX,
LS_BAPE_VBAP TYPE BAPE_VBAP,
LS_BAPE_VBAPX TYPE BAPE_VBAPX,
LT_EXTENSIONIN TYPE TABLE OF BAPIPAREX,
LS_EXTENSIONIN TYPE BAPIPAREX,
LT_RETURN TYPE TABLE OF BAPIRET2,
LS_RETURN TYPE BAPIRET2,
LS_RETURN_INTF TYPE ZSDS_SO_RETURN.
DATA:LV_SO TYPE VBAK-VBELN, "销售订单号
LV_POSNR_INI TYPE VBAP-POSNR. "行号(空值 仅作参数 不赋值)
DATA: LT_KOMV TYPE STANDARD TABLE OF KOMV,
LS_KOMV TYPE KOMV.
CONSTANTS: CNS_MEMORY_ID TYPE CHAR20 VALUE ‘SALEORDER_MAINTAIN’,
CNS_BAPE_VBAK TYPE CHAR20 VALUE ‘BAPE_VBAK’,
CNS_BAPE_VBAP TYPE CHAR20 VALUE ‘BAPE_VBAP’,
CNS_BAPE_VBAKX TYPE CHAR20 VALUE ‘BAPE_VBAKX’,
CNS_BAPE_VBAPX TYPE CHAR20 VALUE ‘BAPE_VBAPX’.
CONSTANTS:CNS_HEAD_TDOBJECT TYPE TDOBJECT VALUE ‘VBBK’,
CNS_ITEM_TDOBJECT TYPE TDOBJECT VALUE ‘VBBP’,
CNS_TDID_01 TYPE TDID VALUE ‘0001’,
CNS_TDID_02 TYPE TDID VALUE ‘0002’,
CNS_AUART_ZOR4 TYPE VBAK-AUART VALUE 'ZOR4', "配件CNS_AUART_ZOR5 TYPE VBAK-AUART VALUE 'ZOR5', "免费CNS_AUART_ZOR6 TYPE VBAK-AUART VALUE 'ZOR6', "服务CNS_AUART_ZOR7 TYPE VBAK-AUART VALUE 'ZOR7', "废料CNS_AUART_ZOR8 TYPE VBAK-AUART VALUE 'ZOR8', "有偿
-
cns_auart_zor9 TYPE vbak-auart VALUE 'ZOR9'. "无偿CNS_KSCHL_ZR02 TYPE KSCHA VALUE 'ZR02',"手工条件类型CNS_KSCHL_ZR01 TYPE KSCHA VALUE 'ZR01',"条件类型CNS_KSCHL_ZK01 TYPE KSCHA VALUE 'ZK01'."条件类型
LOOP AT IT_SOHEAD INTO DATA(LS_SOHEAD).
CLEAR:LT_ITEM,LT_ITEMX,LT_SCH,LT_SCHX,LT_COND,LT_CONDX,LT_PARTS,LT_TEXT,LT_RETURN,LT_EXTENSIONIN,LS_EXTENSIONIN.
"so head
CLEAR:LS_HEADER,LS_HEADERX,LV_SO,LS_LOGIC_SWITCH.IF LS_SOHEAD-VBELN IS NOT INITIAL.
PERFORM FRM_EXIT_ALPHA_INPUT USING LS_SOHEAD-VBELN CHANGING LS_SOHEAD-VBELN.
ENDIF.
LS_HEADER-DOC_TYPE = LS_SOHEAD-AUART. "销售凭证类型
LS_HEADER-SALES_ORG = LS_SOHEAD-VKORG. "销售组织
LS_HEADER-DISTR_CHAN = LS_SOHEAD-VTWEG. "分销渠道
LS_HEADER-DIVISION = LS_SOHEAD-SPART. "产品组
LS_HEADER-PURCH_NO_C = LS_SOHEAD-BSTKD. "客户参考
LS_HEADER-REQ_DATE_H = LS_SOHEAD-KETDAT. "请求交货日期
LS_HEADER-PMNTTRMS = LS_SOHEAD-ZTERM. "付款条款
LS_HEADER-INCOTERMS1 = LS_SOHEAD-INCO1. "国际贸易条款
LS_HEADER-INCOTERMS2 = LS_SOHEAD-INCO2_L. "国际贸易条款位置
LS_HEADER-DOC_DATE = LS_SOHEAD-AUDAT. "凭证日期
LS_HEADER-CURRENCY = LS_SOHEAD-WAERK. "凭证货币
LS_HEADER-EXCHG_RATE = LS_SOHEAD-KURSK. "汇率
IF LS_SOHEAD-BSTDK NE ‘’.
LS_HEADER-PURCH_DATE = LS_SOHEAD-BSTDK. "客户参考日期
LS_HEADERX-PURCH_DATE = ABAP_TRUE.
ENDIF.IF LS_SOHEAD-AUART = CNS_AUART_ZOR5 OR LS_SOHEAD-AUART = CNS_AUART_ZOR8.
LS_HEADER-ORD_REASON = LS_SOHEAD-AUGRU.
ENDIF.
LS_HEADER-CUST_GRP1 = LS_SOHEAD-KVGR1.
LS_HEADER-CUST_GRP2 = LS_SOHEAD-KVGR2.
LS_HEADER-CUST_GRP3 = LS_SOHEAD-KVGR3.
LS_HEADER-VERSION = LS_SOHEAD-VSNMR_V. "跟单员
LS_HEADER-PO_METHOD = LS_SOHEAD-BSARK. "采购订单类型LS_HEADERX-UPDATEFLAG = ZIF_BC_CONSTANTS=>GC_I."‘I’.
LS_HEADERX-DOC_TYPE = ABAP_TRUE.
LS_HEADERX-SALES_ORG = ABAP_TRUE.
LS_HEADERX-DISTR_CHAN = ABAP_TRUE.
LS_HEADERX-DIVISION = ABAP_TRUE.
LS_HEADERX-PURCH_NO_C = ABAP_TRUE.
LS_HEADERX-REQ_DATE_H = ABAP_TRUE.
LS_HEADERX-PMNTTRMS = ABAP_TRUE.
LS_HEADERX-INCOTERMS1 = ABAP_TRUE.
LS_HEADERX-INCOTERMS2 = ABAP_TRUE.
LS_HEADERX-DOC_DATE = ABAP_TRUE.
LS_HEADERX-CURRENCY = ABAP_TRUE.
LS_HEADERX-EXCHG_RATE = ABAP_TRUE.IF LS_SOHEAD-AUART = CNS_AUART_ZOR5 OR LS_SOHEAD-AUART = CNS_AUART_ZOR8.
LS_HEADERX-ORD_REASON = ABAP_TRUE.
ENDIF.
LS_HEADERX-CUST_GRP1 = ABAP_TRUE.
LS_HEADERX-CUST_GRP2 = ABAP_TRUE.
LS_HEADERX-CUST_GRP3 = ABAP_TRUE.
LS_HEADERX-VERSION = ABAP_TRUE. "版本
LS_HEADERX-PO_METHOD = ABAP_TRUE. "采购订单类型LOOP AT IT_SOITEM INTO DATA(LS_SOITEM) WHERE BUSID = LS_SOHEAD-BUSID.
"so item
CLEAR:LS_ITEM,LS_ITEMX.
LS_ITEM-ITM_NUMBER = LS_SOITEM-POSNR."lv_count.
PERFORM FRM_EXIT_MATN1_INPUT USING LS_SOITEM-MATNR CHANGING LS_SOITEM-MATNR.
LS_ITEM-MATERIAL = LS_SOITEM-MATNR. "物料
LS_ITEM-PLANT = LS_SOITEM-WERKS. "工厂
LS_ITEM-SHORT_TEXT = LS_SOITEM-ARKTX. "项目描述
LS_ITEM-ITEM_CATEG = LS_SOITEM-PSTYV. "项目类别
LS_ITEM-TARGET_QTY = LS_SOITEM-KWMENG. "数量
PERFORM FRM_MAT_MEINS_INPUT USING LS_SOITEM-VRKME CHANGING LS_SOITEM-VRKME.
LS_ITEM-TARGET_QU = LS_SOITEM-VRKME. "单位
LS_ITEM-PO_ITM_NO = LS_SOITEM-POSEX. "规格
LS_ITEM-REF_1 = LS_SOITEM-IHREZ. "客户参考(单位)
APPEND LS_ITEM TO LT_ITEM.LS_ITEMX-ITM_NUMBER = LS_SOITEM-POSNR."lv_count. LS_ITEMX-UPDATEFLAG = ZIF_BC_CONSTANTS=>GC_I."'I'. LS_ITEMX-MATERIAL = ABAP_TRUE. LS_ITEMX-PLANT = ABAP_TRUE. LS_ITEMX-SHORT_TEXT = ABAP_TRUE. LS_ITEMX-ITEM_CATEG = ABAP_TRUE. LS_ITEMX-TARGET_QTY = ABAP_TRUE. LS_ITEMX-TARGET_QU = ABAP_TRUE. LS_ITEMX-PO_ITM_NO = ABAP_TRUE. LS_ITEMX-REF_1 = ABAP_TRUE. APPEND LS_ITEMX TO LT_ITEMX."schedule line CLEAR:LS_SCH,LS_SCHX. LS_SCH-ITM_NUMBER = LS_SOITEM-POSNR."lv_count. LS_SCH-SCHED_LINE = 1. LS_SCH-REQ_DATE = LS_SOITEM-ETDAT. LS_SCH-REQ_QTY = LS_SOITEM-KWMENG. LS_SCH-SCHED_TYPE = LS_SOITEM-ETTYP. "计划行类别 APPEND LS_SCH TO LT_SCH.LS_SCHX-ITM_NUMBER = LS_SOITEM-POSNR."lv_count. LS_SCHX-UPDATEFLAG = ZIF_BC_CONSTANTS=>GC_I."'I'. LS_SCHX-SCHED_LINE = 1. LS_SCHX-REQ_DATE = ABAP_TRUE. LS_SCHX-REQ_QTY = ABAP_TRUE. LS_SCHX-SCHED_TYPE = ABAP_TRUE. APPEND LS_SCHX TO LT_SCHX.
**定价 配件-ZOR4 服务类–ZOR6 废料–ZOR7 有偿–ZOR8 ——价格手工输入
-----moidfy by amy 20230423 配件类改为价格自动带出 begin---------
IF
" ls_sohead-auart = cns_auart_zor4 OR
LS_SOHEAD-AUART = CNS_AUART_ZOR6 OR
LS_SOHEAD-AUART = CNS_AUART_ZOR7 OR
LS_SOHEAD-AUART = CNS_AUART_ZOR8.
"ZR02条件类型为手工输入
"Condition line
CLEAR:LS_COND,LS_CONDX.
LS_COND-ITM_NUMBER = LS_SOITEM-POSNR.“lv_count.
LS_COND-COND_TYPE = CNS_KSCHL_ZR02.”'ZR02.
LS_COND-COND_VALUE = LS_SOITEM-KBETR. "单价
LS_COND-COND_UNIT = LS_SOITEM-VRKME .
LS_COND-COND_P_UNT = LS_SOITEM-PEINH .
LS_COND-CURRENCY = LS_SOHEAD-WAERK. "销售凭证货币
APPEND LS_COND TO LT_COND.
LS_CONDX-ITM_NUMBER = LS_SOITEM-POSNR."lv_count.LS_CONDX-COND_TYPE = CNS_KSCHL_ZR02."'ZR02LS_CONDX-COND_VALUE = ABAP_TRUE. "单价(条件金额)LS_CONDX-COND_UNIT = ABAP_TRUE .LS_CONDX-COND_P_UNT = ABAP_TRUE .LS_CONDX-CURRENCY = ABAP_TRUE. "销售凭证货币APPEND LS_CONDX TO LT_CONDX.
-----moidfy by amy 20230423 配件类改为价格自动带出 end---------
ELSE.
"ZK01为折扣价
IF LS_SOHEAD-AUART <> CNS_AUART_ZOR5.
"Condition line
CLEAR:LS_COND,LS_CONDX.
LS_COND-ITM_NUMBER = LS_SOITEM-POSNR.“lv_count.
LS_COND-COND_TYPE = CNS_KSCHL_ZK01.”'ZK01.
-
LS_COND-COND_VALUE = 1."LS_SOITEM-KBETR. "单价
-
LS_COND-COND_UNIT = 'ST' .
-
LS_COND-COND_P_UNT = 100 .LS_COND-CONDVALUE = LS_SOITEM-KBETR. "LS_COND-CURRENCY = LS_SOHEAD-WAERK. "销售凭证货币LS_COND-CURRENCY_2 = LS_SOHEAD-WAERK. "销售凭证货币APPEND LS_COND TO LT_COND.LS_CONDX-ITM_NUMBER = LS_SOITEM-POSNR."lv_count.LS_CONDX-UPDATEFLAG = ZIF_BC_CONSTANTS=>GC_I .LS_CONDX-COND_TYPE = CNS_KSCHL_ZK01."'ZK01'.
-
LS_CONDX-COND_VALUE = ABAP_TRUE. "单价(条件金额)
-
LS_CONDX-COND_UNIT = ABAP_TRUE.
-
LS_CONDX-COND_P_UNT = ABAP_TRUE.LS_CONDX-CURRENCY = ABAP_TRUE. "销售凭证货币APPEND LS_CONDX TO LT_CONDX.ENDIF. ENDIF."item text "--备注 CLEAR:LT_TEXT_TMP. PERFORM FRM_MAINTAIN_TEXT USING LS_SOHEAD-VBELN LS_SOITEM-POSNR CNS_TDID_01 LS_SOITEM-ZTEXT_I CHANGING LT_TEXT_TMP. APPEND LINES OF LT_TEXT_TMP TO LT_TEXT."行项目增强: CLEAR: LS_BAPE_VBAP,LS_BAPE_VBAPX. LS_BAPE_VBAP-POSNR = LS_SOITEM-POSNR. LS_BAPE_VBAPX-POSNR = LS_SOITEM-POSNR. LS_BAPE_VBAP-ZZSEPCT = LS_SOITEM-ZZSEPCT. LS_BAPE_VBAPX-ZZSEPCT = ABAP_TRUE. MOVE CNS_BAPE_VBAP TO LS_EXTENSIONIN-STRUCTURE. ##ENH_OK MOVE LS_BAPE_VBAP TO LS_EXTENSIONIN-VALUEPART1. APPEND LS_EXTENSIONIN TO LT_EXTENSIONIN. CLEAR LS_EXTENSIONIN.MOVE CNS_BAPE_VBAPX TO LS_EXTENSIONIN-STRUCTURE. ##ENH_OK MOVE LS_BAPE_VBAPX TO LS_EXTENSIONIN-VALUEPART1. APPEND LS_EXTENSIONIN TO LT_EXTENSIONIN.
ENDLOOP.
"head text
"–海关文件备注
CLEAR:LT_TEXT_TMP.
PERFORM FRM_MAINTAIN_TEXT USING LS_SOHEAD-VBELN LV_POSNR_INI CNS_TDID_01 LS_SOHEAD-ZTEXT_H1 CHANGING LT_TEXT_TMP.
APPEND LINES OF LT_TEXT_TMP TO LT_TEXT."–生产备注
CLEAR:LT_TEXT_TMP.
PERFORM FRM_MAINTAIN_TEXT USING LS_SOHEAD-VBELN LV_POSNR_INI CNS_TDID_02 LS_SOHEAD-ZTEXT_H2 CHANGING LT_TEXT_TMP.
APPEND LINES OF LT_TEXT_TMP TO LT_TEXT.“partners
CLEAR:LS_PARTS.
LS_PARTS-PARTN_ROLE = CNS_ROLE_SELL.”‘AG’.
LS_PARTS-PARTN_NUMB = LS_SOHEAD-ZROLE_SELL. "售达方
PERFORM FRM_EXIT_ALPHA_INPUT USING LS_PARTS-PARTN_NUMB CHANGING LS_PARTS-PARTN_NUMB.
APPEND LS_PARTS TO LT_PARTS.CLEAR:LS_PARTS.
LS_PARTS-PARTN_ROLE = CNS_ROLE_RECEV."‘RE’.
LS_PARTS-PARTN_NUMB = LS_SOHEAD-ZROLE_RECEV. "收票方
PERFORM FRM_EXIT_ALPHA_INPUT USING LS_PARTS-PARTN_NUMB CHANGING LS_PARTS-PARTN_NUMB.
APPEND LS_PARTS TO LT_PARTS.CLEAR:LS_PARTS.
LS_PARTS-PARTN_ROLE = CNS_ROLE_PAY."‘RG’.
LS_PARTS-PARTN_NUMB = LS_SOHEAD-ZROLE_PAY. "付款方
PERFORM FRM_EXIT_ALPHA_INPUT USING LS_PARTS-PARTN_NUMB CHANGING LS_PARTS-PARTN_NUMB.
APPEND LS_PARTS TO LT_PARTS.CLEAR:LS_PARTS.
LS_PARTS-PARTN_ROLE = CNS_ROLE_DELIV."‘WE’.
LS_PARTS-PARTN_NUMB = LS_SOHEAD-ZROLE_DELIV. "送达方
PERFORM FRM_EXIT_ALPHA_INPUT USING LS_PARTS-PARTN_NUMB CHANGING LS_PARTS-PARTN_NUMB.
APPEND LS_PARTS TO LT_PARTS.
**抬头增强字段写入
"Fill item level self-defined fields
-
extension BAPE_VBAP
CLEAR: LS_BAPE_VBAK,LS_BAPE_VBAKX.
LS_BAPE_VBAK-ZZBRAN1 = LS_SOHEAD-ZZBRAN1.
LS_BAPE_VBAK-ZZBRAN2 = LS_SOHEAD-ZZBRAN2.
LS_BAPE_VBAK-ZZBRAN3 = LS_SOHEAD-ZZBRAN3.
LS_BAPE_VBAK-ZZDJHH = LS_SOHEAD-ZZDJHH.
LS_BAPE_VBAK-ZZSFKKP = LS_SOHEAD-ZZSFKKP.
LS_BAPE_VBAK-ZZISDELV = ‘0’."SO创建 是否发货字段给默认0MOVE CNS_BAPE_VBAK TO LS_EXTENSIONIN-STRUCTURE.
CALL METHOD CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C
EXPORTING
IM_VALUE = LS_BAPE_VBAK
IMPORTING
EX_CONTAINER = LS_EXTENSIONIN+30.
APPEND LS_EXTENSIONIN TO LT_EXTENSIONIN.
CLEAR LS_EXTENSIONIN.LS_BAPE_VBAKX-ZZBRAN1 = ABAP_TRUE.
LS_BAPE_VBAKX-ZZBRAN2 = ABAP_TRUE.
LS_BAPE_VBAKX-ZZBRAN3 = ABAP_TRUE.
LS_BAPE_VBAKX-ZZDJHH = ABAP_TRUE .
LS_BAPE_VBAKX-ZZSFKKP = ABAP_TRUE .
LS_BAPE_VBAKX-ZZISDELV = ABAP_TRUE.MOVE CNS_BAPE_VBAKX TO LS_EXTENSIONIN-STRUCTURE.
##ENH_OK MOVE LS_BAPE_VBAKX TO LS_EXTENSIONIN-VALUEPART1.
APPEND LS_EXTENSIONIN TO LT_EXTENSIONIN.
CLEAR LS_EXTENSIONIN.LS_LOGIC_SWITCH-PRICING = ZIF_BC_CONSTANTS=>GC_C .
IF LS_SOHEAD-AUART = ‘ZRE1’ OR LS_SOHEAD-AUART = ‘ZRE2’
OR LS_SOHEAD-AUART = ‘ZRE3’ OR LS_SOHEAD-AUART = ‘ZRE4’ OR LS_SOHEAD-AUART = ‘ZRE5’
OR LS_SOHEAD-AUART = ‘ZRE6’ OR LS_SOHEAD-AUART = ‘ZRE7’ OR LS_SOHEAD-AUART = ‘ZCR1’.CALL FUNCTION ‘BAPI_CUSTOMERRETURN_CREATE’
EXPORTING
SALESDOCUMENTIN = LS_SOHEAD-VBELN
RETURN_HEADER_IN = LS_HEADER
RETURN_HEADER_INX = LS_HEADERX
LOGIC_SWITCH = LS_LOGIC_SWITCH
TESTRUN = LS_SOHEAD-TESTRUN
IMPORTING
SALESDOCUMENT = LV_SO
TABLES
RETURN = LT_RETURN
RETURN_ITEMS_IN = LT_ITEM
RETURN_ITEMS_INX = LT_ITEMX
RETURN_PARTNERS = LT_PARTS
RETURN_SCHEDULES_IN = LT_SCH
RETURN_SCHEDULES_INX = LT_SCHX
RETURN_CONDITIONS_IN = LT_COND
EXTENSIONIN = LT_EXTENSIONIN
RETURN_TEXT = LT_TEXT.ELSE.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' EXPORTINGSALESDOCUMENTIN = LS_SOHEAD-VBELNORDER_HEADER_IN = LS_HEADERORDER_HEADER_INX = LS_HEADERXLOGIC_SWITCH = LS_LOGIC_SWITCHTESTRUN = LS_SOHEAD-TESTRUN IMPORTINGSALESDOCUMENT = LV_SO TABLESRETURN = LT_RETURNORDER_ITEMS_IN = LT_ITEMORDER_ITEMS_INX = LT_ITEMXORDER_PARTNERS = LT_PARTSORDER_SCHEDULES_IN = LT_SCHORDER_SCHEDULES_INX = LT_SCHXORDER_CONDITIONS_IN = LT_CONDORDER_CONDITIONS_INX = LT_CONDXORDER_TEXT = LT_TEXTEXTENSIONIN = LT_EXTENSIONIN.
ENDIF.
CLEAR: LS_RETURN_INTF-MSGTXT .
LOOP AT LT_RETURN ASSIGNING FIELD-SYMBOL(<LFS_RETURN>) WHERE TYPE CA ZIF_BC_CONSTANTS=>GC_AEX .
CONCATENATE LS_RETURN_INTF-MSGTXT <LFS_RETURN>-MESSAGE INTO LS_RETURN_INTF-MSGTXT SEPARATED BY ZIF_BC_CONSTANTS=>GC_SEPARATOR .
ENDLOOP.IF SY-SUBRC = 0 OR LS_SOHEAD-TESTRUN = ABAP_TRUE.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.LS_RETURN_INTF-BUSID = LS_SOHEAD-BUSID. IF LS_RETURN_INTF-MSGTXT IS NOT INITIAL .LS_RETURN_INTF-STATUS = ZIF_BC_CONSTANTS=>GC_E . ELSE.LS_RETURN_INTF-STATUS = ZIF_BC_CONSTANTS=>GC_S .LS_RETURN_INTF-MSGTXT = TEXT-004 . ENDIF.CLEAR: LT_KOMV[] . IMPORT XKOMV = LT_KOMV FROM MEMORY ID CNS_MEMORY_ID . DELETE FROM MEMORY ID CNS_MEMORY_ID .LOOP AT LT_KOMV INTO LS_KOMV .APPEND INITIAL LINE TO LS_RETURN_INTF-PRICE ASSIGNING FIELD-SYMBOL(<LFS_PRICE>) .<LFS_PRICE>-POSNR = LS_KOMV-KPOSN.<LFS_PRICE>-KSCHL = LS_KOMV-KSCHL.<LFS_PRICE>-KBETR = LS_KOMV-KBETR .<LFS_PRICE>-WAERS = LS_KOMV-WAERS.<LFS_PRICE>-KPEIN = LS_KOMV-KPEIN.<LFS_PRICE>-KMEIN = LS_KOMV-KMEIN.PERFORM FRM_MAT_MEINS_OUTPUT USING <LFS_PRICE>-KMEIN CHANGING <LFS_PRICE>-KMEIN . ENDLOOP. APPEND LS_RETURN_INTF TO ET_RETURN.
ELSE. "SO创建成功
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGWAIT = ZIF_BC_CONSTANTS=>GC_X. "'X'.LS_RETURN_INTF-BUSID = LS_SOHEAD-BUSID. LS_RETURN_INTF-VBELN = LV_SO. LS_RETURN_INTF-STATUS = ZIF_BC_CONSTANTS=>GC_S. LS_RETURN_INTF-MSGTXT = TEXT-001. APPEND LS_RETURN_INTF TO ET_RETURN.
ENDIF.
ENDLOOP.
ENDFUNCTION.