Creating Purchase Order through BAPI using VB

Creating Purchase Order through BAPI using VB

The following code gives the code for creating Purchase Order in the SAP using BAPI_PO_CREATE RFC Function from Visual Basic. This code will give you the correct picture of how can you create a purchase order with one item. You can use a table control to add more items. The code was written in v.4.6.


Option Explicit
Dim functionCtrl As Object
Dim sapConnection As Object
Dim theFunc As Object
Dim PoNumber

Private Sub Command1_Click()

Set functionCtrl = CreateObject("SAP.Functions")
Set sapConnection = functionCtrl.Connection
sapConnection.Client = "500"
sapConnection.user = "USERNAME"
sapConnection.password = "PASSWORD"
sapConnection.Language = "EN"
If sapConnection.logon(0, False) <> True Then
    MsgBox "No connection to R/3 System"
    Exit Sub                                           'End program
End If
Set theFunc = functionCtrl.Add("BAPI_PO_CREATE")


Dim poheader As Object
Dim poitems As Object
Dim poitemschedule As Object
Dim retMess As Object
Dim returnFunc As Boolean
Dim startzeil As Integer
Dim endcol As Integer
Dim the_name As String

Set poheader = theFunc.exports.Item("PO_HEADER")
Set poitems = theFunc.tables.Item("PO_ITEMS")
Set poitemschedule = theFunc.tables.Item("PO_ITEM_SCHEDULES")

poheader.Value("VENDOR") = Text1.Text 
poheader.Value("PURCH_ORG") = Text2.Text 
poheader.Value("PUR_GROUP") = Text3.Text 
poheader.Value("DOC_TYPE") = Text4.Text  

poitems.Rows.Add
poitems.Value(1, "PUR_MAT") = Text5.Text 
poitems.Value(1, "PLANT") = Text6.Text

    Requires Free Membership to View

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

poitems.Value(1, "NET_PRICE") = Text7.Text poitemschedule.Rows.Add poitemschedule.Value(1, "DELIV_DATE") = Text8.Text poitemschedule.Value(1, "QUANTITY") = Text9.Text returnFunc = theFunc.call PoNumber = theFunc.imports("PURCHASEORDER") Set retMess = theFunc.tables.Item("RETURN") If retMess Is Nothing Then MsgBox retMess.Value(1, "MESSAGE") Else MsgBox "Purchase Order No : " & PoNumber & "Created" End If End Sub

This was first published in July 2002

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.