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

项目需求根据科目分配类别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.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,236评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,867评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,715评论 0 340
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,899评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,895评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,733评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,085评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,722评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,025评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,696评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,816评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,447评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,057评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,254评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,204评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,561评论 2 343

推荐阅读更多精彩内容

  • 第五章 现金流量表分析 5.1 现金流量表简介 一、现金流量表的定义 现金流量表是以收付实现制为基础编制的,反映企...
    小镭Ra阅读 4,629评论 0 3
  • SAP 需要手工录入的凭证很少,主要是零星费用、收款付款等操作。随着越来越多企业实施了银企直连、财务共享平台等,费...
    Stone0823阅读 2,777评论 0 2
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 8,520评论 28 53
  • 信任包括信任自己和信任他人 很多时候,很多事情,失败、遗憾、错过,源于不自信,不信任他人 觉得自己做不成,别人做不...
    吴氵晃阅读 6,181评论 4 8
  • 步骤:发微博01-导航栏内容 -> 发微博02-自定义TextView -> 发微博03-完善TextView和...
    dibadalu阅读 3,125评论 1 3