cancel
Showing results for 
Search instead for 
Did you mean: 

Sample code needed to call BAPI from VB

Former Member
0 Kudos

hi friends, i need to call the "OrderMaintain" method in the "MaintenanceOrderBAPI" BAPI. This i need to do it in order to create an Order via VB. Could anyone of you help me in this regard. Kindly send me the WORKING sample code and the list of dll's or ocx's to be included.

Regards Kranthi.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi

This example illustrates a BAPI call in Visual Basic using the BAPI ActiveX Control. This report uses the service BAPI BapiService.MessageGetDetail(), to display the short text and the long text of error messages.

'

' Visual BASIC 5.0

' Copyright SAP AG Walldorf Juli 1998

'

' read a message short and longtext using the BAPI

' BAPI_MESSAGE_GETDETAIL of the object BapiService

' constant for user identification

Const cstrMUsrClient As String = "000"

Const cstrMUsrUser As String = "MYUSER"

Const cstrMUsrPassword As String = "MYPASS"

Const cstrMUsrLanguage As String = "EN"

' constant for system identification

Const cstrMSysSystem As String = "P45"

Const cstrMSysMessageServer As String = "p45main.wdf.sap-ag.de"

Const cstrMSysGroupName As String = "PUBLIC"

'

' constant values for reading message texts

Const cstrMMsgId As String = "SX"

Const cstrMMsgNumber As String = "101"

Const cstrMMsgVariable1 As String = "var1"

Const cstrMMsgVariable2 As String = "var2"

Const cstrMMsgVariable3 As String = "var3"

Const cstrMMsgVariable4 As String = "var4"

Const cstrMMsgLanguage As String = "DE"

' other constant

Const cstrMPathfile As String = "D:\A\saptext.rtf"

' password for login in R/3

Dim strMUsrPassword As String

' react on button START

Private Sub cmdMsgStart_Click()

' define object for BAPI ActiveX control

Dim oBAPICtrl As Object

' define object for R/3 logon control

Dim oLogonCtrl As Object

' business object BapiService

Dim boBapiSercice As Object

' for BAPI: BapiService.MessageGetDetail

Dim oMsgReturn As Object

Dim oMsgText As Object

Dim intCounter As Integer

' to open the file you need a file channel

Dim intChannel As Integer

' create BAPI ActiveX control object

Set oBAPICtrl = CreateObject("SAP.BAPI.1")

' create R/3 logon control object

Set oLogonCtrl = CreateObject("SAP.Logoncontrol.1")

' connection object is part of the BAPI ActiveX Control object

Set oBAPICtrl.Connection = oLogonCtrl.NewConnection

' fill logon parameters for system to use

oBAPICtrl.Connection.System = txtSysSystem

oBAPICtrl.Connection.MessageServer = txtSysMessageServer

oBAPICtrl.Connection.GroupName = txtSysGroupName

' fill logon parameter for user

oBAPICtrl.Connection.Client = txtUsrClient

oBAPICtrl.Connection.User = txtUsrUser

oBAPICtrl.Connection.Password = strMUsrPassword

oBAPICtrl.Connection.Language = txtUsrLanguage

' user logon to R/3

If oBAPICtrl.Connection.Logon(frmStart.hWnd, False) = False Then

MsgBox "R/3 connection failed"

End

End If

' create BAPI service object

Set boBapiService = oBAPICtrl.GetSAPObject("BapiService")

' call method of BapiService

boBapiService.MessageGetDetail id:=txtMsgId, _

Number:=txtMsgNumber, _

Language:=txtMsgLanguage, _

Textformat:=cboMsgTextformat.Text, _

message:=strMsgShorttext, _

Return:=oMsgReturn, _

Text:=oMsgText

' fill field in form

' If txtMsgShorttext = "" Then

' MsgBox "No message read"

' End If

' user logoff from R/3

oBAPICtrl.Connection.Logoff

' error handling check if RETURN parameter is not empty and react

If oMsgReturn.Value("TYPE") <> "" Then

lblReturn.Caption = oMsgReturn.Value("TYPE") + _

". " + _

oMsgReturn.Value("ID") + _

". " + _

oMsgReturn.Value("NUMBER") + _

". " + _

oMsgReturn.Value("MESSAGE") + _

". " + _

oMsgReturn.Value("MESSAGE_V1") + _

". " + _

oMsgReturn.Value("MESSAGE_V2") + _

". " + _

oMsgReturn.Value("MESSAGE_V3") + _

". " + _

oMsgReturn.Value("MESSAGE_V4") + _

". " + _

oMsgReturn.Value("LOG_NO") + _

". " + _

oMsgReturn.Value("LOG_MSG_NO")

Else

' fill form fields

txtMsgShorttext = strMsgShorttext

arrayText = oMsgText.Data

' handling of non RTF texts

If cboMsgTextformat.Text <> "RTF" Then

For intCounter = 1 To oMsgText.RowCount

If intCounter = 1 Then

rtfMsgLongtext.Text = arrayText(intCounter, 1)

Else

rtfMsgLongtext.Text = rtfMsgLongtext.Text + _

