Call Extractions via Script
This section shows how to call an extraction from a Windows script (.bat) or PowerShell script using the command line tool xu.exe.
Call via Windows script (.bat)
Follow the steps below to run an extraction using a Windows script that calls the command line tool xu.exe.
- Create a new batch file.
-
Define the following variables:
- Standard output (XUOutputfile)
- Standard error output (XULogfile)
- Path to the command line tool (XUCmd)
- XU server name (XUServer)
- XU server port (XUPort)
- Name of the extraction (XUExtraction)
:: Execute an Xtract Universal extraction using the command tool xu.exe :: clear screen cls :: Turns off the command echoing feature @echo off :: write the output to a file set XUOutputfile="C:\Data\xubatch\output.txt" :: write the log to a file set XULogfile="C:\Data\xubatch\log.txt" :: set the path to the installation folder set XUCmd="C:\Program Files\XtractUniversal\xu.exe" :: default is also localhost, so you skip it or change it set XUServer=localhost :: default port is also 8065, so you skip it or change it set XUPort=8065 set XUExtraction=customers
-
If the extraction requires input parameters, set dynamic parameters, e.g., v_country for the language key.
-
Run the extraction by calling the command line tool with the corresponding parameters.
@echo off :: create an array with extraction names separated by empty space :: in this example there are two extractions named *customers* and *materials*. set extraction_list=customers materials :: alternative :: set extraction_list[0] = customers :: set extraction_list[1] = materials @echo on for %%e in (%extraction_list%) do ( %XUCmd% -s %XUServer% -p %XUPort% -n %%e 1>>%XUOutputfile% 2>>%XULogfile% ) :: The output in this example is added to the existing file with >>.
-
Check the return code and write a corresponding message. The return code 0 indicates a successful execution. Other Return Codes indicate errors during execution.
-
Optional: extractions can be added to the Windows logs. They can be displayed in the Event Viewer.
Call via PowerShell Script
Follow the steps below to run an extraction using a PowerShell script that calls the command line tool xu.exe.
-
Define the following variables:
- Standard output (XUOutputfile)
- Standard error output (XULogfile)
- Path to the command line tool (XUCmd)
- XU server name (XUServer)
- XU server port (XUPort)
- Name of the extraction (XUExtraction)
# Execute an Xtract Universal extraction using the command tool xu.exe # clear screen clear # write the output to a file $XUOutputfile = "C:\Data\powershell\output.txt" # write the log to a file $XULogfile = "C:\Data\powershell\log.txt" # set the path to the installation folder $XUCmd = 'C:\Program Files\XtractUniversal\xu.exe' $XUServer = "localhost" $XUPort = "8065" $XUExtraction = "SAPSalesCube"
-
If the extraction requires input parameters, set dynamic parameters, e.g., myCalendarMonth for the current month in the format "yyyyMM".
# the extraction has a variable CalendarMonth that needs a value in the format "yyyyMM", e.g. 201712 # Skip this block if you don't use variable # generate the calender month from the current date to be used as a variable # e.g. Tuesday, December 19, 2017 10:40:32 AM $myyear = (Get-Date -format "yyyy") $mymonth = (Get-Date -format "MM") # 201712 $myCalendarMonth = "$myyear$mymonth" # another option Get-Date -format "yyyyMM" # just if you use variables # the extraction has a variable CalendarMonth, its value has the format YYYYMM # set the variable for calendar month e.g. 201712
-
Run the extraction by calling the command line tool with the corresponding parameters.
-
Check the return code and write a corresponding message. The return code 0 indicates a successful execution. Other Return Codes indicate errors during execution.
For more examples on how to use PowerShell scripts with Xtract Universal, see SAP Access with Xtract Universal and Powershell
Related Links:
- Create Extractions via Commandline
- Insert Extraction Events into Windows Logs
- SAP Access with Xtract Universal and Powershell