Pre-Run and Post-Run Process from Process Runner

Previous  Top  Next

Process Runner offers Pre-run or Post-run execution of other programs or scripts.

Process Runner offers many advanced SAP automation capabilities. However, if you want to further extend these capabilities with external processes, you can do so with Pre and Post run integration that Process Runner offers.

With Pre/Post Run integration feature, any external .Exe (standard Executable), .Bat (Batch file), .VBS (VB script) or .JS (Java Script) file can be executed before or after each run.

Externally called process can also receive important parameters from Process Runner that can be utilized to execute its own logic.

The called processes can also communicate back to Process Runner at the end to provide end to end integration.

Additionally there is an option to store VB or Java scripts internally with the process file using convenient iScript option.

 

Some of the examples where you may use Pre/Post run external processes are:

Send automatic e-mail or SMS text message at the end of the each run with status of the run and error count etc. Refer Example.
Look at a mount application server, Unix mount point and move the file(s) to appropriate location before or after each run.
Run a macro to calculate, summarize or perform formatting of external data before each run.
Push downloaded data/report to proprietary software or call third party importer routine.
Trigger another application before or after the run.
Many more...

 

In summary: With combination of in-process extensibility of Dynamic Skips, Dynamic Formulas and with Pre-Run and Post-Run integration as described in this document, you can create cross platform and flexible automation solutions for the most demanding needs.

Screen below shows how to access Pre and Post Run controls.

clip0063

 

 

You can do the necessary settings in following screen by click “Pre/Post Run Process…” button on Advance Tab. To enabled this feature click “Enable Pre and Post External Process” box.

hmtoggle_plus1Pre-Run / Post-Run Process feature – Technical information

Below is how Pre and Post run configuration looks like. You can write and store VB/Java scripts in Pre-Run iScript tab and Post-Run iScript tab.  Scripts stored inside iScript tabs will be saved inside your Process file and will always be available.

clip0064

 

You can individually set either pre-run or post-run process or both.

If you want any external process to run BEFORE regular Process Runner task, you can that set by checking “Pre-Run Process Settings” box.  Similarly if you want any external process to run AFTER regular Process Runner task, you can set by checking “Post-Run Process Settings” box.

External process could be an externally stored Executable (.EXE), Batch (.BAT), Visual Basic scripts (.VBS), Java Scripts (.JS) or internally stored Visual Basic or Java scripts. Internally stored scripts are known as iScripts.

For External file, you can select file that you want to execute as well as pass necessary parameters to that file as follows:

1.   Select File: Here you can choose file you wish to run before/after Process Runner task. You can choose from .Exe, .Bat, .VBS or .JS file.

2.   Parameters: If the external file requires any command line parameters, you can provide them here. You can also choose standard parameters for the context menu there or by clicking ellipse at the end of the text box to get list. Each parameters must be separated by comma.

Next is execution flow setting for controlling process runner task run when external process is busy or terminated. The settings are:

1.   Wait options:  This setting is done when you want process runner task to wait or continue without waiting for external process to terminate. Options are

a.   1-No Wait: By setting this, the Process Runner task will not wait for the external process to finish and proceed.

b.   2-Wait until terminated: By setting this, the Process Runner task waits till the external process finishes completely.

c.   3-Wait until second: By setting this, the Process Runner tasks wait for that many seconds given and then proceed . If the external process finishes by that time, the exit code is trapped else ignored.

2.   Stop on error: When you check this box, the Process Runner task stops as the external process return error exit code(non zero). This box is disabled when you select “1-No Wait” as wait option.

If process type is transaction (TX),  you can also control behavior for additional run types as follows:

1.   Run with normal run:  The process will be executed in normal run mode.

2.   Test Run: The process will be executed in Test Run mode also.

3.   Run with Debug: The process will be executed in Run – Debug All and Run – Debug Error mode also.

4.   Run with Error Processing: The process will be executed in Error Processing Run mode also.

hmtoggle_plus1Internally stored Scripts or iScripts

Process Runner also facilitates iScript feature where you can write and store your own VB script or Java Script and execute it before or after regular process runner tasks. You can maintain independent scripts for pre-run and post-run.

Pre-Run iScript

clip0065

 

Post-Run iScript

clip0066

hmtoggle_plus1Process Runner Variables in external process

Following is a list of variables which can be passed from Process Runner to external process as a parameters or variables. These will help external process to consume them in their internal logic with much tighter integration.

Variable name

Description

Comments and Examples

#CURPRTYPE#

Type of the current process i.e. TX, BA, GS or DE

TX  for Transaction or BA for BAPI/RFM  or  GS for GUI Script  or DE for Data Extractor

#CURPROC#

Process/table/BAPI name that you are using for current process

MM02, MARC, BAPI_CREATE_CONTRACT etc.

"#CURPRFILE#"

Name of the current process file along with full path

C:\Innowera\MRRC.ite

C:\Innowera\MM03.itf

#CURXLFILE#

Excel file being used for current process along with full path

e.g. C:\Innowera\test.xls

