Search code examples
excelvbscriptsap-gui

How to disable the Excel display with SAP GUI Scripting automatically


I recently discovered SAP GUI Scripting. First I started to record easy transactions because I wanted to test if it is possible to execute the script on different PCs with different windows and SAP users. During the testing phase I bumped into one bigger Problem.

In my company every user has the Office Integration which allows you to display (f.e. a Profit Center Report as) an Excel Document in SAP. This display setting is saved permanently.

Now the main problem is that if you record the script with Excel display deactivated and some other users execute the script with Excel display actived the script will not process.

Usually I disable the Excel display setting manually by:

  • clicking System -> User default -> Personal Settings -> Parameter -> Parameter value for G_RW_DOCUMENT_TYPE from XLS to 0

I tried to record this process with the SAP GUI Scripting recorder but it does not record the whole process.

It only records this

session.findById("wnd[0]").maximize
session.findById("wnd[0]/mbar/menu[4]/menu[2]/menu[3]").select

the script does not record the change in parameter value

Is there a way (by adding a code line etc.) for automatically disabling the Excel display setting from active to inactive?


Solution

  • SAP GUI script recorder records the commands only in 1st mode. After the command

    session.findById("wnd[0]/mbar/menu[4]/menu[2]/menu[3]").select
    

    opens a new mode.

    But you can also start the transaction directly and remain in 1st mode.

    for example:

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

    Now that you know that, the problem could be solved as follows:

    session.findById("wnd[0]").maximize
    session.findById("wnd[0]/tbar[0]/okcd").text = "/nsu3"
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpPARAM").select
    session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpPARAM/ssubMAINAREA:SAPLSUID_MAINTENANCE:1104/cntlG_PARAMETER_CONTAINER/shellcont/shell").pressToolbarButton "&FIND"
    session.findById("wnd[1]/usr/chkGS_SEARCH-EXACT_WORD").selected = true
    session.findById("wnd[1]/usr/txtGS_SEARCH-VALUE").text = "G_RW_DOCUMENT_TYPE"
    session.findById("wnd[1]/usr/chkGS_SEARCH-EXACT_WORD").setFocus
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    session.findById("wnd[1]").close
    
    myRow = session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpPARAM/ssubMAINAREA:SAPLSUID_MAINTENANCE:1104/cntlG_PARAMETER_CONTAINER/shellcont/shell").currentCellRow
    session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpPARAM/ssubMAINAREA:SAPLSUID_MAINTENANCE:1104/cntlG_PARAMETER_CONTAINER/shellcont/shell").modifyCell myRow,"PARVA","0"      'instead of "XLS"
    session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpPARAM/ssubMAINAREA:SAPLSUID_MAINTENANCE:1104/cntlG_PARAMETER_CONTAINER/shellcont/shell").currentCellColumn = "PARVA"
    session.findById("wnd[0]/tbar[0]/btn[11]").press
    

    Regards, ScriptMan