美文网首页
ABAP采购订单批导创建2021-07-07

ABAP采购订单批导创建2021-07-07

作者: JayDragon | 来源:发表于2021-07-07 14:33 被阅读0次

    项目需求根据科目分配类别ekpo-knttp不同有不同的处理逻辑,特别是knttp = 'A'(资产采购订单)时如果订单数量超过99得进行拆分且创建相应数量的资产卡片,该批导功能还有对增强的行项目字段及增强的科目账户分配字段及获利能力段的处理
    整个批导的核心代码如下:

    
    FORM import_data .
      DATA:lt_poheader      TYPE STANDARD TABLE OF bapimepoheader,
           lt_poheaderx     TYPE STANDARD TABLE OF bapimepoheaderx,
           lt_poitem        TYPE STANDARD TABLE OF bapimepoitem,
           lt_poitemx       TYPE STANDARD TABLE OF bapimepoitemx,
           lt_poschedule    TYPE STANDARD TABLE OF bapimeposchedule,
           lt_poschedulex   TYPE STANDARD TABLE OF bapimeposchedulx,
           lt_poaccount     TYPE STANDARD TABLE OF bapimepoaccount,
           lt_poaccountx    TYPE STANDARD TABLE OF bapimepoaccountx,
           lt_profit        TYPE TABLE OF bapimepoaccountprofitsegment, "获利能力段
           lt_pocond        TYPE STANDARD TABLE OF bapimepocond,
           lt_pocondx       TYPE STANDARD TABLE OF bapimepocondx,
           lt_potextitem    TYPE STANDARD TABLE OF bapimepotext,
           lt_pocomponents  TYPE STANDARD TABLE OF bapimepocomponent,
           lt_pocomponentsx TYPE STANDARD TABLE OF bapimepocomponentx,
           lt_extensionin   TYPE STANDARD TABLE OF bapiparex,
           lt_pritemtext    TYPE STANDARD TABLE OF bapimepotext,
           lt_return        TYPE STANDARD TABLE OF bapiret2.
    
      DATA:ls_poheader      TYPE  bapimepoheader,
           ls_poheaderx     TYPE  bapimepoheaderx,
           ls_poitem        TYPE  bapimepoitem,
           ls_poitemx       TYPE  bapimepoitemx,
           ls_poschedule    TYPE  bapimeposchedule,
           ls_poschedulex   TYPE  bapimeposchedulx,
           ls_poaccount     TYPE  bapimepoaccount,
           ls_poaccountx    TYPE  bapimepoaccountx,
           ls_profit        TYPE  bapimepoaccountprofitsegment,
           ls_pocond        TYPE  bapimepocond,
           ls_pocondx       TYPE  bapimepocondx,
           ls_potextitem    TYPE  bapimepotext,
           ls_pocomponents  TYPE  bapimepocomponent,
           ls_pocomponentsx TYPE  bapimepocomponentx,
           ls_extensionin   TYPE  bapiparex,
    
           ls_te_item       LIKE  bapi_te_mepoitem,
           ls_te_head       LIKE  bapi_te_mepoheader,
           ls_te_headx      LIKE  bapi_te_mepoheaderx,
           ls_pritemtext    TYPE  bapimepotext,
           ls_return        TYPE  bapiret2.
    
      DATA: lv_ebeln TYPE ekko-ebeln,
            lv_ebelp TYPE ekpo-ebelp.
    
      READ TABLE gt_alv WITH KEY icon = g_red TRANSPORTING NO FIELDS.
      IF sy-subrc = 0.
        MESSAGE '存在错误数据,请处理' TYPE 'S' DISPLAY LIKE 'E'.
      ENDIF.
    
      DATA: lt_asset   TYPE TABLE OF zmmt_asset_tmp,
            ls_asset   TYPE zmmt_asset_tmp,
            ls_input   TYPE zams_assetcreate_input, "资产卡片创建入参
            lv_asset   TYPE bf_anln1, "主资产号
            lv_type    TYPE bapi_mtype,
            lv_message TYPE bapi_msg.
    
      DATA: lt_alv_tmp LIKE gt_alv,
            lv_menge_x TYPE menge_d,
            lv_menge_c TYPE menge_d.
    
      lt_alv_tmp = gt_alv.
      LOOP AT gt_alv ASSIGNING FIELD-SYMBOL(<fs_alv>).
        IF <fs_alv>-knttp IS NOT INITIAL.
          ls_poitem-acctasscat  = <fs_alv>-knttp."科目类别
          ls_poitemx-acctasscat = 'X'.
          IF <fs_alv>-knttp = 'A'."创建资产卡片
            "假如一开始批导的时候,资产卡片创建成功,采购订单号创建失败,这时要把创建成功的资产数据存入自建表ZMMT_ASSET_TMP
            CLEAR lt_asset.
            SELECT * INTO TABLE lt_asset FROM zmmt_asset_tmp WHERE ebeln = <fs_alv>-ebeln AND ebelp = <fs_alv>-ebelp.
            CLEAR lv_menge_c.
            DESCRIBE TABLE lt_asset LINES lv_menge_c."已创建资产数量
            "已创建的资产号数量不等于应创建的资产号数量
            IF lv_menge_c <> <fs_alv>-menge.
              DATA: lv_extwg TYPE mara-extwg, "资产小类
                    lv_maktx TYPE makt-maktx. "资产名称
              CLEAR: ls_input,lv_extwg,lv_maktx.
              SELECT SINGLE mara~extwg makt~maktx INTO (lv_extwg,lv_maktx)
                 FROM mara INNER JOIN makt
                 ON mara~matnr = makt~matnr
                 WHERE mara~matnr = <fs_alv>-matnr
                   AND makt~spras = 1.
              "资产创建入参
              ls_input-action = 'C'.
              ls_input-anlkl  =  lv_extwg+0(1).    "资产类
              ls_input-bukrs  =  <fs_alv>-bukrs.   "公司代码
              ls_input-txt50  =  lv_maktx.         "资产名称
              ls_input-gsber  =  <fs_alv>-bukrs.   "业务范围
              ls_input-kostl  =  <fs_alv>-bukrs.   "成本中心
              ls_input-kostlv =  <fs_alv>-zzkostl. "成本中心对资产负责
              ls_input-ord42  =  'Z01'.            "来源方式:外购
              ls_input-ord44  =  lv_extwg+0(3).    "资产中类
              ls_input-anlue  =  lv_extwg.         "资产小类
              ls_input-meins  =  <fs_alv>-meins.
    
              "还需创建的资产数量 = 应创建资产数量 - 已创建的资产数量
              lv_menge_x = <fs_alv>-menge - lv_menge_c.
    
              DO lv_menge_x TIMES.
                CLEAR: lv_asset,lv_type,lv_message.
                CALL FUNCTION 'ZFM_AM_FIXEDASSET_CREATE'
                  EXPORTING
                    is_input        = ls_input
                    iv_not_equi_syn = ''
    *               IV_TESTRUN      = ''
                    iv_commit       = 'X'
                  IMPORTING
                    ev_asset        = lv_asset
                    ev_type         = lv_type
                    ev_message      = lv_message.
                IF lv_type = 'S'.
                  CLEAR ls_asset.
                  MOVE-CORRESPONDING ls_input TO ls_asset.
                  ls_asset-ebeln   = <fs_alv>-ebeln."原采购订单号
                  ls_asset-ebelp   = <fs_alv>-ebelp."原采购订单行项目号
                  ls_asset-menge   = <fs_alv>-menge."应创建的资产数
                  ls_asset-anln1   = lv_asset.      "主资产号
                  APPEND ls_asset TO lt_asset.
                ENDIF.
              ENDDO.
            ENDIF.
            "如果上面创建资产号时,有创建失败的情况
            DATA lv_flag.
            CLEAR lv_menge_c.
            DESCRIBE TABLE lt_asset LINES lv_menge_c.
            CLEAR lv_flag.
            IF lv_menge_c <> <fs_alv>-menge.
              lv_flag = 'X'."资产号创建不全,不创建采购订单
            ELSE.
              "对科目分配类别为 A 的行项目数量大于 99 的进行数量拆分
              DATA ls_alv LIKE LINE OF gt_alv.
              IF <fs_alv>-menge > 99.
                DELETE lt_alv_tmp WHERE ebeln = <fs_alv>-ebeln AND ebelp = <fs_alv>-ebelp.
                WHILE <fs_alv>-menge > 99.
                  ls_alv = <fs_alv>.
                  ls_alv-menge = 99.
                  <fs_alv>-menge = <fs_alv>-menge - 99.
                  APPEND ls_alv TO lt_alv_tmp.
                ENDWHILE.
                APPEND <fs_alv> TO lt_alv_tmp.
              ENDIF.
            ENDIF.
            IF lt_asset IS NOT INITIAL.
              MODIFY zmmt_asset_tmp FROM TABLE lt_asset.
              IF sy-subrc = 0.
                COMMIT WORK AND WAIT.
              ELSE.
                ROLLBACK WORK.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
        "处理拆分过的数据
        SORT lt_alv_tmp BY ebeln ebelp.
        LOOP AT lt_alv_tmp INTO DATA(ls_alv_tmp) WHERE ebeln = <fs_alv>-ebeln AND ebelp = <fs_alv>-ebelp.
          lv_ebelp = lv_ebelp + 10.
          ls_poitem-po_item   = lv_ebelp."行项目号
          ls_poitemx-po_item  = lv_ebelp.
          ls_poitemx-po_itemx  = 'X'.
          IF <fs_alv>-pstyp IS NOT INITIAL.
            ls_poitem-item_cat   = <fs_alv>-pstyp."项目类别
            ls_poitemx-item_cat  = 'X'.
          ENDIF.
    
          IF <fs_alv>-matnr IS NOT INITIAL.
            ls_poitem-material    = <fs_alv>-matnr."物料号
            ls_poitemx-material = 'X'.
          ENDIF.
    
          IF <fs_alv>-txz01 IS NOT INITIAL.
            ls_poitem-short_text    = <fs_alv>-txz01."采购订单行项目文本
            ls_poitemx-short_text = 'X'.
          ENDIF.
    
          ls_poitem-quantity      = ls_alv_tmp-menge."订单数量
          ls_poitemx-quantity     = 'X'.
    
          IF <fs_alv>-meins IS NOT INITIAL.
            ls_poitem-po_unit      = <fs_alv>-meins."计量单位
            ls_poitemx-po_unit = 'X'.
          ENDIF.
    
          ls_poitem-net_price = <fs_alv>-netpr."订单价格
          ls_poitemx-net_price = 'X'.
    
          IF <fs_alv>-bukrs IS NOT INITIAL.
            ls_poitem-plant        = <fs_alv>-bukrs."工厂
            ls_poitemx-plant       = 'X'.
          ENDIF.
          IF <fs_alv>-lgort IS NOT INITIAL.
            ls_poitem-stge_loc     = <fs_alv>-lgort."库存地点
            ls_poitemx-stge_loc    = 'X'.
          ENDIF.
    
          IF <fs_alv>-konnr IS NOT INITIAL.
            ls_poitem-agreement = <fs_alv>-konnr."合同号
            ls_poitemx-agreement = 'X'.
          ENDIF.
    
          IF <fs_alv>-ktpnr IS NOT INITIAL.
            ls_poitem-agmt_item = <fs_alv>-ktpnr."合同行项目号
            ls_poitemx-agmt_item = 'X'.
          ENDIF.
          "评估类型:若物料主数据在导入公司下的评估类别MARC-BWTTY不为空,则采购单行项目中的物料评估类型EKPO-BWTAR固定放NEW
          DATA lv_bwtty TYPE marc-bwtty.
          CLEAR lv_bwtty.
          SELECT SINGLE bwtty INTO lv_bwtty FROM marc WHERE matnr = <fs_alv>-matnr AND werks = <fs_alv>-bukrs.
          IF sy-subrc = 0 AND lv_bwtty IS NOT INITIAL.
            ls_poitem-val_type = 'NEW'."评估类型
            ls_poitemx-val_type = 'X'.
          ENDIF.
    
          IF <fs_alv>-mwskz IS NOT INITIAL.
            ls_poitem-tax_code     = <fs_alv>-mwskz."税码
            ls_poitemx-tax_code = 'X'.
          ENDIF.
    
          ls_poitem-po_price  = '2'."净价
          ls_poitemx-po_price = 'X'.
    
          IF <fs_alv>-peinh IS NOT INITIAL.
            ls_poitem-price_unit  = <fs_alv>-peinh."每价格单位
            ls_poitemx-price_unit = 'X'.
          ENDIF.
    
          IF <fs_alv>-knttp = 'A'.
            ls_poitem-distrib     = '1'."多重科目分配的分配指示器
            ls_poitem-part_inv    = '1'."部分发票标识
            ls_poitem-gr_non_val  = ''. "货物收据,未评估
            ls_poitemx-distrib    = 'X'.
            ls_poitemx-part_inv   = 'X'.
            ls_poitemx-gr_non_val = 'X'.
          ENDIF.
    
          APPEND ls_poitem  TO lt_poitem.
          APPEND ls_poitemx TO lt_poitemx.
          CLEAR: ls_poitem,ls_poitemx.
          "科目账户分配
          IF <fs_alv>-knttp = 'K'.
            ls_poaccount-po_item = lv_ebelp.
            ls_poaccountx-po_item = lv_ebelp.
            ls_poaccount-serial_no = '01'.
            ls_poaccountx-serial_no = '01'.
            ls_poaccount-costcenter  = |{ <fs_alv>-bukrs ALPHA = IN }|."成本中心
            ls_poaccountx-costcenter = 'X'.
            "自定义字段-科目分配
            CLEAR:ls_extensionin.
            ls_extensionin-structure           = 'BAPI_TE_MEPOACCOUNTING'.
            ls_extensionin-valuepart1+0(5)     = lv_ebelp.                "采购订单号项目号
            ls_extensionin-valuepart1+5(2)     = '01'.                    "科目分配的序号
            ls_extensionin-valuepart1+7(10)    = <fs_alv>-zzkostl.        "管理成本中心
            APPEND ls_extensionin TO lt_extensionin.
    
            CLEAR:ls_extensionin.
            ls_extensionin-structure           = 'BAPI_TE_MEPOACCOUNTINGX'.
            ls_extensionin-valuepart1+0(5)     = lv_ebelp.
            ls_extensionin-valuepart1+5(2)     = '01'.
            ls_extensionin-valuepart1+7(1)     = 'X'.
            APPEND ls_extensionin TO lt_extensionin.
            DATA lv_bklas TYPE mbew-bklas.
            CLEAR lv_bklas.
            SELECT SINGLE bklas INTO lv_bklas FROM mbew
              WHERE matnr = <fs_alv>-matnr
              AND bwkey = <fs_alv>-bukrs.
            IF <fs_alv>-aufnr IS NOT INITIAL OR ( lv_bklas = '1003' OR lv_bklas = '1004')
              OR <fs_alv>-ww005 IS NOT INITIAL.
              "获利能力段-物料编码
              CLEAR:ls_profit.
              ls_profit-po_item                  = lv_ebelp.
              ls_profit-serial_no                = '01'.
              ls_profit-fieldname                = 'ARTNR'.
              ls_profit-value                    = <fs_alv>-matnr.
              APPEND ls_profit TO lt_profit.
              "获利能力段-物料组
              DATA lv_matkl TYPE mara-matkl.
              CLEAR lv_matkl.
              SELECT SINGLE matkl INTO lv_matkl FROM mara WHERE matnr = <fs_alv>-matnr.
              CLEAR:ls_profit.
              ls_profit-po_item                  = lv_ebelp.
              ls_profit-serial_no                = '01'.
              ls_profit-fieldname                = 'MATKL'.
              ls_profit-value                    = lv_matkl.
              APPEND ls_profit TO lt_profit.
              CLEAR lv_matkl.
              "获利能力段-内部订单号
              CLEAR:ls_profit.
              ls_profit-po_item                  = lv_ebelp.
              ls_profit-serial_no                = '01'.
              ls_profit-fieldname                = 'RKAUFNR'.
              ls_profit-value                    = <fs_alv>-aufnr.
              APPEND ls_profit TO lt_profit.
              "获利能力段-车牌号
              CLEAR:ls_profit.
              ls_profit-po_item                  = lv_ebelp.
              ls_profit-serial_no                = '01'.
              ls_profit-fieldname                = 'WW005'.
              ls_profit-value                    = <fs_alv>-ww005.
              APPEND ls_profit TO lt_profit.
            ENDIF.
            APPEND ls_poaccount TO   lt_poaccount.
            APPEND ls_poaccountx TO  lt_poaccountx.
            CLEAR:ls_poaccount,ls_poaccountx.
          ELSEIF <fs_alv>-knttp = 'F'.
            ls_poaccount-po_item = lv_ebelp.
            ls_poaccountx-po_item = lv_ebelp.
            ls_poaccount-serial_no = '01'.
            ls_poaccountx-serial_no = '01'.
            ls_poaccount-costcenter  = |{ <fs_alv>-bukrs ALPHA = IN }|."成本中心
            ls_poaccountx-costcenter = 'X'.
            "自定义字段-科目分配
            CLEAR:ls_extensionin.
            ls_extensionin-structure           = 'BAPI_TE_MEPOACCOUNTING'.
            ls_extensionin-valuepart1+0(5)     = lv_ebelp.                "采购订单号项目号
            ls_extensionin-valuepart1+5(2)     = '01'.                    "科目分配的序号
            ls_extensionin-valuepart1+7(10)    = <fs_alv>-zzkostl.        "管理成本中心
            APPEND ls_extensionin TO lt_extensionin.
    
            CLEAR:ls_extensionin.
            ls_extensionin-structure           = 'BAPI_TE_MEPOACCOUNTINGX'.
            ls_extensionin-valuepart1+0(5)     = lv_ebelp.
            ls_extensionin-valuepart1+5(2)     = '01'.
            ls_extensionin-valuepart1+7(1)     = 'X'.
            APPEND ls_extensionin TO lt_extensionin.
            IF <fs_alv>-aufnr IS NOT INITIAL.
              TRANSLATE <fs_alv>-aufnr TO UPPER CASE.
              ls_poaccount-orderid = |{ <fs_alv>-aufnr ALPHA = IN }|."内部订单号
              ls_poaccountx-orderid = 'X'.
            ENDIF.
            APPEND ls_poaccount TO   lt_poaccount.
            APPEND ls_poaccountx TO  lt_poaccountx.
            CLEAR:ls_poaccount,ls_poaccountx.
          ELSEIF <fs_alv>-knttp = 'A' AND lv_flag IS INITIAL.
            DATA lv_serial_no TYPE dzekkn.
            CLEAR lv_serial_no.
            LOOP AT lt_asset INTO ls_asset.
              ls_poaccount-po_item = lv_ebelp.
              ls_poaccountx-po_item = lv_ebelp.
              lv_serial_no += 1.
              ls_poaccount-asset_no  = ls_asset-anln1."资产号
              ls_poaccountx-asset_no = 'X'.
              ls_poaccount-serial_no = lv_serial_no.
              ls_poaccountx-serial_no = lv_serial_no.
              ls_poaccount-quantity = 1.
              ls_poaccountx-quantity = 'X'.
              ls_poaccount-costcenter = |{ <fs_alv>-bukrs ALPHA = IN }|.
              ls_poaccountx-costcenter = 'X'.
              IF <fs_alv>-aufnr IS NOT INITIAL.
                TRANSLATE <fs_alv>-aufnr TO UPPER CASE.
                ls_poaccount-orderid = |{ <fs_alv>-aufnr ALPHA = IN }|."内部订单号
                ls_poaccountx-orderid = 'X'.
              ENDIF.
              APPEND ls_poaccount TO   lt_poaccount.
              APPEND ls_poaccountx TO  lt_poaccountx.
              DELETE lt_asset WHERE anln1  =  ls_asset-anln1.
              CLEAR:ls_asset,ls_poaccount,ls_poaccountx.
              IF sy-tabix = 99.
                EXIT.
              ENDIF.
            ENDLOOP.
          ENDIF.
    
          "采购订单交货计划行的字段
          ls_poschedule-po_item          = lv_ebelp."行项目
          ls_poschedule-sched_line       = '0001'.
          ls_poschedulex-po_item         = lv_ebelp."行项目
          ls_poschedulex-sched_line      = '0001'.
          ls_poschedule-quantity         = ls_alv_tmp-menge."数量
          ls_poschedulex-quantity        = 'X'."数量
          ls_poschedule-delivery_date    = <fs_alv>-eindt."计划交货时间
          ls_poschedulex-delivery_date   = 'X'."交货时间
    
          APPEND ls_poschedule TO  lt_poschedule.
          APPEND ls_poschedulex TO  lt_poschedulex.
    
          "行项目增强字段处理
          CLEAR: ls_te_item,ls_extensionin.
          ls_extensionin-structure     = 'BAPI_TE_MEPOITEM'.
          ls_extensionin-valuepart1+0(5) = lv_ebelp.                        "行项目
          ls_extensionin-valuepart1+5(30) = <fs_alv>-mrmhzid.               "MRM需求单号
          ls_extensionin-valuepart1+35(11) = <fs_alv>-mrmmxid.              "MRM需求单行项目号
          ls_extensionin-valuepart1+46(10) = <fs_alv>-contactor_id.         "联系人工号
          ls_extensionin-valuepart1+56(50) = <fs_alv>-contactor_name.       "联系人姓名
          ls_extensionin-valuepart1+106(20) = <fs_alv>-manager_phone_no.    "联系人电话
          ls_extensionin-valuepart1+126(20) = <fs_alv>-contactor_add1.      "地址省份
          ls_extensionin-valuepart1+146(20) = <fs_alv>-contactor_add2.      "地址城市
          ls_extensionin-valuepart1+166(20) = <fs_alv>-contactor_add3.      "地址区域
          ls_extensionin-valuepart1+186(54) = <fs_alv>-contactor_add4+0(54)."地址街道门牌
          ls_extensionin-valuepart2+0(46) = <fs_alv>-contactor_add4+54(*).  "地址街道门牌
          ls_extensionin-valuepart2+151(10) = <fs_alv>-zzkostl.             "管理成本中心
          ls_extensionin-valuepart2+161(8) = <fs_alv>-zdatef.               "摊销起始日期
          ls_extensionin-valuepart2+169(8) = <fs_alv>-zdatet.               "摊销结束日期
          APPEND ls_extensionin TO lt_extensionin.
    
          CLEAR ls_extensionin.
          ls_extensionin-structure        = 'BAPI_TE_MEPOITEMX'.
          ls_extensionin-valuepart1+0(5)  = lv_ebelp.
          ls_extensionin-valuepart1+5(1)  = 'X'.
          ls_extensionin-valuepart1+6(1)  = 'X'.
          ls_extensionin-valuepart1+7(1)  = 'X'.
          ls_extensionin-valuepart1+8(1)  = 'X'.
          ls_extensionin-valuepart1+9(1)  = 'X'.
          ls_extensionin-valuepart1+10(1) = 'X'.
          ls_extensionin-valuepart1+11(1) = 'X'.
          ls_extensionin-valuepart1+12(1) = 'X'.
          ls_extensionin-valuepart1+13(1) = 'X'.
          ls_extensionin-valuepart1+22(1) = 'X'.
          ls_extensionin-valuepart1+23(1) = 'X'.
          ls_extensionin-valuepart1+24(1) = 'X'.
          APPEND ls_extensionin TO lt_extensionin.
          CLEAR ls_alv_tmp.
        ENDLOOP.
    
        AT END OF ebeln.
          IF <fs_alv>-sap_ebeln IS NOT INITIAL.
            "如果SAP采购订单号不为空,则外部给号
            ls_poheader-po_number = |{ <fs_alv>-sap_ebeln  ALPHA = IN }|.
            ls_poheaderx-po_number = 'X'.
          ENDIF.
          ls_poheader-collect_no   = <fs_alv>-ebeln."原采购订单号赋值给汇总号
          ls_poheaderx-collect_no  = 'X'.
          ls_poheader-doc_type     = <fs_alv>-bsart."采购订单类型
          ls_poheaderx-doc_type    = 'X'.
          ls_poheader-purch_org    = <fs_alv>-ekorg."采购组织
          ls_poheaderx-purch_org   = 'X'.
          ls_poheader-pur_group    = <fs_alv>-ekgrp."采购组
          ls_poheaderx-pur_group   = 'X'.
          ls_poheader-comp_code    = <fs_alv>-bukrs."公司
          ls_poheaderx-comp_code   = 'X'.
          ls_poheader-vendor       = <fs_alv>-lifnr."供应商
          ls_poheaderx-vendor      = 'X'.
          ls_poheader-pmnttrms     = <fs_alv>-zterm."付款条款
          ls_poheaderx-pmnttrms    = 'X'.
          ls_poheader-currency     = <fs_alv>-waers."货币
          ls_poheaderx-currency    = 'X'.
          ls_poheader-doc_date     = <fs_alv>-bedat."订单日期
          ls_poheaderx-doc_date    = 'X'.
          "抬头增强字段处理:BAPI_TE_MEPOHEADER
          IF lv_flag <> 'X'.
            CALL FUNCTION 'BAPI_PO_CREATE1'
              EXPORTING
                poheader               = ls_poheader
                poheaderx              = ls_poheaderx
                no_price_from_po       = 'X'
                testrun                = ''
              IMPORTING
                exppurchaseorder       = lv_ebeln
              TABLES
                return                 = lt_return
                poitem                 = lt_poitem
                poitemx                = lt_poitemx
                poschedule             = lt_poschedule
                poschedulex            = lt_poschedulex
                poaccount              = lt_poaccount
                poaccountprofitsegment = lt_profit
                poaccountx             = lt_poaccountx
                extensionin            = lt_extensionin.
            LOOP AT lt_return INTO ls_return WHERE type CA 'AE'.
              EXIT.
            ENDLOOP.
    
            IF sy-subrc <> 0."无E类型或A类型错误
              CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                EXPORTING
                  wait = 'X'.
              gs_log-icon   = g_green.
              gs_log-old_ebeln   = <fs_alv>-ebeln.
              gs_log-new_ebeln   = lv_ebeln.
              gs_log-msg = '导入成功 '.
            ELSE.
              CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
              gs_log-icon   = g_red.
              gs_log-old_ebeln   = <fs_alv>-ebeln.
              LOOP AT lt_return INTO ls_return WHERE type CA 'AE'.
                CONCATENATE gs_log-msg ls_return-message INTO gs_log-msg.
              ENDLOOP.
            ENDIF.
          ELSE.
            gs_log-icon        = g_red.
            gs_log-old_ebeln   = <fs_alv>-ebeln.
            gs_log-msg = '资产号创建不全,采购订单创建终止'.
          ENDIF.
    
    
          APPEND gs_log TO gt_log.
          CLEAR:lv_ebeln,lv_ebelp,gs_log,lv_flag.
    
          REFRESH: lt_poheader,lt_poheaderx,lt_poitem,lt_poitemx,lt_poschedule,lt_poschedulex,
                   lt_poaccount,lt_poaccountx,lt_profit,lt_extensionin,lt_return.
          CLEAR: ls_poheader,ls_poheaderx.
        ENDAT.
      ENDLOOP.
    
      "导入订单数据创建成功后更新ALV内表数据字段
      IF gt_log IS NOT INITIAL.
        LOOP AT gt_alv ASSIGNING <fs_alv>.
          READ TABLE gt_log INTO gs_log WITH KEY old_ebeln = <fs_alv>-ebeln.
          IF sy-subrc = 0.
            <fs_alv>-icon = gs_log-icon.
            <fs_alv>-msg = gs_log-msg.
            <fs_alv>-ebeln = gs_log-old_ebeln."原系统采购订单号
            <fs_alv>-new_ebeln = gs_log-new_ebeln.
            CLEAR gs_log.
          ENDIF.
        ENDLOOP.
      ENDIF.
    
    ENDFORM.
    
    

    相关文章

      网友评论

          本文标题:ABAP采购订单批导创建2021-07-07

          本文链接:https://www.haomeiwen.com/subject/jamoultx.html