ABAP EWM 库存状态变更

Posted 想发财的小夏

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP EWM 库存状态变更相关的知识,希望对你有一定的参考价值。

仓库间调拨,更改目标仓位目标库存地点,用fm:/SCWM/STOCK_CHANGE,前台tcode:/n/scwm/post

FUNCTION zewm_change_stock.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     REFERENCE(IV_LGNUM) TYPE  /SCWM/LGNUM
*"     REFERENCE(IT_INPUT) TYPE  ZEWM_T_001
*"  EXPORTING
*"     REFERENCE(ET_OUTPUT) TYPE  BAPIRET2_TAB
*"----------------------------------------------------------------------

  DATA:
    lr_huident  TYPE rseloption,
    lt_huitm    TYPE /scwm/tt_stock_select,
    lt_huhdr    TYPE /scwm/tt_huhdr,
    ls_header   TYPE /scwm/s_gmheader,
    lt_item     TYPE /scwm/tt_spitem,
    ls_item     TYPE /scwm/s_spitem,
    lt_ltap_vb  TYPE /scwm/tt_ltap_vb,
    lt_bapiret  TYPE bapiret2_tab,
    lt_bapiret2 TYPE bapiret2_tab,
    lv_severity TYPE bapi_mtype,
    lv_id       TYPE /lime/line_item_id.

  CLEAR:lt_bapiret.

  LOOP AT it_input INTO DATA(ls_input).

    CLEAR:lv_severity.

    /scwm/cl_tm=>cleanup( ).
    /scwm/cl_tm=>set_lgnum( iv_lgnum ).

    lr_huident = VALUE #( ( sign = 'I' option = 'EQ' low = ls_input-huident ) ).
    CLEAR: lt_huitm, lt_huhdr.
    CALL FUNCTION '/SCWM/SELECT_STOCK'
      EXPORTING
        iv_lgnum   = iv_lgnum
        ir_huident = lr_huident
      IMPORTING
        et_huitm   = lt_huitm
        et_huhdr   = lt_huhdr
      EXCEPTIONS
        error      = 1.

    IF lt_huitm[] IS INITIAL.
      lv_severity = 'E'.
      APPEND VALUE #( id = '00' type = 'E' number = '398' message = '未查询到HU:' && ls_input-huident ) TO lt_bapiret.
      CONTINUE.
    ENDIF.
    READ TABLE lt_huitm INTO DATA(ls_huitm) INDEX 1.

    CLEAR ls_header.
    ls_header-lgnum = iv_lgnum.
    ls_header-created_by = sy-uname.
    ls_header-post  = abap_false.
    ls_header-compl = abap_true.
    ls_header-code = '/SCWM/POST'.

    CLEAR:lv_id,lt_item,ls_item,ls_item-t_quan.
    ADD 1 TO lv_id.
    ls_item-id                     = lv_id.
    ls_item-id_group               = '2'.
    ls_item-direction              = 'T'.
    ls_item-procty                 = ls_input-procty.
    ls_item-guid_hu                = ls_input-guid_hu.
    ls_item-huident                = ls_input-huident.
