生产订单发退料和收货——BAPI_GOODSMVT_CREATE

 

发料:

DATA: lt_item   TYPE TABLE OF bapi2017_gm_item_create,
      lt_return TYPE TABLE OF bapiret2,
      ls_item   TYPE bapi2017_gm_item_create,
      ls_header TYPE bapi2017_gm_head_01,
      ls_code   TYPE bapi2017_gm_code,
      lv_mblnr  TYPE mblnr,
      lv_mjahr  TYPE mjahr.

ls_code = '03'. "T158G-GMCODE
ls_header-pstng_date = sy-datum.
ls_header-doc_date = sy-datum.

"发料
ls_item-move_type = '261'.
ls_item-material = 'MTBN-BDX010-A'. "RESB-MATNR
ls_item-entry_qnt = 1.              "RESB-BDMNG - RESB-ENMNG
ls_item-entry_uom = 'KG'.           "RESB-MEINS
ls_item-plant = '2000'.             "RESB-WERKS
ls_item-stge_loc = '211A'.          "RESB-LGORT
ls_item-reserv_no = '0000873063'.   "RESB-RSNUM
ls_item-res_item = '0002'.          "RSNUM-RSPOS
APPEND ls_item TO lt_item.CLEAR ls_item.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
  EXPORTING
    goodsmvt_header  = ls_header
    goodsmvt_code    = ls_code
  IMPORTING
*   goodsmvt_headret =
    materialdocument = lv_mblnr
    matdocumentyear  = lv_mjahr
  TABLES
    goodsmvt_item    = lt_item
    return           = lt_return.

READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.
  COMMIT WORK AND WAIT.
ELSE.
  ROLLBACK WORK.
ENDIF.

cl_demo_output=>write( lv_mblnr ).
cl_demo_output=>write( lv_mjahr ).
cl_demo_output=>write( lt_return ).
cl_demo_output=>display(  ).
View Code

退料:

DATA: lt_item   TYPE TABLE OF bapi2017_gm_item_create,
      lt_return TYPE TABLE OF bapiret2,
      ls_item   TYPE bapi2017_gm_item_create,
      ls_header TYPE bapi2017_gm_head_01,
      ls_code   TYPE bapi2017_gm_code,
      lv_mblnr  TYPE mblnr,
      lv_mjahr  TYPE mjahr.

ls_code = '03'. "T158G-GMCODE
ls_header-pstng_date = sy-datum.
ls_header-doc_date = sy-datum.

"退料
ls_item-move_type = '262'.
ls_item-xstob     ='X'. "冲销移动类型标识符
ls_item-material = 'MTBN-BDX010-A'.
ls_item-entry_qnt = 1.
ls_item-entry_uom = 'KG'.
ls_item-plant = '2000'.
ls_item-stge_loc = '211A'.
ls_item-reserv_no = '0000873063'.
ls_item-res_item = '0002'.
APPEND ls_item TO lt_item.CLEAR ls_item.


CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
  EXPORTING
    goodsmvt_header  = ls_header
    goodsmvt_code    = ls_code
  IMPORTING
*   goodsmvt_headret =
    materialdocument = lv_mblnr
    matdocumentyear  = lv_mjahr
  TABLES
    goodsmvt_item    = lt_item
    return           = lt_return.

READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.
  COMMIT WORK AND WAIT.
ELSE.
  ROLLBACK WORK.
ENDIF.

cl_demo_output=>write( lv_mblnr ).
cl_demo_output=>write( lv_mjahr ).
cl_demo_output=>write( lt_return ).
cl_demo_output=>display(  ).
View Code

副产品收货:

DATA: lt_item   TYPE TABLE OF bapi2017_gm_item_create,
      lt_return TYPE TABLE OF bapiret2,
      ls_item   TYPE bapi2017_gm_item_create,
      ls_header TYPE bapi2017_gm_head_01,
      ls_code   TYPE bapi2017_gm_code,
      lv_mblnr  TYPE mblnr,
      lv_mjahr  TYPE mjahr.

ls_code = '03'. "T158G-GMCODE
ls_header-pstng_date = sy-datum.
ls_header-doc_date = sy-datum.

"副产品收货
ls_item-move_type = '531'.
ls_item-material = 'MTBN-PGX002'.
ls_item-entry_qnt = 1.
ls_item-entry_uom = 'KG'.
ls_item-plant = '2000'.
ls_item-stge_loc = '211A'.
ls_item-reserv_no = '0000873063'.
ls_item-res_item = '0003'.
APPEND ls_item TO lt_item.CLEAR ls_item.


CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
  EXPORTING
    goodsmvt_header  = ls_header
    goodsmvt_code    = ls_code
  IMPORTING
*   goodsmvt_headret =
    materialdocument = lv_mblnr
    matdocumentyear  = lv_mjahr
  TABLES
    goodsmvt_item    = lt_item
    return           = lt_return.

READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.
  COMMIT WORK AND WAIT.
ELSE.
  ROLLBACK WORK.
ENDIF.

cl_demo_output=>write( lv_mblnr ).
cl_demo_output=>write( lv_mjahr ).
cl_demo_output=>write( lt_return ).
cl_demo_output=>display(  ).
View Code

RE副产品收货

DATA: lt_item   TYPE TABLE OF bapi2017_gm_item_create,
      lt_return TYPE TABLE OF bapiret2,
      ls_item   TYPE bapi2017_gm_item_create,
      ls_header TYPE bapi2017_gm_head_01,
      ls_code   TYPE bapi2017_gm_code,
      lv_mblnr  TYPE mblnr,
      lv_mjahr  TYPE mjahr.

ls_code = '03'. "T158G-GMCODE
ls_header-pstng_date = sy-datum.
ls_header-doc_date = sy-datum.

"RE副产品收货
ls_item-move_type = '532'.
ls_item-xstob     ='X'. "冲销移动类型标识符
ls_item-material = 'MTBN-PGX002'.
ls_item-entry_qnt = 1.
ls_item-entry_uom = 'KG'.
ls_item-plant = '2000'.
ls_item-stge_loc = '211A'.
ls_item-reserv_no = '0000873063'.
ls_item-res_item = '0003'.
APPEND ls_item TO lt_item.CLEAR ls_item.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
  EXPORTING
    goodsmvt_header  = ls_header
    goodsmvt_code    = ls_code
  IMPORTING
*   goodsmvt_headret =
    materialdocument = lv_mblnr
    matdocumentyear  = lv_mjahr
  TABLES
    goodsmvt_item    = lt_item
    return           = lt_return.

READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.
  COMMIT WORK AND WAIT.
ELSE.
  ROLLBACK WORK.
ENDIF.

cl_demo_output=>write( lv_mblnr ).
cl_demo_output=>write( lv_mjahr ).
cl_demo_output=>write( lt_return ).
cl_demo_output=>display(  ).
View Code

主产品和联产品收货

DATA: lt_item   TYPE TABLE OF bapi2017_gm_item_create,
      lt_return TYPE TABLE OF bapiret2,
      ls_item   TYPE bapi2017_gm_item_create,
      ls_header TYPE bapi2017_gm_head_01,
      ls_code   TYPE bapi2017_gm_code,
      lv_mblnr  TYPE mblnr,
      lv_mjahr  TYPE mjahr.

ls_code = '02'. "T158G-GMCODE
ls_header-pstng_date = sy-datum.
ls_header-doc_date = sy-datum.

"主产品和联产品收货
ls_item-move_type = '101'.
ls_item-material = 'CTYN0173-XX'.
ls_item-entry_qnt = 10.
ls_item-entry_uom = 'PCS'.
ls_item-plant = '2000'.
ls_item-stge_loc = '211A'.
ls_item-orderid = '000021009982'.
ls_item-order_itno = '0001'. "AFPO-POSNR
ls_item-mvt_ind = 'F'.
APPEND ls_item TO lt_item.CLEAR ls_item.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
  EXPORTING
    goodsmvt_header  = ls_header
    goodsmvt_code    = ls_code
  IMPORTING
*   goodsmvt_headret =
    materialdocument = lv_mblnr
    matdocumentyear  = lv_mjahr
  TABLES
    goodsmvt_item    = lt_item
    return           = lt_return.

READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.
  COMMIT WORK AND WAIT.
ELSE.
  ROLLBACK WORK.
ENDIF.

cl_demo_output=>write( lv_mblnr ).
cl_demo_output=>write( lv_mjahr ).
cl_demo_output=>write( lt_return ).
cl_demo_output=>display(  ).
View Code

RE主产品和联产品收货(仅RE未限制使用库存,RE FQC库存应该使用BAPI_GOODSMVT_CREATE来整笔冲销)

DATA: lt_item   TYPE TABLE OF bapi2017_gm_item_create,
      lt_return TYPE TABLE OF bapiret2,
      ls_item   TYPE bapi2017_gm_item_create,
      ls_header TYPE bapi2017_gm_head_01,
      ls_code   TYPE bapi2017_gm_code,
      lv_mblnr  TYPE mblnr,
      lv_mjahr  TYPE mjahr.

ls_code = '02'. "T158G-GMCODE
ls_header-pstng_date = sy-datum.
ls_header-doc_date = sy-datum.

"RE主产品和联产品收货
ls_item-move_type = '102'.
ls_item-material = 'CTYN0173-XX'.
ls_item-entry_qnt = 1.
ls_item-entry_uom = 'PCS'.
ls_item-plant = '2000'.
ls_item-stge_loc = '211A'.
ls_item-orderid = '000021009982'.
ls_item-order_itno = '0001'. "AFPO-POSNR
ls_item-mvt_ind = 'F'.
APPEND ls_item TO lt_item.CLEAR ls_item.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
  EXPORTING
    goodsmvt_header  = ls_header
    goodsmvt_code    = ls_code
  IMPORTING
*   goodsmvt_headret =
    materialdocument = lv_mblnr
    matdocumentyear  = lv_mjahr
  TABLES
    goodsmvt_item    = lt_item
    return           = lt_return.

READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.
  COMMIT WORK AND WAIT.
ELSE.
  ROLLBACK WORK.
ENDIF.

cl_demo_output=>write( lv_mblnr ).
cl_demo_output=>write( lv_mjahr ).
cl_demo_output=>write( lt_return ).
cl_demo_output=>display(  ).
View Code

 

posted @ 2021-03-27 14:17  鲸与海  阅读(1855)  评论(0编辑  收藏  举报