0

I wanna pimp up my code for not having many restrictions. I start my Macro like this. There I define the Application, Connection and session. The last comment ist just a placeholder for the SAP gui Skript from recorder.

Public SapGuiAuto
Public objGui As GuiApplication
Public objConn As GuiConnection
Public session As GuiSession
'--- Funktion für SAP-Anbindung ---
Sub SAPCustomerReport()
 
    '--- Verbindungsaufbau zur SAP Sitzung ---
    Set SapGuiAuto = GetObject("SAPGUI")
    Set objGui = SapGuiAuto.GetScriptingEngine
    Set objConn = objGui.Children(0)
    Set session = objConn.Children(0)
 
    '-- SKRIPT AUS DEM SAP RECORDER

End Sub

Now i want to make a loop that goes through all open windows until it find first the "1_RPR". After it finds this it should do the transaction. If this is finished i want to loop again to search for a open window that belongs to "5_SPH" and do there the same process. For the distinction I made this code but I don't know how to make the loop over the open windows.

Dim Test1 As String
     If objConn.Description = "1_RPR" Then
        Test1 = "RPR"
                                                        'Skript für RPR Transaktion <---
     ElseIf objConn.Description = "5_SPH" Then
        Test1 = "SPH/APO"
                                                        'Skript für SPH/APO Transaktion <---
     Else
        GoTo KeineSitzung
     End If

A pre-condition is that someone is logged on to minimum 1 of the servers. If It doesn't fit I will make a MsgBox("No Session of RPR or SPH available.").

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 1
    Does this answer your question? [Find SAP GUI session opened for given SAP system](https://stackoverflow.com/questions/71624238/find-sap-gui-session-opened-for-given-sap-system) – Sandra Rossi Jul 18 '22 at 14:07
  • Not really, because if i open sessions from different servers like 1_RPR or 5_SPH there is no decision there. I want to check for a session for example 1_RPR while there could be both (maybe multiple) opened. And if i found a session, i need to check if the maximum number of possible sessions is higher than the number of sessions in this server, and finally the last step, if the number of sessions is 4 and 6 are possible, it should open a new session because 4 < 6, where i want to run my code. – xaraj yawell Jul 19 '22 at 08:26
  • Could you edit and refine your question to only the part which is not solved, please? Currently, one part of your question is solved by the other answer, so you should remove this part from yours. and focus on how to get the maximum number of sessions i.e. merge your comment into your question. Thank you. – Sandra Rossi Jul 19 '22 at 08:31
  • But my problem isn't solved yet. I didn't asked for finding a free session. I asked to find a specified session with the objConn.Description "1_PRP" or "5_SPH". Whatever i need of these two. If i maybe need a 1_RPR session, i need to find an open session of all opened sessions where the objConn.Description is correct. And then I want to interact with this session. After this i can do a new question with the problem which depends on the maximum number of sessions. – xaraj yawell Jul 19 '22 at 09:12
  • 1
    You should have a look at the code I provided in the solution Sandra linked to. This should give you some insight how to loop through sessions and find the session you want to get. There is also a count property. Please try to explore the code and if you got a specific problem post it here. – Storax Jul 19 '22 at 11:10

0 Answers0