You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

1

Thursday, May 9th 2013, 10:10am

How to use SAP GUI Scripting with Jabaco via JaCoB

Hello community,

a longer time ago I presented here the possibility to use an SAP system via JCo (Java Connector). SAP offers a few interfaces to communicate with it. Another interface is the SAP GUI Scripting.

With SAP GUI Scripting it is possible to emulate user interaction to an SAP system. Nearly all what you can do manually, you can do with SAP GUI Scripting automatically.

Now I have the idea to combine the possibilities of the SAP Remote Function Call (RFC) library via JCo and the user interaction emulation via SAP GUI Scripting. So you can use all RFC and SAP GUI functionalities in one program. Jabaco is an ideal platform to realize this feature.

SAP GUI Scripting is a COM resp. ActiveX library. To use it inside Jabaco it is necessary to use JaCoB (Java COM Bridge). You find a lot of examples in this forum, e.g. here.

Here is now the example how to use SAP GUI Scripting with Jabaco via JaCoB:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'-Begin-----------------------------------------------------------------

  '-Directives----------------------------------------------------------
    Option Explicit

  '-Sub SAPGUIScript----------------------------------------------------
    Sub SAPGUIScript()

      '-Variables-------------------------------------------------------
        Dim SAPROTWr As ActiveXComponent
        Dim Params(0) As Object
        Dim ROTEntry As Dispatch
        Dim App As Dispatch
        Dim Version As String
        Dim Con As Dispatch
        Dim Ses As Dispatch
        Dim oCtrl As Dispatch
        Dim SesInf As Dispatch
  
      Set SAPROTWr = New ActiveXComponent("SapROTWr.SapROTWrapper")
      If SAPROTWr <> Nothing Then
        Params(0) = "SAPGUI"
        ROTEntry = Dispatch.call(SAPROTWr, "GetROTEntry", Params).toDispatch
        If ROTEntry <> Nothing Then
          App = Dispatch.get(ROTEntry, "GetScriptingEngine").toDispatch
          If App <> Nothing Then
          
            '-Shows SAP GUI Scripting version---------------------------
              Version = Dispatch.get(App, "MajorVersion").toString & _
                "." & Dispatch.get(App, "MinorVersion").toString
              Debug.Print Version
              
            '-Gets session 0 from connection 0--------------------------  
              Params(0) = 0
              Con = Dispatch.call(App, "Children", Params).toDispatch
              If Con <> Nothing Then
                Ses = Dispatch.call(Con, "Children", Params).toDispatch
                If Ses <> Nothing Then

                  '-Logs on the SAP system------------------------------
                    '-Sets the Client field-----------------------------
                    '-
                    '- Equivalent SAP GUI Scripting command:
                    '- session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "001"
                    '-
                    '---------------------------------------------------
                      Params(0) = "wnd[0]/usr/txtRSYST-MANDT"
                      oCtrl = Dispatch.call(Ses, "findById", Params).toDispatch
                      Dispatch.put(oCtrl, "text", "001")
                    '-Sets the User field-------------------------------
                    '-
                    '- Equivalent SAP GUI Scripting command:
                    '- session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "BCUSER"
                    '-
                    '---------------------------------------------------
                      Params(0) = "wnd[0]/usr/txtRSYST-BNAME"
                      oCtrl = Dispatch.call(Ses, "findById", Params).toDispatch
                      Dispatch.put(oCtrl, "text", "BCUSER")
                    '-Sets the Password field---------------------------  
                    '-
                    '- Equivalent SAP GUI Scripting command:
                    '-  session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "minisap"
                    '-
                    '---------------------------------------------------
                      Params(0) = "wnd[0]/usr/pwdRSYST-BCODE"
                      oCtrl = Dispatch.call(Ses, "findById", Params).toDispatch
                      Dispatch.put(oCtrl, "text", "minisap")
                    '-Sets the Logon Language field---------------------
                    '-
                    '- Equivalent SAP GUI Scripting command:
                    '- session.findById("wnd[0]/usr/txtRSYST-LANGU").text = "EN"
                    '-
                    '---------------------------------------------------
                      Params(0) = "wnd[0]/usr/txtRSYST-LANGU"
                      oCtrl = Dispatch.call(Ses, "findById", Params).toDispatch
                      Dispatch.put(oCtrl, "text", "EN")
                    '-Sends a return to the SAP GUI---------------------
                    '-
                    '- Equivalent SAP GUI Scripting command:
                    '- session.findById("wnd[0]").sendVKey 0
                    '-
                    '---------------------------------------------------
                      Params(0) = "wnd[0]"
                      oCtrl = Dispatch.call(Ses, "findById", Params).toDispatch
                      Params(0) = 0
                      Dispatch.call(oCtrl, "sendVKey", Params)

                  '-Shows some information from SessionInfo object------
                    SesInf = Dispatch.get(Ses, "Info").toDispatch
                    If SesInf <> Nothing Then
                      Debug.Print Dispatch.get(SesInf, "SystemName")
                      Debug.Print Dispatch.get(SesInf, "SystemNumber").toString
                      Debug.Print Dispatch.get(SesInf, "Transaction")
                      Debug.Print Dispatch.get(SesInf, "User")
                    End If
                
                End If
              End If
          
            App = Nothing
          End If
          ROTEntry = Nothing
        End If
      End If
      Set SAPROTWr = Nothing

    End Sub
    
  '-Main-----------------------------------------------------------------
    Public Sub Command1_Click()
      SAPGUIScript
    End Sub

'-End--------------------------------------------------------------------


You find more information about SAP GUI Scripting in the SAP Community Network (SCN) here or here.

Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

2

Friday, May 10th 2013, 8:19am

Hello community,

here a small extension:
You can use the functions from here to execute your SAP GUI Scripting files from the SAP GUI Scripting recorder.

To create an SAP GUI Script file press Alt+F12 on your keyboard to open the options menu from the SAP GUI for Windows. Choose the menu entry Script Recording and Playback.



Start the recording and do your activities. Then stop the recording and now you can use your SAP GUI Script file with the MSScript Control from Jabaco.

Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

Rate this thread
WoltLab Burning Board