Login Form

Best viewed in IE 7.0

ADVERTISEMENTS
ADVERTISEMENT

ASP.NET Eg: Creating a Purchase Order via BAPI

Using ERPConnect in a Web Application

Of course, ERPConnect is ready for ASP.NET so you will be able to write really cool web applications with a direct link to SAP R/3.

The following example shows the development process for the ASP.NET/ERPConnect project.

The ERPConnect.dll class library must be added as a reference to the project. The dll will be copied to the bin directory when compiling the project. But you need to add one more dll to your bin directory: librfc32.dll. This one is contained in the rfcsdk provided by the SAP GUI installation (System32 directory).

Attention! The trial version of ERPConnect does not work in a web environment. Please apply for a limited test licence number if you want to use ERPConnect with your ASP.NET project ( This email address is being protected from spambots. You need JavaScript enabled to view it. ). [ Download Sample Project ASPCreatePurchaseOrder.zip  ]

ASP.NET Example: Creating a Purchase Order via BAPI

The example below is based on an ASP page that contains several textboxes for the vendor number (txtVendor), the material number (txtMaterial), the quantity (txtQuan), and the plant the vendor should deliver the material to (txtPlant).

Place the following code into the button click event. First of all, we need to establish a con-nection to the SAP system and create a BusinessObjectMethod object (we want to create a purchase order, therefore we have to use the BAPI PuchaseOrder.CreateFromData).



[C#]

private void Button1_Click(object sender, System.EventArgs e)
{
   R3Connection con = new R3Connection("hamlet",11,"Theobald","pw","EN","800");

 ERPConnect.LIC.SetLic("TempLicNumber");

 con.Open(false);

 // Create a BAPI object
 ERPConnect.BusinessObjectMethod  bapi = con.CreateBapi("PurchaseOrder","CreateFromData");


The structure PO_HEADER has to be filled in with the following values:
DOC_TYPE -> Order type (NB normal order)
PURCH_ORG -> Purchasing organization
PUR_GROUP -> Purchasing group
DOC_DATE -> Date
VENDOR -> Vendor number

[C#]

 // Fill header structure
 RFCStructure Header = bapi.Exports["PO_HEADER"].ToStructure();
 Header["DOC_TYPE"]= "NB";
 Header["PURCH_ORG"] = "1000";
 Header["PUR_GROUP"] = "010";
 Header["DOC_DATE"]= ERPConnect.ConversionUtils.NetDate2SAPDate(DateTime.Now);
 Header["VENDOR"]= this.txtVendor.Text

Now the items have to be defined (table PO_ITEMS). All we need is the plant (PLANT) and the material number (PUR_MAT).
The values for the quantity (QUANTITY) and the delivery date (DELIV_DATE) must be placed in the table PO_ITEM_SHEDULES.


[C#]

 // Create an Item
 RFCTable items = bapi.Tables["PO_ITEMS"];
 RFCStructure item = items.AddRow();
 item["PO_ITEM"] = "1";
 item["PUR_MAT"] = this.txtMaterial.Text;
 item["PLANT"] = this.txtPlant.Text;

 // Create and fill shedules
 RFCTable shedules = bapi.Tables["PO_ITEM_SCHEDULES"];
 RFCStructure shedule = shedules.AddRow();
 shedule["PO_ITEM"] = "1";
 shedule["DELIV_DATE"] = ERPConnect.ConversionUtils.NetDate2SAPDate(DateTime.Now);
 shedule["QUANTITY"] = Convert.ToDecimal(this.txtQuan.Text);


Now we can execute the BAPI and process the return messages.

[C#]

 // Exceute Bapi and process return messages
 bapi.Execute();
 this.txtReturn.Text = "";
 foreach(BapiReturn ret in bapi.Returns)
  this.txtReturn.Text += ret.Message + "\r\n";
}



The screenshots below show the ASP page and the created purchase order.



ADVERTISEMENT
Free software downloads