cancel
Showing results for 
Search instead for 
Did you mean: 

SAP.Functions vs SAP.ScriptingCtrl.1 vs SAP.GetScriptingEngine

former_member213011
Participant
0 Kudos

Hi Community,

I noticed from this forum that there are several methods of calling the SAP objects in scripts e.g. SAP.Functions, SAP.ScriptingCtrl.1, GetScriptingEngine etc.

Is there any reference document on the differences between these methods e.g. when we should use it, which one is better for what purpose etc?

Just curious...

Thanks,

Sayuti

Accepted Solutions (1)

Accepted Solutions (1)

stefan_schnell
Active Contributor

Hello Sayuti,

SAP.ScriptingCtrl.1 is the program ID (ProgID) of the SAP GUI Scripting API.

If you create an instance like this

Set application = CreateObject("SAP.ScriptingCtrl.1")

you can use the SAP GUI Scripting API inside your program.

SAP.Function is the ProgID of the SAP Remote Function Call Control library. This has nothing to do with the SAP GUI Scripting API. This is a part of the ActiveX libraries to connect SAP via COM.

GetScriptingEngine is a method of the class GuiApplication from the SAP GUI Scripting API. It delivers an IDispatch interface to an instance of a running SAP GUI process.

Hope my explanations help to understand the difference.

Cheers

Stefan

former_member213011
Participant
0 Kudos

Thanks Stefan for the explanation.

If I get this right:

The SAP.ScriptingCtrl.1 is when we want to create and connect while GetScriptingEngine is a method to point and connect.

Are both from the same SAPFEWSELib?

For SAP.ScriptingCtrl.1

- Does not require saplogon to be running 1st for the script to run..

- Is it faster?

- Does the session created using it destroyed once script finish executing?

- If there is already a running session, can we connect to the same session?

BTW, since SAP.Function is for RFC and not for SAPGUI, not applicable to me at the moment.

Thanks,

Sayuti

stefan_schnell
Active Contributor
0 Kudos

Hello Sayuti,

you can use this way for a new connection:


  '-Variables--------------------------------------------------------
    Dim App As SAPFEWSELib.GuiApplication

    Dim Con As SAPFEWSELib.GuiConnection

   '-For a new connect-----------------------------------------------
    Set App = CreateObject("Sapgui.ScriptingCtrl.1")

    '----------------------------------------------------------------
    '-
    '- Connection parameter
    '- /H/ and the IP address of the target system
    '- /S/ 32 + the system number, in this case 00
    '-
    '----------------------------------------------------------------
    Set Con = App.OpenConnectionByConnectionString( _

      "/H/10.100.100.100/S/3200", True, False)

or this way for an existing connection:

  '-Variables--------------------------------------------------------
    Dim Obj As Object

    Dim App As SAPFEWSELib.GuiApplication
    Dim Con As SAPFEWSELib.GuiConnection

  '-For an existing connect------------------------------------------
    Set Obj = GetObject("SAPGUI")
    Set App = Obj.GetScriptingEngine
    Set Con = App.Children(0)

You see, both are part of the SAPFEWSELib.

To your questions:

  1. SAP GUI Scripting always needs a logon.
  2. I don't think so, because it is both the same.
  3. No, you must close your session explicit, only the instance will be destroyed.
  4. Yes, get the number of the session and connect it with
    Dim Ses As SAPFEWSELib.GuiSession
    Set Ses = Con.Children(3) 'If the session number is 3

Good luck and let us know your results.

Cheers

Stefan

former_member213011
Participant
0 Kudos

Dear Stefan,

For question number 1, what I meant was saplogon.exe does not require to be started before running the script, i.e. the script will run saplogon.exe and attach itself to the process, or do we need to run saplogon.exe first prior to running the script?

Thanks,

Sayuti

stefan_schnell
Active Contributor
0 Kudos

Hello Sayuti,

