Check if xls-file in SAP

396 views Asked by At

I have to export automatically several xls-files out of the SAP to create the specific reports. So far I used the SAP GUI Scripting to enter the transaction code and the DIR-Number (which is unique for each document). This works perfectly when I download just one xls-file. I have to download more than one xls though.

As you can see in the image the xls-file is in the second position, that means with my script it just exports all the files, which are located in second position. For example, if there is a PDF in second position, it exports automatically the PDF, then I can`t create a report.

SAP GUI to show the position

Set xmlDoc = CreateObject("MSXML.DomDocument")
xmlDoc.Load "C:\Users\famichalsk\AppData\Roaming\KPI Report\DIS.xml" 


For Each testNode In xmlDoc.selectNodes("/Reports/Report")

Number_PDP = testNode.SelectSingleNode("DIS_PDP").Text

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]").iconify
session.findById("wnd[0]").resizeWorkingPane 132,31,false
session.findById("wnd[0]/tbar[0]/okcd").text = "/n cv04n"
session.findById("wnd[0]").sendVKey 0
         session.findById("wnd[0]/usr/tabsMAINSTRIP/tabpTAB1/ssubSUBSCRN:SAPLCV100:0401/s subSCR_MAIN:SAPLCV100:0402/ctxtSTDOKNR-LOW").text = Number_PDP
session.findById("wnd[0]/usr/tabsMAINSTRIP/tabpTAB1/ssubSUBSCRN:SAPLCV100:0401/ssubSCR_MAIN:SAPLCV100:0402/ctxtSTDOKNR-LOW").caretPosition = 12
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").doubleClickCurrentCell



session.findById("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").selectNode "          2"
session.findById("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/btnPB_DISPLAY").press


Next

The last two rows are the important ones, because here you select the second "Node" to export. Here I need to check if xls-file or not.

1

There are 1 answers

6
ScriptMan On

You could try the following Workaround. For example:

session.findById("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").selectNode "          2"
session.findById("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").itemContextMenu "          2"
session.findById("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").selectContextMenuItem "&FIND"
myText = session.findById("wnd[1]/usr/txtLVC_S_SEA-STRING").text
session.findById("wnd[1]/tbar[0]/btn[12]").press
if myText = "xyz" then 
session.findById("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/btnPB_DISPLAY").press
end if

It could be that the corresponding passage in the script would have to re-record.

Regards, ScriptMan