*    ls_item-squant_set             = 'X'.
    ls_item-loc-lgnum              = ls_huitm-lgnum.
    ls_item-loc-lgtyp              = ls_huitm-lgtyp.
    ls_item-loc-lgpla              = ls_huitm-lgpla.
    " 源
    ls_item-source_s-idx_stock     = ls_huitm-idx_stock.
    ls_item-source_s-guid_stock    = ls_huitm-guid_stock.
    ls_item-source_s-matid         = ls_huitm-matid.
    ls_item-source_s-batchid       = ls_huitm-batchid.
    ls_item-source_s-cat           = ls_huitm-cat.
    ls_item-source_s-stock_doccat  = ls_huitm-stock_doccat.
    ls_item-source_s-stock_docno   = ls_huitm-stock_docno.
    ls_item-source_s-stock_itmno   = ls_huitm-stock_itmno.
    ls_item-source_s-stock_usage   = ls_huitm-stock_usage.
    ls_item-source_s-owner         = ls_huitm-owner.
    ls_item-source_s-owner_role    = ls_huitm-owner_role.
    ls_item-source_s-entitled      = ls_huitm-entitled.
    ls_item-source_s-entitled_role = ls_huitm-entitled_role.
    ls_item-source_s-stock_cnt     = ls_huitm-stock_cnt.
    ls_item-source_s-qdoccat       = ls_huitm-qdoccat.
    ls_item-source_s-qdocid        = ls_huitm-qdocid.
    ls_item-source_s-qitmid        = ls_huitm-qitmid.
    " 目标
    ls_item-dest_s-matid           = ls_huitm-matid.
    ls_item-dest_s-batchid         = ls_input-batchid.
    ls_item-dest_s-cat             = ls_input-to_cat.   " Cat
    ls_item-dest_s-stock_doccat    = ls_huitm-stock_doccat.
    ls_item-dest_s-stock_docno     = ls_huitm-stock_docno.
    ls_item-dest_s-stock_itmno     = ls_huitm-stock_itmno.
    ls_item-dest_s-stock_usage     = ls_huitm-stock_usage.
    ls_item-dest_s-owner           = ls_input-owner.
    ls_item-dest_s-owner_role      = ls_huitm-owner_role.
    ls_item-dest_s-entitled        = ls_input-entitled.
    ls_item-dest_s-entitled_role   = ls_huitm-entitled_role.
    ls_item-dest_s-stock_cnt       = ls_huitm-stock_cnt.
    ls_item-dest_s-qdoccat         = ls_huitm-qdoccat.
    ls_item-dest_s-qdocid          = ls_huitm-qdocid.
    ls_item-dest_s-qitmid          = ls_huitm-qitmid.
    ls_item-dest_loc-lgnum         = ls_huitm-lgnum.
    ls_item-dest_loc-lgtyp         = ls_input-nltyp.    " 目标存储类型
    ls_item-dest_loc-lgpla         = ls_input-nlpla.    " 目标仓位

    APPEND VALUE #( quan = ls_huitm-quan unit = ls_huitm-meins ) TO ls_item-t_quan.
    APPEND ls_item TO lt_item.

    IF lt_item IS NOT INITIAL.
      CLEAR: lt_ltap_vb, lt_bapiret2, lv_severity.
      CALL FUNCTION '/SCWM/STOCK_CHANGE'
        EXPORTING
          is_header   = ls_header
          it_item     = lt_item
        IMPORTING
          et_ltap_vb  = lt_ltap_vb
          et_bapiret  = lt_bapiret2
          ev_severity = lv_severity
        EXCEPTIONS
          wrong_input = 1
          OTHERS      = 2.

      IF sy-subrc <> 0.
        lv_severity = 'E'.
      ELSE.
        LOOP AT lt_bapiret2 TRANSPORTING NO FIELDS WHERE type CA 'EAX'.
          lv_severity = 'E'.
          EXIT.
        ENDLOOP.
      ENDIF.

      IF lv_severity <> 'E'.
        CLEAR: lt_bapiret2, lv_severity.
        CALL FUNCTION '/SCWM/GM_POST'
          IMPORTING
            et_bapiret  = lt_bapiret2
            ev_severity = lv_severity.
        LOOP AT lt_bapiret2 TRANSPORTING NO FIELDS WHERE type CA 'EAX'.
          lv_severity = 'E'.
          EXIT.
        ENDLOOP.
      ENDIF.

      IF lv_severity <> 'E'.
        COMMIT WORK AND WAIT.
        APPEND VALUE #( id = '00' type = 'S' number = '398' message = ls_input-huident && '修改成功' ) TO lt_bapiret.
      ELSE.
        APPEND LINES OF lt_bapiret2 TO lt_bapiret.
        APPEND VALUE #( id = '00' type = 'E' number = '398' message = ls_input-huident && '修改失败' ) TO lt_bapiret.
        ROLLBACK WORK.
      ENDIF.

      /scwm/cl_tm=>cleanup( iv_reason = /scmb/if_sp_transaction=>sc_cleanup_commit ).

    ENDIF.

  ENDLOOP.

  IF lt_bapiret IS NOT INITIAL.

    et_output[] = lt_bapiret[].

  ENDIF.


ENDFUNCTION.

以上是关于ABAP EWM 库存状态变更的主要内容,如果未能解决你的问题,请参考以下文章

ABAP EWM模拟 /SCWM/ADGI过账更改HU数量

ABAP EWM模拟 /SCWM/ADGI过账更改HU数量

ABAP EWM HU打包

ABAP EWM HU打包

ABAP EWM HU打包

ABAP EWM PRDI交货单过账