#CURXLSHEET#

Excel Sheet name being used

Sheet1, Sheet2 …

#CURSAPSYS#

Name of SAP system ID

PR1, DEV, QAS…

#SAPUSR#

SAP user name

JSMITH

#SAPLAN#

SAP system language user has chosen while logging to SAP

EN,FR,DE

#SAPCLIENT#

SAP client number

101, 800

#NOOFREC#

Number of records extracted by Process Runner (Available only in Data Extractor processes)

20000

#NOOFCALL#

Number of finished calls after a process completed (Available only in Transaction processes)

550

#RUNTYPE#

Type of run user has chosen from normal run, test run, debug run or error processing run. (Available only in Transaction processes)

1 for Run or 2 for Test Run or 3 for Error Processing Run or 4 for Debug Run

#ERRORCOUNT#

No. of error count  ( Available in Transaction processes )

5

#ERRORSTAT#

Error status of the process runner task

1 = Error , 0 = Success

#ERRORMSG#

Error message trapped by the application when process runner error status is 1

Specify account number

SAP Front end Server: The method got an invalid argument.

#XLDATASTARTROW#

Starting row of data in the worksheet chosen while running any task

10

#XLDATAENDROW#

Ending row of data in the worksheet chosen while running any task

100

#XLDATALOGCOL#

Log column

0

#ISMASTERPROCESS#

Is the process a master process or not

1 when its master process else 0

#MASTERXLFILE#

Name of the Excel file used in master process

C:\Documents\Try.xls

#MASTERXLSHEET#

Name of the Excel sheet used in master process

Sheet1, Sheet2

#MASTERXLDATASTARTROW#

Starting row number in master process

2, 5

#MASTERXLDATAENDROW#

Ending row number in master process

100, 1000

hmtoggle_plus1Controlling Process Runner from external process with Return Code

External process can tell Process Runner if it should continue further or stop.  External process can return 0 to indicate that there was no problem and Process Runner should continue further. Or it can return 1 and indicate that there was a problem and Process Runner should not continue further.

Note: This works only if you asked Process Runner to wait for external process. If Process Runner was setup not to wait, it will ignore Return Code and always continue further. Refer to table below for various possibilities.

 

Script Return

Wait Option

Stop On Error Settings

PR behavior

0

No Wait

N/A

Process Runner always continues further

1

No Wait

N/A

Process Runner always continues further

0

Wait until terminated

Unchecked

It waits till all messages are responded and then executes ahead

1

Wait until terminated

Unchecked

It waits till all messages are responded and then executes ahead

0

Wait until seconds (2)

Unchecked

It waits for 2 seconds to respond and then executes ahead

1

Wait until seconds (2)

Unchecked

It waits for 2 seconds to respond and then executes ahead

0

Wait until terminated

Checked

It waits till all messages are responded and then executes ahead since there is no error retuned by script

1

Wait until terminated

Checked

It waits till all messages are responded and then returns without  executing ahead

0

Wait until seconds (2)

Unchecked

It waits for 2 seconds to respond. If user responds during that time , error code is trapped and in this case there is no error so executes ahead. If used doesn’t respond during that time, it just moves ahead without trapping error code.

1

Wait until seconds (2)

Unchecked

It waits for 2 seconds to respond. If user responds during that time, error code is trapped and in this case there is error so execution stops. If used doesn’t respond during that time, it just moves ahead without trapping error code.

 

Here is an example of a VB script file with return error and its behavior with process settings.

     dim a    '---- var declaration

     a = Inputbox("Enter number")     '----Accept value of a from keyboard

     if a >= 10 then   '----Check value of a

                 msgbox 100      '----Show 100

                 wscript.quit(0) '---- Error code 0 is returned (No error state)

     else

                             if a >= 0 then     '----Check value of a

                                         msgbox a          '----Show 10

                                         wscript.quit(0) '---- Error code 0 is returned (No error state)

                             else

                                         msgbox -1         '----Show -1

                                         wscript.quit(1) '---- Error code 1 is returned (Error state)

                             end if    '----Close if

     end if    '----Close if

This script takes parameters from command line and shows them one by one and terminates with error code 0 (no error).  If no parameter is give, it shows messages and terminates with error code 1.

Similarly you can write a Java script as well, here is an example.

This will repeat any statement within the while loop 100 times. It will increment loop variable after each iteration.

     a = 1;    //----initialization of a

     while ( a <= 100 )          //----check value of a, if it is <= 100

     {

                  //----comment statement

                  //----write any code that you want to repeat here

                  i++;     //----increment the loop control variable a

     }           //----close loop

 

For trapping error generated from external application, the process runner uses one environment variable called PRERRORLEVEL and PRERRORMSG. When the external process wants to return some value as exit status to process runner program, they can use this environment variable and set its value to desired exit code they want. Process Runner’s Pre-run or Post-run execution feature can trap this value and control further processing accordingly. The process runner program considers non zero value of that variable as an error state and zero as a success. Same way if someone wants to get some error message back to process runner, they can use this PRERRORMSG environment variable.