Eric Erikson FCC Consulting

View Original

EPM Automate: Using GetSubstVar with DOS Batch File

Summary: this post is about using the EPM Automate GetSubstVar command within a DOS batch script and then transforming the output into a usable variable.



With most every FCC implementation there are multiple EPM Automate processes. One of these is typically to load and consolidate the close period. A discussion that typically comes up is how to control the period and year for which the process is running.

Over the years I've preferred using a file on the EPM Automate server. The admin would set the period and year there (either within a file or just read the name of a file). There are other controls I like putting here, like to skip the process, to load or not to load exchange rates, etc.

There is a way to use the substitution variables within the application if this approach isn't desired. There is an EPM Automate command that gets substitution variables: GetSubstVar. 

First, log into the environment and use the getsubstvar command to get the variable. The parameters let you get variables from the application level or the cube level. You can also get all of the variables at those levels or just a specific one. Here, these commands are getting specific variables from the Consol cube and writing the output to text files.

call "c:\oracle\epm automate\bin\epmautomate" login 
call "c:\oracle\epm automate\bin\epmautomate" getsubstvar Consol name=CurrMonth >> currmonth.txt
call "c:\oracle\epm automate\bin\epmautomate" getsubstvar Consol name=CurrYear >> curryear.txt
call "c:\oracle\epm automate\bin\epmautomate" logout

The three line output of the two text files looks like this (excluding the filenames):

CURRMONTH.TXT
Processing...
 Consol.CurrMonth=Dec
getsubstvar completed successfully

CURRYEAR.TXT
Processing...
 Consol.CurrYear=FY19
getsubstvar completed successfully


The next step is to get the info that's needed from the files, namely the period and the year. Fortunately, the DOS batch command FOR can take care of that. FOR has many different options. Here are the two commands to run to pick out the month and year from the above.

for /f "tokens=2 delims==" %%i in (currmonth.txt) do (set currmonth=%%i)
for /f "tokens=2 delims==" %%i in (curryear.txt) do (set curryear=%%i)

NOTE: if running these commands within a batch file, the variable i is preceded with TWO % and if running manually from a command line use ONE % instead. Tokens=2 instructs FOR to read the second occurrence of what is found. Delims== instructs FOR to use = [the second one] as the delimiter. 

Last, if the script needs to pass the year to Data Management to run a data load rule, create a new variable to combine the month, a dash, and then the two digit year (strip off the FY).

set dmperiod=%currmonth%-%curryear:~2,2%

So now there are three variables. To verify, type:

echo %currmonth%
echo %curryear%
echo %dmperiod%