SAP Good Movement BAPI: SAP MM-IM offers a package of SAP Good Movement BAPIs to read, update or create Material Document.
Usually, the relative SAP Good Movement BAPI for Good Movement start with BAPI_GOODSMVT_*.
Table of Contents
SAP Good Movement BAPI : Create
Let’s start with SAP Good Movement BAPI to create a Material Document.
The BAPI to consider is BAPI_GOODSMVT_CREATE. This BAPI will post goods movements.
Within BAPI_GOODSMVT_CREATE there is a call to the standard function module MB_CREATE_GOODS_MOVEMENT which generate the SAP Material Doument.
BAPI_GOODSMVT_CREATE Sample ABAP Code
Here ABAP code showing how to create in ABAP program a SAP Material Document with the Standard BAPI_GOODSMVT_CREATE.
PS: This code is not mine, check the source here. You can use as a template for your ABAP Program using this SAP BAPI.
* Structures for BAPI data: gm_header type bapi2017_gm_head_01, gm_code type bapi2017_gm_code, gm_headret type bapi2017_gm_head_ret, gm_item type table of bapi2017_gm_item_create with header line. data: gm_return type bapiret2 occurs 0. data: gm_retmtd type bapi2017_gm_head_ret-mat_doc. clear: gm_return, gm_retmtd. refresh gm_return. * Setup BAPI header data. gm_header-pstng_date = sy-datum. gm_header-doc_date = sy-datum. gm_code-gm_code = '06'. " MB11 * Write 551 movement to table clear gm_item. move: '551' to gm_item-move_type , '000000000040001234' to gm_item-material, '1' to gm_item-entry_qnt, 'EA' to gm_item-entry_uom, '0004' to gm_item-plant, '4000' to gm_item-stge_loc, '201' to gm_item-move_reas. * Determine cost center per plant case xresb-werks. when '0004'. move '0000041430' to gm_item-costcenter. when '0006'. move '0000041630' to gm_item-costcenter. when '0007'. move '0000041731' to gm_item-costcenter. when '0008'. move '0000041830' to gm_item-costcenter. endcase. append gm_item. * Call goods movement BAPI call function 'BAPI_GOODSMVT_CREATE' exporting goodsmvt_header = gm_header goodsmvt_code = gm_code importing goodsmvt_headret = gm_headret materialdocument = gm_retmtd tables goodsmvt_item = gm_item return = gm_return. call function 'BAPI_TRANSACTION_COMMIT' exporting wait = 'X'.
You can find an other sample ABAP program reading a file and creating SAP Material Document for each line of the file here.
Create a Material Document with Equipment ( Serial number )
A common business case (for example in SAP PM Plant Management or SAP QM for Quality Management), you may have to create document material in SAP not for the material itself but for Equipment.
Actually, SAP Equipment is identified both by :
- Material Number
- Serial Number
Check more on SAP PM Equipment Creation Explained – General Data (1)
The same SAP BAPI situed above BAPI_GOODSMVT_CREATE can make the job.
You have just to fill the table GOODSMVT_SERIALNUMBER with list of Equipments.
Find an ABAP Code Sample to create a Material Document with multiple equipment for a material
(Create single Material Document with Multiple Equipment)
Read more about
- SAP Good Movement IDoc (MBGMCR03) : Structure and BAPI
- SAP Good Movement Types
- Goods Movement Tables in SAP
- Goods Movement Transaction codes in SAP
Cancel Good Movement BAPI
In order to reverse Goods Movements, use the standard BAPI BAPI_GOODSMVT_CANCEL.
SAP BAPI will call in its processing the fm MB_CANCEL_GOODS_MOVEMENT responsible to cancelling an existing SAP Good Movement.
You can cancel the whole Good Movement as you can partially can the Material Document.
You have to set some additional information as:
- GOODSMVT_PSTNG_DATA: Posting date
- GOODSMVT_PR_UNAME: User Name for Printing Goods Receipt/Issue Slip
Don’t forget to call a ‘BAPI_TRANSACTION_COMMIT’ to commit modification to Database.
Read SAP Good Movement BAPI
BAPI_GOODSMVT_GETDETAIL
The BAPI BAPI_GOODSMVT_GETDETAIL will display Details for Material Document.
It is very helpful if you want to get a quick overview ( in ABAP ) of the Material Document.
The input are:
- MATERIALDOCUMENT- Material Document Number
- MATDOCUMENTYEAR – Material Document Year
and The output are:
- GOODSMVT_HEADER – Material Document Header
- BAPI_GOODSMVT_GETITEMS Display Detailed List of Material Documents
- GOODSMVT_ITEMS – Material Document Items
BAPI_GOODSMVT_GETITEMS
The BAPI BAPI_GOODSMVT_GETITEMS will display a detailed List of Material Documents.
This BAPI are more Search BAPI. Acutally in input you can fill tables with range of value for
- Range for Material
- Plant Ranges
- Range for Stor. Loc.
- Range for Batch
- Mvt Type Ranges
- Range for Special Stock Indicator
- Trans./Event Type Range
- Range for Posting Date
- Vendor Range
- Range for User Name
- Range for Purchasing Document
And the Return of the BAPI_GOODSMVT_GETITEMS are two tables with the list of :
- GOODSMVT_HEADER – Table for Material Document Header
- GOODSMVT_ITEMS – Table for Materail Document Item