美文网首页
So reject (change)

So reject (change)

作者: Mmm_余安 | 来源:发表于2020-07-23 10:42 被阅读0次

    本例包含SET物料部分订单拒绝,全部拒绝

     DATA: lt_return TYPE TABLE OF bapiret2,
            ls_return TYPE  bapiret2.
      FIELD-SYMBOLS: <f_so> LIKE LINE OF gt_so.
    
      DATA: order_header_in  LIKE  bapisdh1,
            order_header_inx LIKE  bapisdh1x,
            order_item_in    LIKE TABLE OF bapisditm, " Order Items
            order_item_inx   LIKE TABLE OF bapisditmx,
            schedule_lines   LIKE TABLE OF bapischdl,
            schedule_linesx  LIKE TABLE OF bapischdlx.
    
      DATA: i_bapi_view       LIKE  order_view,
            sales_documents   LIKE TABLE OF sales_key,
            order_headers_out LIKE  TABLE OF bapisdhd,
            order_items_out   LIKE TABLE OF bapisdit,
            extensionout      LIKE TABLE OF bapiparex.
      DATA: order_schedules_out LIKE TABLE OF bapisdhedu.
      DATA: origin_line LIKE bapisdit.
    
      DATA: extensionin        LIKE TABLE OF  bapiparex,
            extensionex        LIKE TABLE OF  bapiparex,
            order_partners_out LIKE TABLE OF bapisdpart.
    
    ******* extension
      DATA:   BEGIN OF lwa_ext_head
             ,  structure  TYPE te_struc VALUE 'BAPE_VBAK'
             ,  fld        TYPE bape_vbak
             ,END OF lwa_ext_head
             ,BEGIN OF lwa_ext_headx
             ,  structure  TYPE te_struc VALUE 'BAPE_VBAKX'
             ,  fld        TYPE bape_vbakx
             ,END OF lwa_ext_headx
             ,BEGIN OF lwa_ext_item
             ,  structure  TYPE te_struc VALUE 'BAPE_VBAP'
             ,  fld        TYPE bape_vbap
             ,END OF lwa_ext_item
             ,BEGIN OF lwa_ext_itemx
             ,  structure  TYPE te_struc VALUE 'BAPE_VBAPX'
             ,  fld        TYPE bape_vbapx
             ,END OF lwa_ext_itemx.
    
      DATA: lv_vbeln TYPE vbak-vbeln.
      DATA: lv_reject_all. "reject all
      DATA: lv_posnr_ora TYPE vbap-posnr.
    
    *  SELECT SINGLE * FROM vbap INTO @DATA(lw_vbap)
    *    WHERE vbeln = @pw_main-order
    *      AND posnr = @pw_main-item.
    
      LOOP AT  gt_so INTO gs_so WHERE sel = 'X' AND mess <> 'successful!'.
        CLEAR:sales_documents, order_headers_out, order_items_out, order_schedules_out, extensionout.
        CLEAR: lv_reject_all,lv_vbeln.
        CLEAR:order_header_in,order_header_inx, lt_return,order_item_in,order_item_inx,schedule_lines, schedule_linesx,extensionin.
        CLEAR:  i_bapi_view, origin_line.
    
        IF gs_so-olfmng > gs_so-opqty.
          gs_so-mess =  'error:reject qty.>open qty'.
          gs_so-icon =  icon_led_red.
          MODIFY gt_so FROM gs_so.
          CONTINUE.
        ENDIF.
        lv_vbeln = gs_so-vbeln.
        "IF pw_check-menge <= 0 AND gs_so-kwmeng = gs_so-ord_qty.
        IF gs_so-kwmeng = gs_so-olfmng.
          lv_reject_all = 'X'.
        ENDIF.
    
    
        i_bapi_view-item       = 'X'.
        i_bapi_view-sdschedule = 'X'.
        i_bapi_view-header     = 'X'.
    
        APPEND INITIAL LINE TO sales_documents
               ASSIGNING FIELD-SYMBOL(<f1>).
        <f1>-vbeln = gs_so-vbeln.
    
    "获取原本so相关信息
        CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
          EXPORTING
            i_bapi_view         = i_bapi_view
    *       I_MEMORY_READ       =
    *       I_WITH_HEADER_CONDITIONS       = ' '
          TABLES
            sales_documents     = sales_documents
            order_headers_out   = order_headers_out
            order_items_out     = order_items_out
            order_schedules_out = order_schedules_out
            extensionout        = extensionout.
    
        READ TABLE lt_return INTO DATA(lw_return) WITH KEY type = 'E'.
        IF sy-subrc = 0.
          RETURN.
        ENDIF.
    
        CLEAR lt_return[].
    
        SORT order_items_out BY itm_number DESCENDING.
    
        DATA(lv_posnr) = order_items_out[ 1 ]-itm_number.
        lv_posnr+5 = 0.
        lv_posnr_ora = gs_so-posnr.
    
    ”业务需求itme物料需要带出库存地点,做了处理(可优化)
        DO 10 TIMES.
          DATA(lv_index) = sy-index.
          IF sy-index = 1.
    
            ASSIGN order_items_out[ itm_number = gs_so-posnr ] TO FIELD-SYMBOL(<cr>).
            IF sy-subrc NE 0.
              MESSAGE | Sales document item not found, please refresh. |
                 TYPE 'I'.
              EXIT.
            ENDIF.
    
          ELSE.
    
            ASSIGN order_items_out[ itm_number = lv_posnr_ora hg_lv_item = gs_so-posnr ] TO <cr>.
            IF sy-subrc NE 0.
              EXIT.
            ENDIF.
    
          ENDIF.
    
    
    ****** new item for rejection
          IF lv_reject_all IS INITIAL.
    "部分拒绝
            APPEND INITIAL LINE TO  order_item_in
                   ASSIGNING FIELD-SYMBOL(<2>).
            MOVE-CORRESPONDING <cr> TO <2>.
            lv_posnr = lv_posnr + 10.
    
            <2>-itm_number = lv_posnr .
            <2>-material   = <cr>-material.
            <2>-item_categ = <cr>-item_categ.
            <2>-target_qty = gs_so-olfmng.
            <2>-target_qu  = <cr>-sales_unit .
            <2>-plant      = <cr>-plant .
            IF <cr>-hg_lv_item = gs_so-posnr.
              <2>-store_loc = <cr>-stge_loc.
              <2>-hg_lv_item = lv_posnr - ( lv_index - 1 ) * 10.
            ENDIF.
    
            CLEAR:  <2>-wbs_elem.
            <2>-reason_rej = reason ."'KJ'.
    
    *      clear <2>-ITEM_CATEG.
    
            APPEND INITIAL LINE TO order_item_inx
                   ASSIGNING FIELD-SYMBOL(<3>).
            <3>-itm_number  = lv_posnr .
            <3>-material    = 'X'.
            <3>-item_categ  = 'X'.
            <3>-target_qty  = 'X'.
            <3>-target_qu   = 'X'.
            <3>-reason_rej  = 'X'.
            <3>-updateflag  = 'I'.
            <3>-po_itm_no   = 'X'.
            <3>-plant = 'X'.
            <3>-ship_point  = 'X'.
            IF <cr>-hg_lv_item = gs_so-posnr.
              <3>-store_loc = 'X'.
              <3>-hg_lv_item = 'X'.
            ENDIF.
    
            IF lv_index = 1.."header物料部分发货需要重新插入一行
    
              APPEND INITIAL LINE TO schedule_lines
                     ASSIGNING FIELD-SYMBOL(<4>).
              APPEND INITIAL LINE TO schedule_linesx
                     ASSIGNING FIELD-SYMBOL(<5>).
    
              <4>-itm_number = lv_posnr.
              <4>-sched_line = '0001'.
              <4>-req_qty = gs_so-olfmng.
    
              <5>-itm_number = lv_posnr.
              <5>-sched_line = '0001'.
              <5>-updateflag = 'I'.
              <5>-req_qty = 'X'.
    
            ENDIF.
    ****** oringial line change quantity
            APPEND INITIAL LINE TO  order_item_in
                   ASSIGNING <2>.
            APPEND INITIAL LINE TO order_item_inx
                   ASSIGNING <3>.
    
    
            MOVE-CORRESPONDING <cr> TO <2>.
            <2>-itm_number = <cr>-itm_number .
    *      <2>-MATERIAL   =  <CR>-MATERIAL.
    *      <2>-ITEM_CATEG = <CR>-ITEM_CATEG.
    
            <2>-target_qty = gs_so-kwmeng - gs_so-olfmng.
            <3>-target_qty  = 'X'.
    
            CLEAR:  <2>-wbs_elem, <2>-ship_point.
    
            <3>-itm_number  = <cr>-itm_number .
    
            <3>-updateflag  = 'U'.
    
            DATA: lf_1st.
            CLEAR lf_1st.
            LOOP AT order_schedules_out ASSIGNING FIELD-SYMBOL(<os>)
                    WHERE itm_number = <cr>-itm_number.
              IF lf_1st = ''.
                APPEND INITIAL LINE TO schedule_lines ASSIGNING <4>.
                APPEND INITIAL LINE TO schedule_linesx ASSIGNING <5>.
                MOVE-CORRESPONDING <os> TO <4>.
    
                <4>-itm_number = <os>-itm_number.
                <4>-sched_line = <os>-sched_line.
                <4>-req_qty    = gs_so-kwmeng - gs_so-olfmng ."<os>-req_qty - pw_main-ord_qty + pw_check-menge. "<cr>-req_qty.
    
                <5>-itm_number = <os>-itm_number.
                <5>-sched_line = <os>-sched_line.
                <5>-updateflag = 'U'.
                <5>-req_qty    = 'X'.
                lf_1st = 'X'.
              ELSE.
              ENDIF.
            ENDLOOP.
    
          ELSE.
    "全部拒绝
    *        reject origiall line
            APPEND INITIAL LINE TO  order_item_in
                   ASSIGNING <2>.
            APPEND INITIAL LINE TO order_item_inx
                   ASSIGNING <3>.
            MOVE-CORRESPONDING <cr> TO <2>.
            <2>-itm_number = <cr>-itm_number .
            <2>-reason_rej =  reason ."'KJ'.
            <2>-plant      = <cr>-plant .
            <2>-store_loc  = <cr>-stge_loc .
            <3>-reason_rej  = 'X'.
            CLEAR:  <2>-wbs_elem, <2>-ship_point.
            <3>-itm_number  = <cr>-itm_number .
            <3>-updateflag  = 'U'.
            <3>-plant = 'X'.
            <3>-store_loc = 'X'.
    
            lv_posnr = <cr>-itm_number.
    
          ENDIF.
    
    ******* extension
    
          lwa_ext_item-fld-/bshm/som_incmpl  = 'X'.
    
          lwa_ext_item-fld-vbeln = lv_vbeln.
          lwa_ext_item-fld-posnr = lv_posnr.
          APPEND lwa_ext_item TO extensionin.
    
          lwa_ext_itemx-fld-vbeln = lv_vbeln.
          lwa_ext_itemx-fld-posnr = lv_posnr.
    
          DATA: lv_ci TYPE i.
          lv_ci = 3.
          DO 100 TIMES.
            ASSIGN COMPONENT lv_ci OF STRUCTURE lwa_ext_itemx-fld
                TO FIELD-SYMBOL(<xxx>).
            CHECK sy-subrc EQ 0.
            <xxx> = 'X'.
            lv_ci = lv_ci + 1.
          ENDDO.
          APPEND lwa_ext_itemx TO extensionin.
          UNASSIGN <cr>.
    
          lv_posnr_ora = lv_posnr_ora + 10.
    
        ENDDO.
    **    header
        order_header_in-dlv_block = ''.
        order_header_inx-dlv_block = 'X'.
        order_header_inx-updateflag = 'U'.
    
        DO 10 TIMES.
          IF sy-index <> 1.
            WAIT UP TO 1 SECONDS.
          ENDIF.
          CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
            EXPORTING
              salesdocument    = lv_vbeln
              order_header_in  = order_header_in
              order_header_inx = order_header_inx
            TABLES
              return           = lt_return
              order_item_in    = order_item_in
              order_item_inx   = order_item_inx
              schedule_lines   = schedule_lines
              schedule_linesx  = schedule_linesx
              extensionin      = extensionin.
    
          "Sales document 0000000000 is currently being processed (by user XXXXXX)
          READ TABLE lt_return WITH KEY type = 'E' id = 'V1' number = '042' TRANSPORTING NO FIELDS.
          IF sy-subrc <> 0.
            EXIT.
          ENDIF.
    
        ENDDO.
        READ TABLE lt_return INTO ls_return WITH KEY type = 'E'." TRANSPORTING NO FIELDS.
        IF sy-subrc = 0.
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    
          gs_so-mess = ls_return-message.
          gs_so-icon =  icon_led_red.
          MODIFY gt_so FROM gs_so.
          CONTINUE.
        ELSE.
          gs_so-mess = 'successful!'.
          gs_so-icon =  icon_led_green.
          MODIFY gt_so FROM gs_so.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait = 'X'.
        ENDIF.
    
      ENDLOOP.
      IF sy-subrc <> 0.
        MESSAGE 'Rejected' TYPE 'E'.
      ENDIF.
      LOOP AT  gt_so INTO gs_so WHERE sel = 'X' .
        LOOP AT gt_so ASSIGNING <f_so> WHERE vbeln = gs_so-vbeln AND uepos = gs_so-posnr.
          <f_so>-mess =  gs_so-mess .
          <f_so>-icon =  gs_so-icon.
        ENDLOOP.
      ENDLOOP.
    

    相关文章

      网友评论

          本文标题:So reject (change)

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