首页 > 其他 > 详细

修改采购订单,服务型采购订单

时间:2019-10-31 10:43:57      阅读:88      评论:0      收藏:0      [点我收藏+]

  DATA: wa_item     TYPE  zmodifypurorder_tab.
  DATA: wa_services TYPE  zmodifypurorder_tab2.

  DATA:ext_line  TYPE n LENGTH 10.
  DATA:line_no   TYPE n LENGTH 10.
  DATA:pckg_no   TYPE n LENGTH 10.
  DATA:serial_no TYPE n LENGTH 2 .

  pckg_no   = ‘0000000000‘. "软件包号
  line_no   = ‘0000000001‘. "内部行编号
  ext_line  = ‘0000000000‘. "行号
  serial_no = ‘00‘        . "帐户分配的顺序编号


  IF i_header-ebeln IS INITIAL.
    msg_type = ‘E‘.
    message = ‘采购订单号为空‘.
    EXIT.
  ENDIF.

  DATA:pocondheader    TYPE STANDARD TABLE OF  bapimepocondheader,
       wa_pocondheader TYPE  bapimepocondheader,
       pocondheaderx    TYPE STANDARD TABLE OF  bapimepocondheaderx,
       wa_pocondheaderx LIKE  bapimepocondheaderx.


  IF i_header-loekz = ‘X‘."整个删除采购订单,X为删除标识,删除后的取消删除是 L 。
    gs_poheader-po_number   = i_header-ebeln."采购凭证号
    gs_poheader-delete_ind  = ‘X‘."采购凭证中的删除标识
    gs_poheaderx-po_number  = ‘X‘."采购凭证号
    gs_poheaderx-delete_ind = ‘X‘."采购凭证中的删除标识

  ELSE.
    gs_poheader-po_number   = i_header-ebeln."采购凭证号
    gs_poheader-comp_code   = i_header-bukrs. "公司代码 bukrs  公司代码
    gs_poheader-purch_org   = i_header-ekorg. "采购组织 ekorg  采购组织
    gs_poheader-pur_group   = i_header-ekgrp. "采购组 ekgrp  采购组
    gs_poheaderx-po_number  = ‘X‘."采购凭证号
    gs_poheaderx-comp_code  = ‘X‘."公司代码
    gs_poheaderx-purch_org  = ‘X‘."采购组织
    gs_poheaderx-pur_group  = ‘X‘."采购组

    LOOP AT it_items INTO wa_item.
      CALL METHOD z_itf_utils=>add_zero
        CHANGING
          c_input = wa_item-ebelp.
      CALL METHOD z_itf_utils=>add_zero
        CHANGING
          c_input = wa_item-matnr.
      IF wa_item-loekz = ‘X‘."行项目有删除标识

        gwa_item-po_item    = wa_item-ebelp."采购凭证的项目编号
        gwa_item-material   = wa_item-matnr."物料号
        gwa_item-delete_ind = ‘X‘."采购凭证中的删除标识
        APPEND gwa_item TO gt_item.

        gwa_itemx-po_item    = wa_item-ebelp."采购凭证的项目编号
        gwa_itemx-po_itemx   = ‘X‘."采购凭证的项目编号
        gwa_itemx-material   = ‘X‘."物料号
        gwa_itemx-delete_ind = ‘X‘."采购凭证中的删除标识
        APPEND gwa_itemx TO gt_itemx.


      ELSE." 行项目有更新
        SELECT SINGLE packno INTO pckg_no FROM ekpo
          WHERE ebeln = i_header-ebeln AND ebelp = wa_item-ebelp.
        IF pckg_no <> ‘0‘."服务型订单
          "1.------------------先更新行项目描述,只更新服务行明细不能成功,必须更新行项目行任意数据,所以只能暂时先随便更新行项目描述,然后再根据数据更新行项目和服务行
          gwa_item-po_item        = wa_item-ebelp  ."采购凭证的项目编号 ebelp  采购凭证的项目编号
          gwa_item-short_text     = ‘修改‘."‘加入新的冷冻液‘ 短文本
          APPEND gwa_item TO gt_item.

          gwa_itemx-po_item        = wa_item-ebelp  ."采购凭证的项目编号
          gwa_itemx-short_text     = ‘X‘.
          APPEND gwa_itemx TO gt_itemx.
          CLEAR:gwa_itemx,gwa_item.

          CLEAR: gt_return, gwa_return.
          CALL FUNCTION ‘BAPI_PO_CHANGE‘
            EXPORTING
              purchaseorder = i_header-ebeln
              poheader      = gs_poheader
              poheaderx     = gs_poheaderx
            TABLES
              return        = gt_return
              poitem        = gt_item
              poitemx       = gt_itemx.
          LOOP AT gt_return INTO gwa_return WHERE type = ‘E‘ OR type = ‘A‘.
            msg_type = ‘E‘.
            EXIT.
            CLEAR gwa_return.
          ENDLOOP.
          IF msg_type EQ ‘E‘.
            message = ‘采购订单修改失败. ‘.
            CLEAR gwa_return.
            LOOP AT gt_return INTO gwa_return.
              IF gwa_return-type = ‘E‘ OR gwa_return-type = ‘A‘.
                CONCATENATE message gwa_return-message INTO message.
              ENDIF.
              CLEAR gwa_return.
            ENDLOOP.
            CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘.
          ELSE.
            "提交所做得更改
            CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘
              EXPORTING
                wait = ‘X‘.
            IF sy-subrc = 0.