Chr(13) + Chr(10) + _

arrayText(intCounter, 1)

End If

Next intCounter

End If

' handling of RTF texts

If cboMsgTextformat.Text = "RTF" Then

' save text as rtf file

intChannel = FreeFile

Open cstrMPathfile For Output As #intChannel

For intCounter = 1 To oMsgText.RowCount

Print #intChannel, arrayText(intCounter, 1)

Next intCounter

Close #intChannel

rtfMsgLongtext.LoadFile cstrMPathfile, rtfRTF

End If

End If

End Sub

This is taken from help.sap.com

For Details check this link....

http://help.sap.com/saphelp_46c/helpdata/en/76/4a42f7f16d11d1ad15080009b0fb56/frameset.htm

There are few other links which can be helpful in this case.....

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndcom/html/sapintegration.asp

http://www.erphome.net/pdf/tech/J07.pdf

http://www.sapgenie.com/interfaces/

Have a nice time ahead

Mithlesh Kumar Jha

Former Member
0 Kudos

<head>

<title>Details</title>

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

</head>

<body>

<center>

<font face="arial" size="1"><b>Details</b></font>

<BR>

<%

Set objFunctions = Server.CreateObject("SAP.Functions")

objFunctions.Connection.User = "USERID"

objFunctions.Connection.Client = "010"

objFunctions.Connection.Language = "EN"

objFunctions.Connection.ApplicationServer = "1.2.3.4"

objFunctions.Connection.Password = "PWD"

If objFunctions.Connection.Logon(0, True) <> True Then

Response.Write "Cannot logon!"

End If

Dim objFuncUpload , notetable

t=Request.QueryString("location")

Set objFuncUpload = objFunctions.Add("Z_BAPI_GET_ORDERS")

objFuncUpload.Exports("FUNCTIONAL_LOCATION") = t

If objFuncUpload.Call = True Then

Set notetable = objFuncUpload.Tables("NOTIFICATIONLIST")

If notetable.rowcount = 0 Then

Response.Write "No records available"

End If

Else

Response.Write objFuncUpload.Exception

End If

%>

<p align=center>

<font face="arial" size="1">

<table cellpadding = "3" cellspacing="3">

<tr><td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

<td><font face="arial" size="1">Notification Number</td>

<td><font face="arial" size="1"> Priority </td>

<td><font face="arial" size="1"> Start Date </td>

<td> <font face="arial" size="1">Contact Person </td>

</tr>

</table>

<table Cellspacing = "8">

<%

Response.write "<form name=a method=GET action=ServiceOrd.asp> "

Dim notes,pri

if notetable.rowcount > 4 then

loopcount = 4

else

loopcount = notetable.rowcount

end if

For i = 0 To loopcount-1 ' Restricting display to 11 entries

notes = notetable(i + 1, "notificationno")

pri = notetable(i + 1, "priority")

%>

<tr><Td><input type=radio name="notification" value="<%=notes%>"></td>

<%

Response.Write "<td><font face=arial size=1>"&notes&"</td>"

Response.Write "</input>"

Response.Write "<td><font face=arial size=1>"&pri&"</td>"

Response.Write "<td align=right><font face=arial size=1>"&notetable(i + 1, "startdate")&"</td>"

Response.Write "<td><font face=arial size=1>"&notetable(i + 1, "contactperson")&"</td></tr>"

Next

Response.Write "</table> "

if notetable.rowcount <> 0 Then

Response.Write "<br/><input type=submit value=Submit> "

Response.Write "</form>"

End If

%>

</p>

</font>

<br>

<font face ="verdana" size="1">All Rights Reserved Intelligroup Asia</font>

</center>

</body>

gregorw
Active Contributor
0 Kudos

Hello Kranthi,

have you tried Google with "sap vb example"? I've found <a href="http://www.sap-img.com/abap/vb-codes-or-vba-macro-code-for-access-sap-and-run-one-rfc.htm">Vb codes (or VBA macro code) for access SAP, and run one RFC</a>.

Regards

Gregor

Former Member
0 Kudos

Hello Gregor,

Thank you for your quick assistance. But let me put out my requirements more elaborately. The sample code that i am getting in google and stuff contains chunks of code that lets me connect to SAP. In that code, we can pass the parameters directly by value. for eg.

oCompanyCode.GetList CompanyCode:="0001",return:=oReturn

But my requirement is such that i need to pass a header that contains all the relevant details to create an Order. When i explored calling the BAPI via an ABAP program, i observed that two headers are being created. One that has the actual data and the second one is being suffixed with "up" and the constant "X" is being passed to it. So kindly give me help on how to call a method in a BAPI that takes headers instead of values as input. You can see the "OrderMaintain" method in "MaintenanceOrderBAPI" has this type of behavior.

Regards,

Kranthi.

athavanraja
Active Contributor
0 Kudos

check the following threads

Regards

Raja

Former Member
0 Kudos

Hello Raja,

It would be really good if you could send some sample program in VB that creates an Order in SAP by calling the "MaintenanceOrderBAPI".

Regards,

Kranthi.