Skip to Content
avatar image
Former Member

SAP Script - just export Excel-Files for daily report

Hi there,

I have the following problem:

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.

Screenshot SAP GUI

Here`s my code:

' Reading the XML-File to pass unique number for each document
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

' Recorded SAP GUI Script to export the number above
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

' Here the unique number is passed
session.findById("wnd[0]/usr/tabsMAINSTRIP/tabpTAB1/ssubSUBSCRN:SAPLCV100:0401/ssubSCR_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

' Here is the problem, it just selects the second node, actually first I want to check if it is a xls-file, if not check the next position till you get the xls.

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

I hope you could understand my problem, sorry for my english. Thanks in advance.

Fabian

example.jpg (96.3 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers