# Sap script for previous day



## Neo Gotcha (Jun 3, 2019)

Dear all,

i'm facing a problem running an SAP SCRIPT, actually i'm running VL06F transaction automatically to generate a sales report from the beginning of the month up to date ashown in the code below, can you help me to find what to change in order to set the ending date to the previous date than the actual date:


```
session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").focusDate = "20190603"
```

below the entire code:


```
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]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nvl06f"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[0]/usr/ctxtIT_WTIST-HIGH").setFocus
session.findById("wnd[0]/usr/ctxtIT_WTIST-HIGH").caretPosition = 0
session.findById("wnd[0]").sendVKey 4
session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").focusDate = "20190603"
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
```

thank you for your support.


----------



## jkpieterse (Jun 3, 2019)

Replace the date string literal "20190603" with:

```
Format(Date-1,"yyyymmdd")
```
This will always return yesterdays date in a string of the proper format.


----------



## Neo Gotcha (Jun 6, 2019)

dear jkpieterse,

i used these code but it gives me an error, seems that the function "format" is not taken in consideration, the error code is 800A000D.
Is there a solution to these problem?

Regards.


----------



## jkpieterse (Jun 6, 2019)

OK, I thought the code you gave is VBA code.


----------



## Neo Gotcha (Jun 6, 2019)

jkpieterse said:


> OK, I thought the code you gave is VBA code.


 
i'll explain i'm using SAP ERP which have a recording option which saved as a script, the code i shared is the one that was generated, so i'm trying to modify it when i used (Date-1) it run normal but it gaves a date format as yyyy/mm/dd, unfortunately SAP read format as yyyy.mm.dd

do you think it can be modified.

thanks a lot for your support.

regards.


----------



## Neo Gotcha (Jun 6, 2019)

dear Jan,

i think i foud the solution, since the code generated from SAP is a VBS code the solution is to replace as below:


```
replace(Date-1, "/", ".")
```

thank you for your patience.

regards.


----------

