This sample shows how to create a goods receipt for a goods movement using the BAPI BAPI_GOODSMVT_CREATE.
About
The BAPI BAPI_GOODSMVT_CREATE requires multiple parameters to create a goods receipt for a goods movement. The export parameter GM_CODE of BAPI_GOODSMVT_CREATE represents the transaction code that would be used to post the movement as a dialog user. Values for GM_CODE include:
“01” is replaced by SAP with the transaction code MB01 that creates a goods receipt for purchase orders.
“02” is replaced by SAP with the transaction code MB31 for goods receipt for production orders.
"05" is replaced by SAP with the transaction code MB1C for other goods receipts.
Other export parameters for BAPI_GOODSMVT_CREATE include:
the Posting Date of the Document
the Username
the Document Date.
The table parameters for BAPI_GOODSMVT_CREATE include:
PLANT (Plant)
PO_NUMBER (Purchase Order Number)
PO_ITEM (Purchase Order Item)
ENTRY_QNT (Quantity)
MOVE_TYPE "101" is the Movement Type for the goods receipt for purchase order into warehouse/stores.
MVT_IND is the Movement Indicator that specifies the type of document that constitutes the basis for the movement.
STGE_LOC is the Storage Location for the goods.
Call BAPI_GOODSMVT_CREATE
The following code sample calls the BAPI BAPI_GOODSMVT_CREATE. If a goods receipt is successfully created the function returns the material document number and the year.
usingSystem;usingERPConnect;// Set your ERPConnect licenseLIC.SetLic("xxxx");usingvarconnection=newR3Connection(host:"server.acme.org",systemNumber:00,userName:"user",password:"passwd",language:"EN",client:"001"){Protocol=ClientProtocol.NWRFC,};connection.Open();publicboolGoodsReceipt101(stringPO_Number,stringPO_ITEM,stringPlant,decimalQuantity){stringrMessage;// Fill Export Structures for the FunctionModuleRFCFunctionfunc=connection.CreateFunction("BAPI_GOODSMVT_CREATE");func.Exports["GOODSMVT_HEADER"].ToStructure()["PSTNG_DATE"]="20070921";//Posting Date in the Documentfunc.Exports["GOODSMVT_HEADER"].ToStructure()["PR_UNAME"]="HUGO";//UserNamefunc.Exports["GOODSMVT_HEADER"].ToStructure()["HEADER_TXT"]="XXX";//HeaderTextfunc.Exports["GOODSMVT_HEADER"].ToStructure()["DOC_DATE"]="20070921";//Document Date in Documentfunc.Exports["GOODSMVT_CODE"].ToStructure()["GM_CODE"]="01";// Fill Table Items RFCStructureitemrow=func.Tables["GOODSMVT_ITEM"].Rows.Add();itemrow["PLANT"]=Plant;//Plantitemrow["PO_NUMBER"]=PO_Number;//Purchase Order Numberitemrow["PO_ITEM"]=PO_ITEM;//Item Number of Purchasing Document itemrow["ENTRY_QNT"]=Quantity;//Quantity in Unit of Entryitemrow["MOVE_TYPE"]="101";//Movement Typeitemrow["MVT_IND"]="B";//Movement Indicatoritemrow["STGE_LOC"]="0001";//Storage Location// Execute Function Modulefunc.Execute();RFCFunctionfuncCommit=connection.CreateFunction("BAPI_TRANSACTION_COMMIT");funcCommit.Exports["WAIT"].ParamValue="X";stringMaterialDocument=func.Imports["MATERIALDOCUMENT"].ParamValue.ToString();stringMatDocumentYear=func.Imports["MATDOCUMENTYEAR"].ParamValue.ToString();// Check Return-Tableif(func.Tables["RETURN"].RowCount>0){rMessage=func.Tables["RETURN"].Rows[0,"MESSAGE"].ToString();funcCommit.Execute();return!func.Tables["RETURN"].Rows[0,"TYPE"].ToString().Equals("E");}else{funcCommit.Execute();rMessage="";returntrue;}}