API_GOODSMVT_CREATE
物料移动,比如MB1B
'343' "unblock
'344' "block
参考代码
*&BAPI
DATA: goodsmvt_header LIKE bapi2017_gm_head_01,
goodsmvt_code LIKE bapi2017_gm_code.
DATA: goodsmvt_headret LIKE bapi2017_gm_head_ret,
materialdocument TYPE bapi2017_gm_head_ret-mat_doc,
matdocumentyear TYPE bapi2017_gm_head_ret-doc_year.
DATA:goodsmvt_item LIKE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
goodsmvt_serialnumber LIKE TABLE OF bapi2017_gm_serialnumber WITH HEADER LINE,
return LIKE TABLE OF bapiret2 WITH HEADER LINE.
FIELD-SYMBOLS LIKE LINE OF goodsmvt_item.
DATA:lv_item_line TYPE int4.
CHECK it_data[] IS NOT INITIAL.
*抬头部分给值:
CLEAR: goodsmvt_item[],goodsmvt_header.
REFRESH: goodsmvt_item.
goodsmvt_header-pstng_date = sy-datum.
goodsmvt_header-doc_date = sy-datum.
goodsmvt_header-pr_uname = sy-uname.
goodsmvt_code = '04'.
*行项目部分给值
LOOP AT it_data INTO ls_data .
goodsmvt_item-material = ls_data-matnr.
goodsmvt_item-plant = ls_data-werks.
goodsmvt_item-stge_loc = ls_data-lgort.
goodsmvt_item-move_type = iv_move_type.
goodsmvt_item-move_plant = ls_data-werks.
goodsmvt_item-move_stloc = ls_data-lgort.
goodsmvt_item-entry_qnt = 1. " only 1
READ TABLE goodsmvt_item ASSIGNING <ls_item>
WITH KEY material = ls_data-matnr
plant = ls_data-werks
stge_loc = ls_data-lgort
move_type = iv_move_type
move_plant = ls_data-werks
move_stloc = ls_data-lgort.
IF sy-subrc = 0.
<ls_item>-entry_qnt = <ls_item>-entry_qnt + 1.
ELSE.
APPEND goodsmvt_item.
ENDIF.
DESCRIBE TABLE goodsmvt_item LINES lv_item_line.
goodsmvt_serialnumber-matdoc_itm = lv_item_line.
goodsmvt_serialnumber-serialno = ls_data-sernr.
APPEND goodsmvt_serialnumber.
**********
Call bapi
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = goodsmvt_header
goodsmvt_code = '04' "#EC * "goodsmvt_code mb1b
IMPORTING
materialdocument = materialdocument
matdocumentyear = matdocumentyear
TABLES
goodsmvt_item = goodsmvt_item[]
goodsmvt_serialnumber = goodsmvt_serialnumber
return = return[].
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
READ TABLE return WITH KEY type = 'E'.
IF sy-subrc = 0.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = return-id
msgnr = return-number
msgv1 = return-message_v1
msgv2 = return-message_v2
msgv3 = return-message_v3
msgv4 = return-message_v4
IMPORTING
message_text_output = lv_msg.
ELSE.
lv_mblnr = materialdocument.
ENDIF.