Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Sap Netweaver & BAPI

Former Member
0 Kudos

Hi friends,

I am not much familiar with BAPI's, but my company uses BAPI's for two Business processes.

with uprgarde to Sap Netweaver coming in near future I am bit concerned about how handle BAPI calls to Sap from VB.

please give your suggestions.

regards

2 REPLIES 2

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

What is the concern? They should still work. You may need to do a little tweaky.

Regards,

Rich HEilman

Former Member
0 Kudos

see below example code calling a bapi from sap

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

And also see below link which will help you linking vb with sap using DCOM

http://help.sap.com/saphelp_webas610/helpdata/en/09/6b320f419311d2952000a0c94260a5/content.htm