Objectives: Logon To SAP From VB. Use of BAPI. Creation of Sales Order Using BAPI

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Note: To complete this exercise, you need Microsoft Visual Basic 5.0 or Later.

Objectives
By the end of this Exercise, you will be familiar to:

• Logon to SAP from VB.


• Use of BAPI.
• Creation of Sales Order Using BAPI.

Prerequisites
Before working on this exercise, you should be familiar with the following:

• Microsoft Visual Basic 5.0 or later


• Forms creation and Managing objects.

1. Start Visual Basic new project as


Standard EXE (as shown in
picture).

Customer Order Creation Using BAPI 1


Customer Order Creation Using BAPI
Seetharam

2. Select properties Window

Type property values as shown


below.

Property Value 2

Name frmCustomer
Caption Customer Order
Height 4425
Width 8520

3. Add a Text Box to form.

• Click on text box with right


mouse button.

• Choose Copy.

• Click on form with right mouse


3
button.

• Choose Paste.

• When it prompts Choose ‘Yes’


to create a control array. ( As
shown in Picture.)

• Create 10 more Text boxes by


Pasting them.

Customer Order Creation Using BAPI 2 of 9


Customer Order Creation Using BAPI
Seetharam

4. Place a label control before Text


box.
4
Change its Caption to ‘Doc. Type’

Repeat this step for all Text boxes.

5. Change the captions for label


controls as shown in picture.

Below are Captions for each lable.

Doc Type
Sales Org 5
Distribution Channel
Division
Date
PO Number
Partner Role
Partner Number
Req. Quantity
Material
Rate

Customer Order Creation Using BAPI 3 of 9


Customer Order Creation Using BAPI
Seetharam

6. Create Command buttons as shown


in Picture.

Change their Captions to

1. Create Order
2. Log Off

7. Copy following code to Form_Load () Event.

Text1(4) = Format(Now, "mm/dd/yyyy")


Set bapictrl = CreateObject("SAP.BAPI.1")
Set oconnection = bapictrl.connection
oconnection.logon

Set boOrder = bapictrl.getSapobject("SalesOrder")


Set oPartner = bapictrl.dimas(boOrder, "CreateFromData", "orderpartners")
Set oItemin = bapictrl.dimas(boOrder, "CreateFromData", "orderitemsin")
Set oheader = bapictrl.dimas(boOrder, "CreateFromData", "orderheaderin")

Customer Order Creation Using BAPI 4 of 9


Customer Order Creation Using BAPI
Seetharam

8. Copy following code to General


Declarations Section of the form.

Dim bapictrl As Object


Dim boOrder As Object
Dim oPartner As Object 8
Dim oItemin As Object
Dim oheader As Object
Dim oreturn As Object
Dim oconnection As Object

6. Copy the following code to Click event of the Command Button.

Dim x As String
oheader.Value("DOC_TYPE") = Text1(0)
oheader.Value("SALES_ORG") = Text1(1)
oheader.Value("DISTR_CHAN") = Text1(2)
oheader.Value("DIVISION") = Text1(3)
oheader.Value("PRICE_DATE") = Text1(4)
oheader.Value("PURCH_NO") = Text1(5)

oPartner.rows.Add
oPartner.Value(1, "PARTN_ROLE") = Text1(6)
oPartner.Value(1, "PARTN_NUMB") = Text1(7)

oItemin.rows.Add
oItemin.Value(1, "REQ_QTY") = Text1(8)
oItemin.Value(1, "MATERIAL") = Text1(9)
oItemin.Value(1, "COND_VALUE") = Text1(10)
boOrder.createfromdata orderheaderin:=oheader, orderitemsin:=oItemin,
orderpartners:=oPartner, return:=oreturn
x = oreturn.Value("message")
If x = "" Then
MsgBox "Transaction complete"
Else
MsgBox x
End If

Customer Order Creation Using BAPI 5 of 9


Customer Order Creation Using BAPI
Seetharam

9. Run the program

1. by hitting the Function key F5


2. by choosing Start menu item from 9
Run Menu

10. Provide Clint Id, User Id,


Password etc in relevent text
boxes..

Contact your system administrator for


the details.

10

Customer Order Creation Using BAPI 6 of 9


Customer Order Creation Using BAPI
Seetharam

11. Provide details for relevant fields


then click on Create Order
Command Button.

11

12. When you see the message


‘Transaction Complete’

12

Customer Order Creation Using BAPI 7 of 9


Customer Order Creation Using BAPI
Seetharam

Checking your Order:

To access the ‘Display Sales Order: Initial Screen’ choose path:

Logistics → Sales/Distribution → Sales → Order → Display

13. Click on Order.

13

14. You will be displayed Search


screen.
Enter the Purchase order no which
you have entered earlier (194 in 14
this case)

15. Hit enter or click on Choose Enter


button.

15
4

Customer Order Creation Using BAPI 8 of 9


Customer Order Creation Using BAPI
Seetharam

16. Order no will be displayed as


shown
Hit enter.

16
4

17. Standard Order Overview Screen


will be displayed with relevant
details.

Customer Order Creation Using BAPI 9 of 9

You might also like