cancel
Showing results for 
Search instead for 
Did you mean: 

Script to run multiple transactions in different windows

Former Member
0 Kudos

Hi!

I've recently discovered the function of script recording in SAP, and find it very useful. I've recorded a few scripts that I use on a regular basis, but when I do, I manually open a new session and starts the different scripts in each window. Is there any way I can have one script that will run all my scripts automatically? I've searched the forum and found a few threads on similar questions, but due to my rather poor knowledge of scripting, I'm not able to convert any of the examples I found in other threads to a script that suits me. Maybe someone can write me an example I can use?

I would like to:

1. Run transaction zpm3n and execute

2. Open new session

3. Run transaction cm07 and execute

4. Open new session

5. Run tranaction IW38 and execute

I might want some additional inputs for each transaction, but I think I'm able to add this by myself.

I have a separate script for each function, if it would be easier to create a script that runs each of the others one by one.

Here is one of my scripts (recorded in SAP), how can I rewrite this to open a new session and switch to the new session?

This opens zpm3n and gets a variant I have created for this transaction.

--------START---------

If Not IsObject(application) Then

   Set SapGuiAuto  = GetObject("SAPGUI")

   Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

   Set connection = application.Children(0)

End If

If Not IsObject(session) Then

   Set session    = connection.Children(0)

End If

If IsObject(WScript) Then

   WScript.ConnectObject session,     "on"

   WScript.ConnectObject application, "on"

End If

session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").text = "zpm3n"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/tbar[1]/btn[17]").press

session.findById("wnd[1]/usr/txtV-LOW").text = "u_429395"

session.findById("wnd[1]/usr/txtENAME-LOW").text = ""

session.findById("wnd[1]").sendVKey 8

session.findById("wnd[0]/tbar[1]/btn[8]").press

-----------END-------------

Appreciate all help!

Espen

Accepted Solutions (0)

Answers (2)

Answers (2)

thomas_brutigam2
Active Participant
0 Kudos

Hi Ridhwan,
Which of the Code you dont understand ?

You can also Copy and Paste the Code or give us a better question...

greetings

former_member622450
Discoverer
0 Kudos

I think the WSF tag is wrong. As far as i have seen the Code starts with <pre> instead of </pre> as shown in the code.
I have copied the code from the link.

</pre>
Dim currentNode
Set xmlParser = CreateObject ("Msxml2.DOMDocument")
'Creating an XML declaration
xmlParser.appendChild (xmlParser.createProcessingInstruction ("xml", "version = '1.0' encoding = 'windows-1251'"))
Set SapGuiAuto = GetObject ("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
Set connection = application.Children (0)
Set session = connection.Children (0)
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
'Maximize the SAP window
session.findById ("wnd [0]"). maximize
enumeration "wnd [0]"
'enumeration' wnd [0] / usr "
MsgBox "Done!", VbSystemModal Or vbInformation
Sub enumeration (SAPRootElementId)
Set SAPRootElement = session.findById (SAPRootElementId)
'Creating a root element
Set XMLRootNode = xmlParser.appendChild (xmlParser.createElement (SAPRootElement.Type))
enumChildrens SAPRootElement, XMLRootNode
xmlParser.save ("C: \ SAP_tree.xml")
End Sub
Sub enumChildrens (SAPRootElement, XMLRootNode)
For i = 0 To SAPRootElement.Children.Count - 1
Set SAPChildElement = SAPRootElement.Children.ElementAt (i)
'Create a node
Set XMLSubNode = XMLRootNode.appendChild (xmlParser.createElement (SAPChildElement.Type))
'Attribute Name
Set attrName = xmlParser.createAttribute ("Name")
attrName.Value = SAPChildElement.Name
XMLSubNode.setAttributeNode (attrName)
'Attribute Text
If (Len (SAPChildElement.Text)> 0) Then
Set attrText = xmlParser.createAttribute ("Text")
attrText.Value = SAPChildElement.Text
XMLSubNode.setAttributeNode (attrText)
End If
'Attribute Id
Set attrId = xmlParser.createAttribute ("Id")
attrId.Value = SAPChildElement.Id
XMLSubNode.setAttributeNode (attrId)
'If the current object is a container, then iterate through the child elements
If (SAPChildElement.ContainerType) Then enumChildrens SAPChildElement, XMLSubNode
Next
End Sub
<pre>
thomas_brutigam2
Active Participant
0 Kudos

Hi Espen,

It is not as easy as it looks...

if there is one Script that would handle all the Transactions it would stop until each transaction is through with all Action. To process all Transactions in one Script it would need multithreading-
That's not possible in VBS :-).

There was a Post like yours some time ago ...

http://scn.sap.com/thread/3388231

same problem  - same answer .....

former_member622450
Discoverer
0 Kudos

Hi,

Can you guys check this page out? i am unable to understand the vbs script

https://www.smartspate.com/how-you-can-automate-work-in-sap-with-vbscript/