函数使用十六:BAPI_GOODSMVT_CREATE

*&---------------------------------------------------------------------*
*& Report  ZBAPI_GOODSMVT_CREATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zbapi_goodsmvt_create.

DATA:gs_head TYPE bapi2017_gm_head_01,
       gv_code TYPE bapi2017_gm_code,
       gs_head_r TYPE bapi2017_gm_head_ret,
       gt_item TYPE TABLE OF bapi2017_gm_item_create,
       gw_item LIKE LINE OF gt_item,
       gt_return TYPE TABLE OF bapiret2,
       gw_return LIKE LINE OF gt_return,
       lv_line_id TYPE i.

"header data
gv_code = '01'."采购收货
gs_head-pstng_date = sy-datum."mkpf-bldat.
gs_head-doc_date = sy-datum."mkpf-budat.
gs_head-pr_uname = sy-uname.
gs_head-ref_doc_no = '4500011395'.


"item data
ADD 1 TO lv_line_id.
gw_item-line_id = lv_line_id.
gw_item-material = 'K300000'.
gw_item-plant  = '6375'.

gw_item-batch    = 'H'.
gw_item-vendor = '0000401210'.
gw_item-stge_loc = '4001'.

gw_item-move_type  = '101'.
gw_item-move_plant = '6375'.
gw_item-move_stloc = '4001'.
gw_item-po_number = '4500011395'.
gw_item-po_item = '10'.

gw_item-entry_qnt  = 2.  "结余数量.
gw_item-entry_uom = 'PC'.
**SELECT SINGLE meins INTO gw_item-entry_uom FROM mara WHERE matnr = s_item-zmodeno.
APPEND gw_item TO gt_item.



CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
  EXPORTING
    goodsmvt_header  = gs_head
    goodsmvt_code    = gv_code
  IMPORTING
    goodsmvt_headret = gs_head_r
  TABLES
    goodsmvt_item    = gt_item
    return           = gt_return.  "
IF gs_head_r-mat_doc IS NOT INITIAL.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.
  WRITE gs_head_r-mat_doc.
ELSE.
  READ TABLE gt_return INTO gw_return WITH KEY type = 'E'.
  IF sy-subrc = 0.
    WRITE: gw_return-message.
  ENDIF.
ENDIF.
.

 

上一篇:我为什么鼓吹thick client


下一篇:函数使用十三:BAPI_REQUISITION_CREATE