cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to handle Save as Dialog?

Former Member
0 Kudos
14,741

Hello,

I am new to Scripting : specially to copy SAP GUI Script to excel VBA but SAP will pop up a -save as- windows which is not recorded in the Script recorder: this may be a Window popup I don't know: How do I enter a path and filename automatically so I don't have to press SAVE in that popup ?

I also would like to over write this file since I am using this task as repetitive. I see a few chats on that subject but cannot get the proper VBA code . tx

below is a typical Script from SAP GUI :

  1. session.findById("wnd[0]").maximize
  2. session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00007"
  3. session.findById("wnd[0]/usr/ctxtCHARG-LOW").Text="4552872B"
  4. session.findById("wnd[0]/usr/ctxtBWART-LOW").Text="101"
  5. session.findById("wnd[0]/usr/txtMJAHR-LOW").Text="2000"
  6. session.findById("wnd[0]/usr/txtMJAHR-HIGH").Text="2015"
  7. session.findById("wnd[0]/usr/ctxtALV_DEF").Text="/CPS"
  8. session.findById("wnd[0]/usr/ctxtALV_DEF").SetFocus
  9. session.findById("wnd[0]/usr/ctxtALV_DEF").caretPosition =4
  10. session.findById("wnd[0]/tbar[1]/btn[8]").press

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Not sure if you still need a hint, anyways let me share how I managed to get around the dialog box issue myself.

The requirement was to create an attachment to the invoice from one of its outputs (most outputs have archive mode configured, but for some reason a couple of them didn't and there was no quicker way of adding 100+ attachments per month or so, until this was fixed). The output went to the spool, from where it would be exported as PDF to a temp location, and from there later uploaded as the invoice attachment.

' prior to this some code that gets the output processed and into the spool - here we end up right before hitting that
' "export to pdf" button
session.findById("wnd[0]/usr/chk[1,3]").selected = true
session.findById("wnd[0]/usr/chk[1,3]").setFocus

' and here I start another script in the background that will be handling the dialog box:
set Wshell = CreateObject("WScript.Shell")
Wshell.run "C:\tmp\script_dialog.vbs",1,false

' now you run the "export to pdf"
session.findById("wnd[0]/mbar/menu[0]/menu[2]/menu[2]").select
session.findById("wnd[0]/tbar[0]/okcd").text = "/nvf02"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtVBRK-VBELN").text = yourVariable

' sleep is optional, I needed it because my instance took long to process some of the documents
WScript.Sleep 2*1000

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

' once more you run the background script (the last one stops the moment it ends processing the dialog box), this time for
' the file upload

set Wshell = CreateObject("WScript.Shell")
Wshell.run "C:\tmp\script_dialog.vbs",1,false

' and some more code after the upload dialog is done

session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_PCATTA_CREA"
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press

And here is that background script:

' I'm using excel to store my variables - if you want to overwrite the file then this might not be necessary
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,"Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet

docName = objSheet.Cells(2, 3).Value
FileName =  docName&".pdf"

Set Wshell = CreateObject("WScript.Shell")
Do 
 bWindowFound = Wshell.AppActivate("Save As") 
 wscript.sleep 1000
 cWindowFound = Wshell.AppActivate("Import file") 
 wscript.sleep 1000
Loop Until bWindowFound or cWindowFound

' and probably the least elegant solution around - using tab sendkeys to access the necessary input fields. 
' the number of tabs depends on what you want to access - might be different for you. Trial and error are recommended ;)

if (bWindowFound) Then

Wshell.appActivate "Save As"
Wshell.SendKeys "{TAB}"
WScript.Sleep 100
Wshell.SendKeys "{TAB}"
WScript.Sleep 100
Wshell.SendKeys "{TAB}"
WScript.Sleep 100
Wshell.SendKeys "{TAB}"
WScript.Sleep 100
Wshell.SendKeys "{TAB}"
WScript.Sleep 100
Wshell.SendKeys FileName
WScript.Sleep 100
Wshell.SendKeys "{ENTER}"
end if

if (cWindowFound) Then

Wshell.appActivate "Import file"
Wshell.SendKeys "{TAB}"
WScript.Sleep 100
Wshell.SendKeys "{TAB}"
WScript.Sleep 100
Wshell.SendKeys "{TAB}"
WScript.Sleep 100
Wshell.SendKeys FileName
WScript.Sleep 1000
Wshell.SendKeys "{ENTER}"
end if

Hope this helps. Let me know if you have any questions.

Cheers,

Mike

script_man
Active Contributor
0 Kudos

Hi Dan,

the solution depends on the SAP GUI version. If you are using version 7.5, you can immediately look at the proposal of Martin Luedecke.

Otherwise it will be more complicated but still solvable. 😉

https://archive.sap.com/discussions/thread/1487670

Regards,

ScriptMan

Former Member
0 Kudos

tx for the hint Frank,

since I am just a new user of SAP I have no access to add NOTES ,

or this may be in SETTINGS etc.

can you provide instructions on how to implement this ?

I have to contact a HELP desk in the company here to add this .

I am assuming this will enable de GUI Script recoder to actually record all actions in any popup windows.

I am copying this in to Excel VBA to run this as a macro . the first part works fine in Excel, but

stops right at the Save As window popup...

tx for your HELP ..

Cheers,

DAN

FrankKrauseGUI
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Dan,

you should apply SAP Note 1974590 - file save dialog during scripting.

With this SAP Note the file save dialog will be displayed as an ABAP Dialogbox that can be accessed via SAP GUI Scripting.

Best regards,
Frank