*              msg_type = ‘S‘.
*              message = ‘采购订单修改成功. ‘.
            ELSE.
              msg_type = ‘E‘.
              message = ‘采购订单修改失败: 未知异常. ‘.
              CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘.
            ENDIF.
          ENDIF.
          "2------------------------重新更新采购订单数据
          CLEAR:gwa_item,gt_item,gwa_itemx,gt_itemx.
          ext_line    =  ‘0000000000‘ ."行号
          line_no     =  ‘0000000001‘ ."内部行编号

          CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
            EXPORTING
              input  = pckg_no
            IMPORTING
              output = pckg_no.

          gwa_item-po_item        = wa_item-ebelp  ."采购凭证的项目编号 ebelp  采购凭证的项目编号
          gwa_item-stge_loc       = wa_item-mlgort . "收货库存地点   lgobe  库存地点
          gwa_item-tax_code       = wa_item-mwskz  . "税码      mwskz  销售/购买税代码
          gwa_item-short_text     = wa_item-ktext1 ."‘加入新的冷冻液‘ 短文本
          gwa_item-pckg_no        = pckg_no.
          APPEND gwa_item TO gt_item.


          gwa_itemx-po_item        = wa_item-ebelp  ."采购凭证的项目编号
          gwa_itemx-stge_loc       = ‘X‘. "收货库存地点
          gwa_itemx-tax_code       = ‘X‘. "税码
          gwa_itemx-short_text     = ‘X‘.
          gwa_itemx-pckg_no        = ‘X‘.
          APPEND gwa_itemx TO gt_itemx.

          "服务订单概要行
          gwa_poservices-pckg_no   = pckg_no  .
          gwa_poservices-line_no   = line_no  ."内部行编号
          gwa_poservices-ext_line  = ext_line ."行号

          pckg_no  = pckg_no +  1 .
          CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
            EXPORTING
              input  = pckg_no
            IMPORTING
              output = pckg_no.

          gwa_poservices-subpckg_no  = pckg_no  .
          APPEND gwa_poservices TO gt_poservices.


          "服务包数据
          LOOP AT it_services INTO wa_services WHERE ebelp = wa_item-ebelp  ."采购凭证的项目编号
            "开始处理服务明细
            ext_line  = ext_line +  10  ."行号
            SELECT SINGLE introw INTO line_no FROM esll" 内部行编号
               WHERE packno = pckg_no AND extrow = ext_line.
            IF sy-subrc <> ‘0‘ .
              line_no   = line_no  +  1   ."内部行编号
            ENDIF.

            CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
              EXPORTING
                input  = ext_line
              IMPORTING
                output = ext_line.

            CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
              EXPORTING
                input  = line_no
              IMPORTING
                output = line_no.

            gwa_poservices-pckg_no       = pckg_no   .
            gwa_poservices-line_no       = line_no   ."内部行编号
            gwa_poservices-ext_line      = ext_line  ."行号
            gwa_poservices-subpckg_no    = ‘0000000000‘ .
            gwa_poservices-short_text    = wa_services-ktext1."  短文本
            gwa_poservices-quantity      = wa_services-menge ." 数量带标记
            gwa_poservices-base_uom      = wa_services-meins ." 基本计量单位
            gwa_poservices-gr_price      = wa_services-brtwr ." 总价
            gwa_poservices-tax_code      = wa_item-mwskz     ." 销售/购买税代码
