cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to get hold of session in SAP

0 Kudos

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

Sandra_Rossi
Active Contributor

You're wrong, opening a connection should NOT make it appear in saplogon.ini file (and anyway, this file is not used anymore nowadays, if I'm not wrong).

If there's no session opened, it means that the connection string is incorrect.

I guess you have a SAP GUI (for Windows?) installed and an entry to your SAP system exists. Could you show the entry details and show your your connection string so that we can validate it?

Sandra_Rossi
Active Contributor
0 Kudos

"JQSAPM01" is NOT a valid connection string. Please provide the details, as I told you. Don't hide all information, simply change the names, but keep names coherent between SAP GUI entry and connection string. That's all.

0 Kudos

Hi Sandra,

That may be the host name

I have manually connected to the SAP and using script i have got the below details.

"/SAP_CODEPAGE=1100 /FULLMENU JQSAPM01 00 /3 /UPDOWNLOAD_CP=2"

i think you are asking a connection string in a format as below

"/H/XX.21.8.XX/S/3200" or JQSAPM01.company.com

tried with all these but no luck

if you see the connection properties

i could see Connection.DisabledByServer = true

that means SAP scripting is disabled in server. Is it rquired to enable this?

sapgui/user_scripting must be TRUE

Thanks,

Deepak

Sandra_Rossi
Active Contributor
0 Kudos

Don't you have a group or other SAP GUI properties?

Sandra_Rossi
Active Contributor
0 Kudos

Sorry, I just saw you last comment. Yes it must be enabled, otherwise you can't connect.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

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

Answers (3)

Answers (3)

S_Sriram
Active Contributor
0 Kudos
0 Kudos

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

S_Sriram
Active Contributor
0 Kudos

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

0 Kudos

I would also like to add

Connection.DisabledByServer = true this means that the Scripting is disabled on your application server

Can this be the problem?

S_Sriram
Active Contributor
0 Kudos

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

0 Kudos

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