Create single Material Document with Multiple Equipment

SAP Materail Good Movement

The following is a sample ABAP code to Create single Material Document with Multiple Equipment.
If you have to move multiple Materials from Different Plant or Storage location with the same Movement Type, you have to create ONE Material Document for each Material/Plant/Storage Location.

Prepare Data


GM_CODE is very important. It defines the nature of Good Movement.

The full list for GM_CODE is:

Table Description
GM_CODETransaction Description
01 MB01Post Goods Receipt for PO
02 MB31Goods Receipt for Production Order
03 MB1AGoods Withdrawal
04 MB1BTransfer Posting
05 MB1COther Goods Receipts
06 MB11Goods Movement
07 MB04Subsequ.Adj.of Mat.ProvidedConsmp.

For example, if you want to transfer stock for a plant to an other, use 04 as GM_CODE for Transfer Posting.

Set Movement Type on Item level

Next, you have to set the movement type.
Here a link to the complete list of SAP Movement Types.

In the following ABAP Sample Code, we will be using 311 for?Transfer of storage location to storage location in one step.

Equipment / Serial Number Data

Once the header and the Items are set for Material Document, we have to set the equipment

Within a loop of equipment ( Serial Number), for each serial Number found for the material in the item, we add a new line to GOODSMV_SERIALNUMBER with the following data:

  • GOODSMV_SERIALNUMBER-matdoc_itm?=?1?
  • GOODSMV_SERIALNUMBER-serialno = “the serial number”

ABAP Simple Code


  goodsmvt_code-gm_code = '04'  . " Transfer Posting 

  " Set Header Line
  goodsmvt_header-pstng_date = sy-datum .
  goodsmvt_header-doc_date   = sy-datum.
  goodsmvt_header-header_txt = header_txt. "# a description as input 
  goodsmvt_header-pr_uname   = sy-uname . 

  " Set Item line 
  goodsmvt_item-material   = p_matnr .     
  goodsmvt_item-plant      = p_werks_out . 
  goodsmvt_item-stge_loc   = p_lgort_out.  
  goodsmvt_item-move_type  = '311' .
  goodsmvt_item-entry_qnt  = p_qty . "# Set your quantity
  goodsmvt_item-move_plant = p_werks_in.
  goodsmvt_item-move_stloc = p_lgort_in.
  goodsmvt_item-mvt_ind    = '' .
  append goodsmvt_item to goodsmvt_itemt.
  " set Equipement
  LOOP AT lt_serial into ls_serial.
     goodsmv_serialnumber-matdoc_itm = 1 .
     goodsmv_serialnumber-serialno = ls_serial-serialnr.
     append goodsmv_serialnumber to goodsmvt_serialnumber.
 " Call Good Movement Creation BAPI
 call function 'BAPI_GOODSMVT_CREATE'
        goodsmvt_header       = goodsmvt_header
        goodsmvt_code         = goodsmvt_code
        testrun               = p_testrun "# 'X' "testrun
        materialdocument         = materialdocument
        matdocumentyear          = matdocumentyear
        goodsmvt_item         = goodsmvt_itemt
        goodsmvt_serialnumber = goodsmvt_serialnumber
        return                = return.

  if return[] is initial and p_testrun EQ ' '.
    " commit Transaction
    call function 'BAPI_TRANSACTION_COMMIT'
        wait = 'X'.
    " Error -> Roll Back 
    call function 'BAPI_TRANSACTION_ROLLBACK'