on 02-06-2009 8:23 PM
Hi Experts - I was wondering if someone out there can help me. My question is how would I copy a column of data from an ALV grid and paste it into another area (variant) using a script. I can get it to select (highlight) the column but cannot get it to copy to clipboard for later pasting. Ctrl-C is not recorded in the script. If this is not working with this version, is there a way I can get the script to keypress the letter "C" so I can do a copy through right-clicking and bringing up context menu. I tried saving it into a file and read in the file later but file saved from ALV comes with vertical bars around the data. I tried everything I could think of. The only way seems to be find the command to cut and keep it in the clipboard for pasting.
Thanks for any insight. (I also posted this question in another forum by mistake).
Umur
Hi Umur,
I have this problem solved as follows:
For example:
session.findById("wnd[0]/usr/subSUB_OBJSEL:/BE2/SAPLRECN_GUI_CN_SEL:1000/ctxt/BE2/RECN_CONTRACT_X-RECNNR").setFocus
The recorded line converts it to.
MyClip = session.findById("wnd[0]/usr/subSUB_OBJSEL:/BE2/SAPLRECN_GUI_CN_SEL:1000/ctxt/BE2/RECN_CONTRACT_X-RECNNR").text
At a new location you can use the variable again:
session.findById("wnd[0]/usr/subSUB_OBJSEL:/BE2/SAPLRECN_GUI_CN_SEL:1000/ctxt/BE2/RECN_CONTRACT_X-New_RECNNR").Text = MyClip
Regards,
ScriptMan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Scriptman - this is from an SUIM report output and provides a list only. The individual fields are not recognized by the script when you try to record. The only thing that can be done is to click on the column header and select all. The whole thing is in a container. When I click the header title the recording shows this:
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellRow = -1
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn "BNAME"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectedRows = ""
It is at this point that I would like to be able to cut and paste. That is what I can't get the script to record and playback. So I had to be creative and save it into a file and then call it up and paste it after cleaning the file from garbage dashes and bars. It works and does the trick but it is a very clunky solution.
Cheers
Umur
ScriptMan - I tried your solution but I am not sure what panel you have popping up with wnd[1] in your code. As there is no Window[1] it fails. All I have is a shell with rows of userid's, that I can only click on the column heading. Is there a way I can simulate Control-C key combination (to copy the row into clipboard so I can then paste it into another list?
Regards
Umur
Hi Umur,
sorry, it should properly WND [0] read.
My approach is to suggest that each cell must be read out individually.
For example:
...
ROW = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellRow
CELL = session.findById("wnd[0]/usr/cntlCONTAINER_0100/shellcont/shell").getcellvalue (ROW,"BNAME")
CELL_1 = session.findById("wnd[0]/usr/cntlCONTAINER_0100/shellcont/shell").getcellvalue (ROW,"BNAME_1")
CELL_2 = session.findById("wnd[0]/usr/cntlCONTAINER_0100/shellcont/shell").getcellvalue (ROW,"BNAME_2")
MyLINE = CELL & CELL_1 & CELL_2
ROW = ROW + 1
...
Incidentally, I must apologize for my English. Basically, I can absolutely not. Google - translator helps me here.
Regards,
ScriptMan
ScriptMan - it cannot find control because there is no "cntlCONTAINER_0100" element on that screen. The only element is "usr > cntlGRID1> shellcont --> shell", and that is just the shell. Sorry if I am missing something.
Regards
Umur
P.S. the English whether translated or not is just fine. Thanks for your effort and taking time to help out fellow scripters.
Hi Umur,
of course, read as follows:
...
ROW = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellRow
CELL = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getcellvalue (ROW,"BNAME")
CELL_1 = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getcellvalue (ROW,"BNAME_1")
CELL_2 = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getcellvalue (ROW,"BNAME_2")
MyLINE = CELL & CELL_1 & CELL_2
ROW = ROW + 1
...
That was just an example. The whole time is actually only the function ... "getCellValue" that one can not record. Sorry if I use my examples inaccurate confused should have.
Regards,
ScriptMan
ScriptMan - you did it again! Thanks! I was able to read the values from the grid and pasted into a text file to be later used by pasting the user id's into another program's variant. I counted number of rows and inserted the reading process in a 'for' loop for that range.
Set fso = CreateObject("Scripting.FileSystemObject")
Set TextFile = fso.CreateTextFile("c:\tmp\Conc.txt",True)
session.findById("wnd[0]").maximize
RowCt = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").rowCount
For ROW = 0 To RowCt-1
CELL = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getcellvalue (ROW,"BNAME")
TextFile.WriteLine CELL
Next
TextFile.Close
I then open this file and read records one by one into the variant lines. This works ok but if there was a way to pull in the text file directly into the variant using 'Import from text file' function (Shift-F11). When I press the button, I can't get the script to type the filename into the Windows "Open" Dialog box. Is there a way to overcome this?
Regards
Umur
Hi Umur,
first I am happy that I could help you. You notice that you are also profound, with the topic of scripting deal.
When I see the last question correctly, it goes to windows and entries into this who are not in script recorder can record. I think I have a few solutions. Unfortunately, I am starting tomorrow for a few days. I come to you again.
Regards,
ScriptMan
Hi Umur,
now I'm back. I will publish here an example of how I would solve the problem.
It is thought the dialog box has the name "Open File".
...
set Wshell = CreateObject("WScript.Shell")
Do
bWindowFound = Wshell.AppActivate("Open File")
WScript.Sleep 1000
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Open File")
if (bWindowFound) Then
Wshell.appActivate "Open File"
WScript.Sleep 100
Wshell.sendkeys "c:\tmp\filename.txt"
WScript.Sleep 100
Wshell.sendkeys ""
end if
...
As I said, it should only be a suggestion.
Regards,
ScriptMan
Hi ScriptMan - just tried your code. I open up the "Open file' dialog but it sits there - I changed 1000 wait to 100 to see if anything was going to happen but did not seem to go through. It looks like it is not recognizing the open dialog to enter the filename. I tried changing the "Open File" with "Open" (which is what the window title is in my case) thinking it might be what it is looking for but that did not work either. I did not complete the end of the code to execute and save the names but the names do not even drop in the Multiple Selection for User ID dialog. I wanted to get to that point before worrying about the end of the code.
Here's the code - I showed the point it hangs with '<--'. Looks like this will be tricky to get it to work:
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
set Wshell = CreateObject("WScript.Shell")
session.findById("wnd[0]/usr/btn%_S_BNAME_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/tbar[0]/btn[23]").press
Do
bWindowFound = Wshell.AppActivate("Open File") *<-- this is where it comes up to and hangs*
WScript.Sleep 100
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Open File")
if (bWindowFound) Then
Wshell.appActivate "Open File"
WScript.Sleep 100
Wshell.sendkeys "c:\tmp\Conc.txt"
WScript.Sleep 100
Wshell.sendkeys ""
end if
Regards
Umur
Hi Umur,
Obviously, the window title to be adjusted. If they are "Open" means that my example looks like this:
...
Do
bWindowFound = Wshell.AppActivate("Open")
WScript.Sleep 1000
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Open")
if (bWindowFound) Then
Wshell.appActivate "Open"
WScript.Sleep 100
Wshell.sendkeys "c:\tmp\Conc.txt"
WScript.Sleep 100
Wshell.sendkeys ""
end if
...
Unfortunately, I know the specific transaction is not that you are using. A tip from me: After the dialog has opened, all entries should try only using the keyboard to grasp. These keystrokes, you should write to you and me. If you prefer, you can also use my e-address. I would then have a look.
Regards,
ScriptMan
Hi ScriptMan - sorry but even with the dialog box name used as "Open" does not do the trick. I had tried it last week and tried again with Open again, still won't work. The Open dialog screen comes up and it just sits there as if "bWindowFound" is never true. I bring up the dialog box prior to getting into the 'Do':
set Wshell = CreateObject("WScript.Shell")
session.findById("wnd[0]/usr/btn%_S_BNAME_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/tbar[0]/btn[23]").press
Do
bWindowFound = Wshell.AppActivate("Open")
WScript.Sleep 1000
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Open")
if (bWindowFound) Then
Wshell.appActivate "Open"
WScript.Sleep 100
Wshell.sendkeys "c:\tmp\Conc.txt"
WScript.Sleep 100
Wshell.sendkeys ""
end if
-
I then moved the dialog open line in the loop to see if that would make it work but it still did not work with the command in the loop.
Not sure what else I can play with to make it work.
Regards
Umur
Hi ScriptMan - I am running a security report transaction through SUIM (program RSUSR070) - Roles by Complex Selection Criteria (selection according to user assignments). But I also tried it with another screen - IW38 to pull up, "Entered by" user ids. It still did not do anything and just sat there waiting to process the next command on the open dialogue. The dialog box (title "Multiple Selection for xxxx") to populate the user id is pretty much identical for all these. The title of the dialog window is "Open" for all. Looks like it is having problem in identifying that the Open dialog has popped up.
Thanks
Regards
Umur
Hi Umur,
I have a long time until I have grasped what is actually happening. My solution to the problem is as follows:
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
set Wshell = CreateObject("WScript.Shell")
Wshell.run "c:\tmp\open.vbs",1,false
session.findById("wnd[0]/usr/btn%_S_BNAME_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/tbar[0]/btn23").press
...
The file "open.vbs" has the following contents:
set Wshell = CreateObject("Wscript.Shell")
Do
bWindowFound = Wshell.AppActivate("Open")
WScript.Sleep 1000
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Open")
if (bWindowFound) Then
Wshell.appActivate "Open"
WScript.Sleep 100
Wshell.sendkeys "c:\tmp\Conc.txt"
WScript.Sleep 100
Wshell.sendkeys ""
end if
Let's see if this is already the solution for you.
Regards,
ScriptMan
Hi ScriptMan - you are a genius. You did it again! This is going to help eliminate a lot of steps in my script where I had to copy id's into a text file, go into another script, clean the data, save, then come back to the same screen and copy these one by one into the dialog, counting the number of lines, etc.
This helps a lot! I am going to paste the script below, in case some one else needs something similar and they can modify and use.I am sure I can use it for some other cases.
Thanks again and best regards.
Umur
-
'This script opens a text file (Conc.txt) populated with userid's and paste these into a "multiple
'selection for xxx" panel. This script emulates SHIFT-F11 (Import from text file) command. Although this
'script uses "BNAME" as the field label, the concept can
'be used for any panel where the input file contains data to be pulled into a multiple select field under
'the "Single value" column. Could be used for equipment number, user ids, material numbers, etc. etc..
'The key to make this work another script file that runs in the background, called by the main script.
'The background file "open.vbs" contents is as follows:
'
'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
'set Wshell = CreateObject("Wscript.Shell")
'Do
'bWindowFound = Wshell.AppActivate("Open")
'WScript.Sleep 1000
'Loop Until bWindowFound
'bWindowFound = Wshell.AppActivate("Open")
'if (bWindowFound) Then
'Wshell.appActivate "Open"
'WScript.Sleep 100
'Wshell.sendkeys "c:\tmp\Conc.txt"
'WScript.Sleep 100
'Wshell.sendkeys ""
'end if
'
'save the above code in a directory and execute the main script.Courtesy: ScriptMan
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
set Wshell = CreateObject("WScript.Shell")
Wshell.run "c:\tmp\open.vbs",1,false
session.findById("wnd[0]/usr/btn%_S_BNAME_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/tbar[0]/btn[23]").press
session.findById("wnd[1]/tbar[0]/btn[8]").press
'This script opens a text file populated with userid's and paste these into a "multiple
'selection for xxx" panel. This script emulates SHIFT-F11 (Import from text file) command. Although this
'script uses "BNAME" as the field label, the concept can
'be used for any panel where the input file contains data to be pulled into a multiple select field under
'the "Single value" column. Could be used for equipment number, user ids, material numbers, etc. etc..
'The key to make this work another script file that runs in the background, called by the main script.
'The background file "open.vbs" contents is as follows:
'
'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
'set Wshell = CreateObject("Wscript.Shell")
'Do
'bWindowFound = Wshell.AppActivate("Open")
'WScript.Sleep 1000
'Loop Until bWindowFound
'bWindowFound = Wshell.AppActivate("Open")
'if (bWindowFound) Then
'Wshell.appActivate "Open"
'WScript.Sleep 100
'Wshell.sendkeys "c:\tmp\Conc.txt"
'WScript.Sleep 100
'Wshell.sendkeys ""
'end if
'
'save the above code in a directory and execute the main script.Courtesy: ScriptMan
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
set Wshell = CreateObject("WScript.Shell")
Wshell.run "c:\tmp\open.vbs",1,false
session.findById("wnd[0]/usr/btn%_S_BNAME_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/tbar[0]/btn[23]").press
session.findById("wnd[1]/tbar[0]/btn[8]").press
Sorry the code got pasted garbled. Here it is again:
'This script opens a text file populated with userid's and paste these into a "multiple
'selection for xxx" panel. This script emulates SHIFT-F11 (Import from text file) command. Although this
'script uses "BNAME" as the field label, the concept can
'be used for any panel where the input file contains data to be pulled into a multiple select field under
'the "Single value" column. Could be used for equipment number, user ids, material numbers, etc. etc..
'The key to make this work another script file that runs in the background, called by the main script.
'The background file "open.vbs" contents is as follows:
'
'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
'set Wshell = CreateObject("Wscript.Shell")
'Do
'bWindowFound = Wshell.AppActivate("Open")
'WScript.Sleep 1000
'Loop Until bWindowFound
'bWindowFound = Wshell.AppActivate("Open")
'if (bWindowFound) Then
'Wshell.appActivate "Open"
'WScript.Sleep 100
'Wshell.sendkeys "c:\tmp\Conc.txt"
'WScript.Sleep 100
'Wshell.sendkeys ""
'end if
'
'save the above code in a directory and execute the main script.Courtesy: ScriptMan
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
set Wshell = CreateObject("WScript.Shell")
Wshell.run "c:\tmp\open.vbs",1,false
session.findById("wnd[0]/usr/btn%_S_BNAME_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/tbar[0]/btn[23]").press
session.findById("wnd[1]/tbar[0]/btn[8]").press
Hi,
I'm trying to execute your code but without success. When "Open" window appears it only changes a current directory to "My Computer" or "Recent Files". Can you help me with that?
Screenshots:
My code:
001 | |
002 | If Not IsObject(application) Then |
003 | Set SapGuiAuto = GetObject("SAPGUI") |
004 | Set application = SapGuiAuto.GetScriptingEngine |
005 | End If |
006 | If Not IsObject(connection) Then |
007 | Set connection = application.Children(0) |
008 | End If |
009 | If Not IsObject(session) Then |
010 | Set session = connection.Children(0) |
011 | End If |
012 | If IsObject(WScript) Then |
013 | WScript.ConnectObject session, "on" |
014 | WScript.ConnectObject application, "on" |
015 | End If |
016 | set Wshell = CreateObject("WScript.Shell") |
017 | MySession.findById("wnd[0]").resizeWorkingPane 142,18,false |
018 | MySession.findById("wnd[0]/tbar[0]/okcd").text = "zse16" |
019 | MySession.findById("wnd[0]").sendVKey 0 |
020 | MySession.findById("wnd[0]/usr/ctxtI_TABLE").text = "MLAN" |
021 | MySession.findById("wnd[0]/usr/ctxtI_TABLE").caretPosition = 4 |
022 | MySession.findById("wnd[0]").sendVKey 0 |
023 | MySession.findById("wnd[0]/tbar[1]/btn[8]").press |
024 | Wshell.run "c:\sciezka.vbs",1,false |
025 | MySession.findById("wnd[0]/usr/btn%_I1_%_APP_%-VALU_PUSH").press |
026 | MySession.findById("wnd[1]/tbar[0]/btn[23]").press |
027 | MySession.findById("wnd[1]/tbar[0]/btn[8]").press |
028 |
sciezka.vbs:
set Wshell = CreateObject("Wscript.Shell")
Do
bWindowFound = Wshell.AppActivate("Open")
WScript.Sleep 1000
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Open")
if (bWindowFound) Then
Wshell.appActivate "Open"
WScript.Sleep 100
Wshell.sendkeys "C:\materials.txt"
WScript.Sleep 100
Wshell.sendkeys ""
end if
Hi Jon -
this is how I call it from main module:
....
FileName = "C:\Tanks-MtceItem.txt"
Wshell.run "c:\tmp\TankLoad.vbs " & FileName,1,False
session.findById("wnd[0]/usr/btn%_WAPOS_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]/tbar[0]/btn[23]").press
session.findById("wnd[1]/tbar[0]/btn[8]").press
...
and this is how my called routine 'TankLoad.vbs' looks like:
Dim FileNam2
Set Wshell = CreateObject("WScript.Shell")
Do
bWindowFound = Wshell.AppActivate("Open")
WScript.Sleep 1000
Loop Until bWindowFound
bWindowFound = Wshell.AppActivate("Open")
if (bWindowFound) Then
Wshell.appActivate "Open"
WScript.Sleep 100
Wshell.sendkeys "{TAB}"
Wshell.sendkeys "{TAB}"
Wshell.sendkeys "{TAB}"
Wshell.sendkeys "{TAB}"
WScript.Sleep 100
FileNam2 = WScript.Arguments.Item(0)
'Wshell.sendkeys "c:\EQ2814.txt"
Wshell.sendkeys FileNam2
WScript.Sleep 100
Wshell.sendkeys "{ENTER}"
WScript.Sleep 100
end if
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.