*           gwa_poservices-matl_group    = wa_item-matkl     ." 物料组
*           gwa_poservices-DELETE_IND = ."删除标识
            APPEND gwa_poservices TO gt_poservices.

            serial_no  =  serial_no +  1  ."账户分配规范序号:服务行
            CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
              EXPORTING
                input  = serial_no
              IMPORTING
                output = serial_no.

            gwa_povalues-pckg_no        = pckg_no  .
            gwa_povalues-line_no        = line_no  ."内部行编号
            gwa_povalues-serno_line     = serial_no  ."账户分配规范序号:服务行
            gwa_povalues-serial_no      = serial_no  ."帐户分配的顺序编号
            APPEND gwa_povalues TO gt_povalues  .

*------总账科目
            gwa_poaccount-po_item     = wa_item-ebelp."采购凭证的项目编号 .
            gwa_poaccount-serial_no   = serial_no    . "账户分配规范序号:服务行
            gwa_poaccount-gl_account  = wa_item-sakto."总账科目编号
            gwa_poaccount-costcenter  = wa_item-kostl."成本中心
            gwa_poaccount-co_area     = ‘XF00‘       .
            CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
              EXPORTING
                input  = wa_item-aufnr
              IMPORTING
                output = wa_item-aufnr.
            gwa_poaccount-orderid      = wa_item-aufnr."内部订单号
            APPEND gwa_poaccount TO gt_poaccount.

            gwa_poaccountx-po_item     = wa_item-ebelp."采购凭证的项目编号
            gwa_poaccountx-serial_no   = serial_no    ."帐户分配的顺序编号
            gwa_poaccountx-gl_account  =  ‘X‘         .
            gwa_poaccountx-costcenter  =  ‘X‘         .
            gwa_poaccountx-co_area     =  ‘X‘         .
            gwa_poaccountx-orderid     =  ‘X‘         .
            APPEND gwa_poaccountx TO gt_poaccountx.
            CLEAR:wa_services,gwa_poservices,gwa_povalues,gwa_poaccount,gwa_poaccountx.
          ENDLOOP.




****************************************************************************************************************
        ELSE."普通的采购订单
          gwa_item-po_item        = wa_item-ebelp  ."采购凭证的项目编号 ebelp  采购凭证的项目编号
          gwa_item-material       = wa_item-matnr  ."物料号
          gwa_item-plant          = wa_item-mwerks . "收货工厂 name1  工厂
          gwa_item-stge_loc       = wa_item-mlgort . "收货库存地点   lgobe  库存地点
*         gwa_item-quantity       = wa_item-erfmg  . "采购订单数量       menge  采购订单数量
          gwa_item-tax_code       = wa_item-mwskz  . "税码      mwskz  销售/购买税代码
          gwa_item-net_price      = wa_item-netpr."净价
          gwa_item-po_price       = ‘2‘. "价格采纳:1 = 总值, 2 = 净值
          gwa_item-price_unit     = wa_item-peinh. "价格单位
          gwa_item-short_text     = wa_item-ktext1 ."‘加入新的冷冻液‘ 短文本
          gwa_item-matl_group     = wa_item-matkl  ." ‘Z003‘   物料组
          gwa_item-pckg_no        = pckg_no.
          APPEND gwa_item TO gt_item.


          gwa_itemx-po_item        = wa_item-ebelp  ."采购凭证的项目编号
          gwa_itemx-material       = ‘X‘  ."物料号
          gwa_itemx-plant          = ‘X‘. "收货工厂
          gwa_itemx-stge_loc       = ‘X‘. "收货库存地点
*         gwa_itemx-quantity       = ‘X‘. "采购订单数量
          gwa_itemx-tax_code       = ‘X‘. "税码
          gwa_itemx-net_price      = ‘X‘.
          gwa_itemx-po_price       = ‘X‘.
          gwa_itemx-price_unit     = ‘X‘.
          gwa_itemx-short_text     = ‘X‘.
          gwa_itemx-matl_group     = ‘X‘.
          gwa_itemx-pckg_no        = ‘X‘.
          APPEND gwa_itemx TO gt_itemx.
        ENDIF.


        "交货日期的处理
        gwa_poschedule-po_item        = wa_item-ebelp. "采购凭证的项目编号
        gwa_poschedule-del_datcat_ext = ‘D‘."交货日期的类别
        IF wa_item-eeind IS NOT INITIAL.
          gwa_poschedule-delivery_date  = wa_item-eeind."交货日期
        ENDIF.

        gwa_poschedule-quantity       = wa_item-erfmg."采购订单数量
        APPEND gwa_poschedule TO gt_poschedule.

        gwa_poschedulex-po_item        = wa_item-ebelp. "采购凭证的项目编号
        gwa_poschedulex-del_datcat_ext = ‘X‘."交货日期的类别
        gwa_poschedulex-delivery_date  = ‘X‘."交货日期
        gwa_poschedulex-quantity       = ‘X‘."采购订单数量
        APPEND gwa_poschedulex TO gt_poschedulex.
      ENDIF.


      CLEAR: wa_item,gwa_item, gwa_itemx,gwa_povalues,gwa_poservices,
      gwa_poschedule,gwa_poschedulex,
      gwa_poaccount,gwa_poaccountx.
    ENDLOOP.
  ENDIF.


  CLEAR: gt_return, gwa_return.
  CALL FUNCTION ‘BAPI_PO_CHANGE‘
    EXPORTING
      purchaseorder                = i_header-ebeln
      poheader                     = gs_poheader
      poheaderx                    = gs_poheaderx
   TABLES
     return                       = gt_return
     poitem                       = gt_item
     poitemx                      = gt_itemx
     poschedule                   = gt_poschedule
     poschedulex                  = gt_poschedulex
     poaccount                    = gt_poaccount
     poaccountx                   = gt_poaccountx
     poservices                   = gt_poservices
     posrvaccessvalues            = gt_povalues  .
  LOOP AT gt_return INTO gwa_return WHERE type = ‘E‘ OR type = ‘A‘.
    msg_type = ‘E‘.
    EXIT.
    CLEAR gwa_return.
  ENDLOOP.
  IF msg_type EQ ‘E‘.
    message = ‘采购订单修改失败. ‘.
    CLEAR gwa_return.
    LOOP AT gt_return INTO gwa_return.
      IF gwa_return-type = ‘E‘ OR gwa_return-type = ‘A‘.
        CONCATENATE message gwa_return-message INTO message.
      ENDIF.
      CLEAR gwa_return.
    ENDLOOP.
    CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘.
  ELSE.
*   提交所做得更改
    CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘
      EXPORTING
        wait = ‘X‘.
    IF sy-subrc = 0.
      msg_type = ‘S‘.
      message = ‘采购订单修改成功. ‘.
    ELSE.
      msg_type = ‘E‘.
      message = ‘采购订单修改失败: 未知异常. ‘.
      CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘.
    ENDIF.
  ENDIF.

修改采购订单,服务型采购订单

原文:https://www.cnblogs.com/moqi222/p/11769831.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!