Skip to Content
-1

Not able to get hold of session in SAP

Hello Experts,

I am very new to SAP and first time i am trying to automate the GUI using C#

Version is SAP GUI 730

I have two issues

1. The new connection created is not appearing in saplogon.ini file

2. I am not getting the session even though i have logged into the SAP

What library i am using to automate:

Here for automation I am using SAP.GUI.Scripting.net which basically a .net version of the below

- saprotwr.dll : ROT Wrapper - sapfewse.ocx : Controls library

SAP landscape :

Scripting enabled in GUI but scripting is not enabled in server (requested but may take time)

Procedure :

a) started the process saplogon.exe

b) trying to get the session so that i can enter the credentials to login

I am getting an error when taking the GUI session from connection, there is no session associated with the connection

_sapGuiApplication = GetSAPGuiApp(secondsOfTimeout);

_sapGuiApplication.OpenConnectionByConnectionString(server);
var index = _sapGuiApplication.Connections.Count - 1;
this._sapGuiConnection = _sapGuiApplication.Children.ElementAt(index) as GuiConnection;
index = _sapGuiConnection.Sessions.Count - 1;
this._sapGuiSession = _sapGuiConnection.Children.Item(index) as GuiSession;

can somebody help me with this?

Regards,

Deepak

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on May 28 at 11:52 AM

    Thanks all i am able to connect. The issue was with server side enabling of script

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 21 at 05:51 PM
    -1

    Hi Deepak.

    1. Are you sure where is the saplogon.ini location? you want to logon SAP system? or any other action going to perform?

    If you are using only for logon you can use the SAPSHCUT.exe. you can find the command line help use the following string in the command prompt " start sapshcut /?"

    2. Are you using the same user id and password to get the session?

    Regards

    SS

    Add a comment
    10|10000 characters needed characters exceeded

    • sap-con.pngsap-login.pngsap-logon.pngHi Sandra & Sriram,

      Thanks for your reply. Apologies if there is any confusion as to my lack of knowledge in this

      Yes, this is a windows client and I am using the same username and password to connect

      I tried to do scripting in two ways,

      Regarding first issue:-

      We can create connections on the SAP logon screen and it will appear on the right panel. (name, SID, Group/server). We have a few default connections, all of which appear in the file saplogon.ini. But not the one created by me (I read somewhere that they are going to replace it with xml file from version 740)

      this was for connecting to SAP and getting the session using the below code snippet and I am getting an error on the highlighted part

      SapGuiApp = new GuiApplication(); SapConnection = SapGuiApp.OpenConnection(connectString,true); //creates connection- where connection string is the name of the connection on the screen

      SapSession = (GuiSession)SapConnection.Sessions.Item(0);


      connection string in this case is the name of the SAP connection i created

      This is something i have received from SAP administration team

      when i create a connection by Create connection i am giving this in the Application Server field

      Second one :-

      was to connect using OpenConnectionByConnectionString by passing the server details and i was getting the same error

      _sapGuiApplication = GetSAPGuiApp(secondsOfTimeout); _sapGuiApplication.OpenConnectionByConnectionString(server);

      var index = _sapGuiApplication.Connections.Count - 1;

      this._sapGuiConnection = _sapGuiApplication.Children.ElementAt(index) as GuiConnection;

      index = _sapGuiConnection.Sessions.Count - 1;

      this._sapGuiSession = _sapGuiConnection.Children.Item(index) as GuiSession;


      connection string in this case is "JQSAPM01" :

      This is something i have received from SAP administration team

      when i create a connection by Create connection i am giving this in the Application Server field

      Thanks,

      Deepak

      sap-logon.png (37.1 kB)
      sap-con.png (9.9 kB)
      sap-login.png (20.5 kB)
  • Posted on May 21 at 07:27 PM
    -1

    Hi Deepak.

    We can understand your requirements, but I am sure about the .net scripting, You can try the following steps from SAPGUI. by creating the either *.bat or *.cmd file to executing the commands.

    Start the SAPGUI with any one of the applicationaton server, you can use the command line "start 1. sapgui (host of application server) (system number)" & create the *.bat or cmd file

    If you want to pass the user credentials use the following commands

    2. "Start sapshcut -system=SID -client=XXX -desc=(You have define the system parameters in the SAPGUI logonpad) -user=userid -pw=Password -maxgui "

    & create the *.bat or cmd file

    3. SAPGUI 7.30, 7.40 & 7.50 version are already end of support from SAP, better try to use the latest version SAPGUI 7.60.

    Regards

    SS

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 22 at 06:46 AM
    -1
    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Sriram,

      thanks for this. I am able to login but my issue still exists, i am not able to get the 'Session'

      in my c# code I have to enter some text to the edit text field on the screen and i am using the below code referencing SAP sapfewse.ocx

      GuiTextField txt = (GuiTextField)SapSession.ActiveWindow.FindByName("ABCD-ABCD", "GuiTextField")
      
      txt.Text = "ABCD";

      as you can see this can be achieved only if i have a session and i am unable to get a session from a connection

      My question : Is it necessary to enable server-side scripting to get the session from a connection?

      i mean sapgui/user_scripting =TRUE

      Thanks,

      Deepak