Skip to Content
Author's profile photo Venkateswaran (Venkat) Krishnamurthy

Goods Movement Transaction – BAPI


At the time of implementation, we need to upload large amount master data and transactional data in the MM Module. For Example to Upload the initial stock.  Secondly there may be a situation that we need to upload a large amount of Goods Movement transaction.  In order to achieve that we can use the following BAPI.   This document explains the steps to arrange the data and upload in the system using BAPI.

This document will provide a guideline with respect to your requirement.  Use this BAPI template for all types of Goods movement transaction by Changing appropriate movement indicator, GMcode of header information of BAPI and execute it.


Arrange the Data in the following format. Preferably in the Excel format

Ths is a comprehensive list of data.  You can use the relevent fields based on your movement type. But do not change the sequence.

External Document Number – Any reference document number you need to maintain

  • Movement Type   – Movement type viz 561 311 etc
  • Plant    – plant code
  • Material Number   – Material code
  • Quantity   – Quantity
  • Issuing Location  – From Storage location
  • Receiving Location  – Receiving Storage location
  • Purchase Document No  – PO document
  • Purchase Document Item No – PO item number
    Delivery Purchase Order Number – Delivery document no
  • Delivery Item   – Delivery item no
  • Production Document No  – Production doc no
  • Scrap Reason   – Reason code
  • Document Date   – Document date on which you post it
  • Posting Date   – Posting date

Header level flags

There are some header level flags for BAPI we set based on the movement type we execute.

GMCODE Table T158G –  01 – MB01 – Goods Receipts for Purchase Order
                      02 – MB31 – Goods Receipts for Prod Order
                      03 – MB1A – Goods Issue
                      04 – MB1B – Transfer Posting
                      05 – MB1C – Enter Other Goods Receipt
                      06 – MB11

Movement Indicator

       Goods movement w/o reference
  B – Goods movement for purchase order
  F – Goods movement for production order
  L – Goods movement for delivery note
  K – Goods movement for kanban requirement (WM – internal only)
  O – Subsequent adjustment of “material-provided” consumption
  W – Subsequent adjustment of proportion/product unit material

BAPI – Details

Header Data : Header, Code
Item Details  : Internal table that contain material details that we fetch from Excelsheet

Technical details

Now we see the technical details for writing this BAPI Execution code

Data Defention

parameters: p-file like ibipparms-path default ‘c:\datasource\MB1C.xls’.
data: begin of gmhead.
         include structure bapi2017_gm_head_01.
data: end of gmhead.

data: begin of gmcode.
         include structure bapi2017_gm_code.
data: end of gmcode.

data: begin of mthead.
         include structure bapi2017_gm_head_ret.
data: end of mthead.

data: begin of itab occurs 100.
         include structure bapi2017_gm_item_create.

data: begin of itemtab occurs 100,

         ext_doc(10),           “External Document Number

         mvt_type(3),           “Movement Type

         plant(4),              “Plant

         material(18),          “Material Number

         qty(13),               “Quantity

         issue_loc(4),          “Issuing Location

         recv_loc(4),           “Receiving Location

         pur_doc(10),           “Purchase Document No

         po_item(3),            “Purchase Document Item No

         del_no(10),            “Delivery Purchase Order Number

         del_item(3),           “Delivery Item

         prod_doc(10),          “Production Document No

         scrap_reason(10),      “Scrap Reason

         doc_date(8),           “Document Date

         post_date(8),          “Posting Date

       end of itemtab.

Read Data

Read data from Excel and store in Internal table

  DATA: loc_filename TYPE rlgrap-filename. “string.
  DATA: it_raw TYPE truxs_t_text_data.
  loc_filename = p-file.
      i_line_header        = ‘X’
      i_tab_raw_data       = it_raw       
      i_filename           = loc_filename
      i_tab_converted_data = pcitab           
      conversion_failed    = 1
      OTHERS               = 2.

endform.                    ” UPLOAD_DATA

Set Header information

gmhead-pstng_date = sy-datum. “you can change it from the data you read from excl
gmhead-doc_date = sy-datum.
gmhead-pr_uname = sy-uname.
gmcode-gm_code = ’04’.   “04 – MB1B – Transfer Posting

Set Item Details

loop at itemtab.
  itab-move_type  = itemtab-mvt_type.
  itab-mvt_ind    = ”.
  itab-plant      = itemtab-plant.
  itab-material   = itemtab-material.
  itab-entry_qnt  = itemtab-qty.
  itab-move_stloc = itemtab-recv_loc.
  itab-stge_loc   = itemtab-issue_loc.
  itab-po_number  = itemtab-pur_doc.
  itab-po_item    = itemtab-po_item.
  itab-move_reas  = itemtab-scrap_reason.

  append itab.

Now Call BAPI

call function ‘BAPI_GOODSMVT_CREATE’
    goodsmvt_header             = gmhead
    goodsmvt_code               = gmcode
*   TESTRUN                     = ‘ ‘
    goodsmvt_headret            = mthead
*   MATERIALDOCUMENT            =
*   MATDOCUMENTYEAR             =
    goodsmvt_item               = itab
    return                      = errmsg.

Display errors if any

clear errflag.
loop at errmsg.
  if errmsg-type eq ‘E’.
    write:/’Error in function’, errmsg-message.
    errflag = ‘X’.
    write:/ errmsg-message.

You can use this BAPI template for Goods movement by setting appropriate header flags.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.