as far as I know it is not necessary to have a running process of saplogon.exe, if you use OpenConnectionByConnectionString as the example above (or OpenConnection). But I am not really sure, because I have used this procedure only once for error Analysis.

Let us know the results, it is very interesting.

Thanks and cheers

Stefan

former_member213011
Participant
0 Kudos

Dear Stefan,

I've tested both methods using the following:

Option Explicit

Const sapServer As String = "sap.msg.server.address"

Const sapID As String = "mySAPID"

Const sapPassword As String = "******"

Dim sap As SAPFEWSELib.GuiApplication

Dim sapCon As SAPFEWSELib.GuiConnection

Dim sapSession As SAPFEWSELib.GuiSession

   

Sub testMethod1()

    Set sap = CreateObject("SAPGUI.Scriptingctrl.1")

    Set sapCon = sap.OpenConnectionByConnectionString(sapServer, True)

    Call loginInfo

End Sub

Sub testMethod2()

    Set sap = GetObject("SAPGUI").GetScriptingEngine

    Set sapCon = sap.OpenConnectionByConnectionString(sapServer, True)

    Call loginInfo

End Sub

Sub loginInfo()

    Set sapSession = sapCon.Children(0)

    With sapSession

        .FindById("wnd[0]/usr/txtRSYST-MANDT").Text = "200"

        .FindById("wnd[0]/usr/txtRSYST-BNAME").Text = sapID

        .FindById("wnd[0]/usr/pwdRSYST-BCODE").Text = sapPassword

        .FindById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

        .FindById("wnd[0]").SendVKey 0

    End With

End Sub

Sub killSAP()

    Set sapSession = Nothing

    Set sapCon = Nothing

    Set sap = Nothing

End Sub

----------------------------------------

My findings are:

For Method1:

  1. I do not have to start the saplogon.exe (aka the logonpad) to use it.
  2. An instance of SAPGUI is created as an object with Excel itself. Checked in the Windows Running Process using Task Manager did not show saplogon.exe.
  3. The SAPGUI always display the classic interface with some buttons not even visible though its there. I had to hover until the tooltip of the button appear.
  4. Setting the SAP objects to Nothing in procedure killSAP will close the SAPGUI.

While typing the killSAP procedure, I mistakenly put the order of object variables from sap to sapSession instead of the other way around as per above. This caused the script and Excel to be 'hanging' until I have to force-close it in Task Manager. Ctrl + Break didn't seem to work in the VBE and Task Manager shows Excel is running (not actually 'not responding').

For Method2:

  1. The saplogon.exe must be running first in order for the script to work. Running the script without starting saplogon will cause an error. The logonpad can be closed once a session is established as long as the saplogon process is still running.
  2. The interface of SAPGUI is the new version.
  3. killSAP will not close the session. Only the script will be detached from the session.

Based on the above, I'm sticking with Method2 with a Shell command to execute saplogon if it is not already running.

Thanks,

Sayuti

stefan_schnell
Active Contributor
0 Kudos

Hello Sayuti,

thank you very much for sharing your results and experience.

Cheers

Stefan

Answers (1)

Answers (1)

Former Member
0 Kudos

Dear Sayuti, Stefan,

I just reading your post and your testmethode2, i'm quite intrusting to get the new version.

I try it and unfortunately, i getting an error into excel. the saplon is lauched but the application is in idle mode, until i get an error.

Is it possible to share how you do this type of connection with more details ?

Many thanks.

former_member213011
Participant
0 Kudos

Dear Samir,

What is the error did you get from Excel?

I'm not sure how to be more detailed than I already have. The procedure is pretty straightforward.

First you need to do 'early-binding' to sapfewse.ocx. has written how to do it here: http://scn.sap.com/thread/2102571

If this does not solve the issue, perhaps, the version of software is different. I used Excel 2010 running on Windows 7 and saplogon 720.

Also, is scripting support enabled by your server?

Thanks,

Sayuti