cancel
Showing results for 
Search instead for 
Did you mean: 

Using current connection/session to use object "SAP.Functions"

Former Member
0 Kudos

Hi all,

I have planning layout (SAP SEM-BPS 3.5, SAP GUI Excel In Place). I have to call remote function (functional module from BW server side). Mentioned function reads some data from table and returns ones to Excel.

To do one I use object "SAP.Functions"

Dim funct, conn, LogonControl

Set funct = CreateObject("SAP.Functions")

This object requires connection to BW

Set LogonControl = CreateObject("SAP.LogonControl.1")

Set conn = LogonControl.NewConnection

If conn.Logon(0, True) Then ...

funct.Connection = conn

So, I create new connection and new session.

Is there any way to use existing connection/session to use one within "SAP.Functions" object?

Thanks in advance,

Dmitry

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

I think you should use:

Set SapGuiAuto = GetObject("SAPGUI")

So for example:

Function Attach
	Dim GuiAuto
	On Error Resume Next
	Set GuiAuto = GetObject("SAPGUI")
	On Error Goto 0

	If GuiAuto Is Nothing THEN
		Msgbox "Please start SAPlogon"
		Set Attach = Nothing
		Exit Function
	Else
	...you code...

	End If
End Function

It works for me.

Regards,

EK

Edited by: Erkan Kopuz on Feb 7, 2008 10:03 AM

Former Member
0 Kudos

Hello,

I get connection by proposed way. But, when I try to use this connection

E.G.

Set SapGuiAuto = GetObject("SAPGUI")

Set appl = SapGuiAuto.GetScriptingEngine

Set conn1 = appl.Children(0)

and use this connection within CreateObject("SAP.Functions")

E.G.

+ Set funcControl = CreateObject("SAP.Functions")+

+ funcControl.Connection = conn1+

VB script returns error.

What a reason of error? Perhaps, additional type convertion for object Connection is needed?

Former Member
0 Kudos

Hello,

you can check if you are connected with <MyConnObject>.isconnected and if it returns 1 then you are, if not you can try <MyConnObject>.reconnect.

Regards,

Andi