SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Exitcode and Program Type Jobs

 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Exitcode and Program Type Jobs
Author Message
Victor Neto



Joined: 03 Nov 2004
Posts: 17

Post Exitcode and Program Type Jobs Reply with quote

Hi,

1. I am trying to setup a SAS job as

a Program Type job.

2. I used the NEW Job 24x7 dialog to setup my job:

( run program or document file )

3. In the Command Line Text Box I specified:

c:\prodexec\prodexec.bat comscat smb test001

The prodexec.bat batch file calls the SAS program

TEST001 and passes it several parameters. The batch

file allows me to start the SAS program with

minimal parameters as they are inside the batch file.

4. In the Successful Exit Code text box, I specified:

0 ( Zero! )

5. I forced the SAS program to abort with a return

code of 8.

data _null_;

abort return 8;

run;

6. I ran the job and looked at the job statistics

and the exit code was 0.

Questions:

1. Does the Successful exit code field not work?

2. Can I not use the run Program option If I specify

a batch file in the command line?

3. How can I capture the exit code from a SAS program

that is called from a batch file?

Thanks Vic

What am I doing wrings ca



Wed Jan 05, 2005 12:32 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7969

Post Re: Exitcode and Program Type Jobs Reply with quote

Having SAS job exiting with code 8 is not the same as having batch file exiting with that exit code. In your case 24x7 runs the batch file and checks the exit code of the called process (which is exit code of "cmd.exe") not the exit code of child processes invoked fro mthe batch. Therfore if you don't make the batch file to "save" somewhere SAS exit code you cannot capture it in 24x7.

To remedy that use the ERRORLEVEL variable in your batch file to detect SAS exit code and pass it back using an environment variable.
You can add the following lines in your batch file after invoking SAS:

... run sas command here ...
if NOT errorlevel 0 goto abort
SAS_RET_CODE=0
exit
:abort
set SAS_RET_CODE=%errorlevel%

Now, convert your program type job in 24x7 to a JAL script type job and paste the followng litle script

Dim( process_id, number )
Dim( sas_success, boolean )
RunAndWait( "c:\prodexec\prodexec.bat", "", 0, process_id )
IsEqual( 0, @V"env:SAS_RET_CODE", sas_success )

If( sas_success, HANDLE_SUCCESS, HANDLE_FAILURE )
HANDLE_SUCCESS:
//... code here what you want to do on success
Exit

HANDLE_FAILURE:
//... code here what you want to do on failure, for example
RaiseError "SAS process completed with exit code @V"env:SAS_RET_CODE""

Hope this helps.
By the way, why do you need a batch file to run SAS, why not to run it directly?

: Hi,

: 1. I am trying to setup a SAS job as

: a Program Type job.

: 2. I used the NEW Job 24x7 dialog to setup my job: ( run program or document
: file )

: 3. In the Command Line Text Box I specified: c:\prodexec\prodexec.bat comscat
: smb test001

: The prodexec.bat batch file calls the SAS program

: TEST001 and passes it several parameters. The batch

: file allows me to start the SAS program with

: minimal parameters as they are inside the batch file.

: 4. In the Successful Exit Code text box, I specified: 0 ( Zero! )

: 5. I forced the SAS program to abort with a return

: code of 8.

: data _null_;

: abort return 8;

: run;

: 6. I ran the job and looked at the job statistics

: and the exit code was 0.

: Questions: 1. Does the Successful exit code field not work?

: 2. Can I not use the run Program option If I specify

: a batch file in the command line?

: 3. How can I capture the exit code from a SAS program

: that is called from a batch file?

: Thanks Vic

: What am I doing wrings ca

Wed Jan 05, 2005 1:57 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7969

Post Re: Exitcode and Program Type Jobs Reply with quote

correction, the addition to the batch file can be as simple as just one line added after invoking SAS program.
set SAS_RET_CODE=%errorlevel%

: Having SAS job exiting with code 8 is not the same as having batch file
: exiting with that exit code. In your case 24x7 runs the batch file and
: checks the exit code of the called process (which is exit code of
: "cmd.exe") not the exit code of child processes invoked fro mthe
: batch. Therfore if you don't make the batch file to "save"
: somewhere SAS exit code you cannot capture it in 24x7.

: To remedy that use the ERRORLEVEL variable in your batch file to detect SAS
: exit code and pass it back using an environment variable.
: You can add the following lines in your batch file after invoking SAS: ...
: run sas command here ...
: if NOT errorlevel 0 goto abort
: SAS_RET_CODE=0
: exit
: set SAS_RET_CODE=%errorlevel%

: Now, convert your program type job in 24x7 to a JAL script type job and paste
: the followng litle script

: Dim( process_id, number )
: Dim( sas_success, boolean )
: RunAndWait( "c:\prodexec\prodexec.bat", "", 0, process_id
: )
: IsEqual( 0, @V"env:SAS_RET_CODE", sas_success )

: If( sas_success, HANDLE_SUCCESS, HANDLE_FAILURE )
: HANDLE_SUCCESS: //... code here what you want to do on success
: Exit

: HANDLE_FAILURE: //... code here what you want to do on failure, for example
: RaiseError "SAS process completed with exit code
: @V"env:SAS_RET_CODE""

: Hope this helps.
: By the way, why do you need a batch file to run SAS, why not to run it
: directly?

Wed Jan 05, 2005 2:00 pm View user's profile Send private message
Victor Neto



Joined: 03 Nov 2004
Posts: 17

Post Re: Exitcode and Program Type Jobs Reply with quote

: correction, the addition to the batch file can be as simple as just one line
: added after invoking SAS program.
: set SAS_RET_CODE=%errorlevel%

Hello,

Thanks for the quick response.

I call a batch file: prodexec.bat because to call sas
directly requires passing several parameters:

c:\program files\sas\sas 9.1\sas.exe
-sysin c:\my_program_directory\%PGMNAME%.sas
-autoexec c:\my_macro_directory\autoexec.sas
-log c:\Archive\%APPCODE%\%PGMNAME%_%DATE%_%TIME%_saslog.txt
-nosplash
-icon
-sysparm "%APPLIB% %APPCODE% %PGMNAME%"

Wrapping the call to SAS makes it much simpler as
I only pass three parameters to the PRODEXEC.BAT file.
Everthing else is inside the batch file.

I was thinking of converting my batch file into
a vbscript routine / template and add the exitcode
logic to the script file.

Ideally, I would like to call a script file Like:

c:\prodexec\wscript prodexec.vbs comscat smb smb001

where: comscat is the library reference where

the program is stored.

smb is the sas catalog name where the SAS

program isstored.

smb001 is the name of the program.

This simplifies the calling of the SAS program.

Is there a way that I can use the 24x7 script file template and
pass it variable parameters?


Wed Jan 05, 2005 2:29 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7969

Post Re: Exitcode and Program Type Jobs Reply with quote

Yes, you can create a job template to do that. The Template Builder utility can be found under the Tools menu. The template can then have 3 prompts for the 3 variable parameters and automatically generate the required VBscript job or program type job to call external VBscript file.

To be honest with you don't see any advantages in using an external VBscript file or batch file, parsing parameters, returning errors, separately handling errors from child process, etc.., when all this can be done in a much more simple way inside 24x7, including automatic error handling.

It seems to me that the way you trying to "wrap" SAS calls makes job handling much more complicated. It prevents direct access to the process exit code, it disables automatic job error handling, it creates unnecessary external dependencies, and so on. You can create a simple 3 to 5 line script (either JAL or VBScript) inside 24x7 to handle all that. Shall you need to run another SAS program you simply create another job using "create from job" link and then change program name in the copied script. The only advantage of your method (as I see it) it makes the job command line more readable. Please correct me if I am wrong.

: Hello,

: Thanks for the quick response.

: I call a batch file: prodexec.bat because to call sas
: directly requires passing several parameters: c:\program files\sas\sas
: 9.1\sas.exe
: -sysin c:\my_program_directory\%PGMNAME%.sas
: -autoexec c:\my_macro_directory\autoexec.sas
: -log c:\Archive\%APPCODE%\%PGMNAME%_%DATE%_%TIME%_saslog.txt
: -nosplash
: -icon
: -sysparm "%APPLIB% %APPCODE% %PGMNAME%"

: Wrapping the call to SAS makes it much simpler as
: I only pass three parameters to the PRODEXEC.BAT file.
: Everthing else is inside the batch file.

: I was thinking of converting my batch file into
: a vbscript routine / template and add the exitcode
: logic to the script file.

: Ideally, I would like to call a script file Like: c:\prodexec\wscript
: prodexec.vbs comscat smb smb001

: where: comscat is the library reference where

: the program is stored.

: smb is the sas catalog name where the SAS

: program isstored.

: smb001 is the name of the program.

: This simplifies the calling of the SAS program.

: Is there a way that I can use the 24x7 script file template and
: pass it variable parameters?

Wed Jan 05, 2005 2:51 pm View user's profile Send private message
Victor Neto



Joined: 03 Nov 2004
Posts: 17

Post Re: Exitcode and Program Type Jobs Reply with quote

: Yes, you can create a job template to do that. The Template Builder utility
: can be found under the Tools menu. The template can then have 3 prompts
: for the 3 variable parameters and automatically generate the required
: VBscript job or program type job to call external VBscript file.

: To be honest with you don't see any advantages in using an external VBscript
: file or batch file, parsing parameters, returning errors, separately
: handling errors from child process, etc.., when all this can be done in a
: much more simple way inside 24x7, including automatic error handling.

: It seems to me that the way you trying to "wrap" SAS calls makes
: job handling much more complicated. It prevents direct access to the
: process exit code, it disables automatic job error handling, it creates
: unnecessary external dependencies, and so on. You can create a simple 3 to
: 5 line script (either JAL or VBScript) inside 24x7 to handle all that.
: Shall you need to run another SAS program you simply create another job
: using "create from job" link and then change program name in the
: copied script. The only advantage of your method (as I see it) it makes
: the job command line more readable. Please correct me if I am wrong.

Hi Again,

My main reason for using a batch file, is that there
are several paths and parameters which I need to
specify when starting up a SAS program such as:

1. the SAS executable directory path.
2. the SAS macro library path and autoexec macro

that initializes the sas environment.
3. the User Application Program Library path.
4. The SAS Log directory path where the program logs

are stored.
5. A custom SAS log dataset name that contains the

program name, date and time of the run.
6. A program name that is used to call the program

and to name the sas log dataset.
7. And some SAS input runtime parameters.

I really don't want to hard-code them each time I
setup a program in 24x7. This makes the maintenance
of the jobs much tougher. When we upgrade the SAS
software, the execution library may change. This
means that I would have to edit all the jobs in 24x7.

I need something that is easy to setup and it is
easy to maintain when the directories change.

SAS has a tendancy to change the directory path
when the software version changes.

Is it possible to have a job template that references
global variables.

These global variables would refer to these common
directories that may change from time to time ?

example 1a. These would be global variables:

sas_lib = c:\program files\sas\sas 9.1
auto_exec_lib = p:\common\macros
app_pgm_lib = p:\smb\programs
sas_log_lib = p:\archive\smb

Example 1b. These would be template prompts:

applib = comscat
appcode = smb
pgmname = smb00001

If you have any ideas, it would be greatly appreciated.

Thanks Vic


Wed Jan 05, 2005 4:31 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7969

Post Re: Exitcode and Program Type Jobs Reply with quote

Sorry, I missed your yesterday's reply, …didn't see it until now.
…..
Even if you put them into batch files or external scripts you still need to modify all these files if SAS library path changes. Don't you?

If you use internal 24x7 scripts you can then store common parameters in an .INI file, registry or just put them into global variables initialized on 24x7 startup. That's what some people do, they write an "init" job to set global variables and then use them in other scripts as constants. This "init" job has [on startup] schedule type.

I personally prefer using .INI files because this method is very simple, doesn't require extra jobs, and every change is global, it is "seen" immediately by all jobs. Reading values from .INI files is also simple -> IniFileGetKey.

On the other hand, if SAS settings are already stored somewhere in the registry you can read them directly from there and if they change after new version install you don't need to do anything. Jobs will find new settings automatically.

: Hi Again,

: My main reason for using a batch file, is that there
: are several paths and parameters which I need to
: specify when starting up a SAS program such as: 1. the SAS executable
: directory path.
: 2. the SAS macro library path and autoexec macro

: that initializes the sas environment.
: 3. the User Application Program Library path.
: 4. The SAS Log directory path where the program logs

: are stored.
: 5. A custom SAS log dataset name that contains the

: program name, date and time of the run.
: 6. A program name that is used to call the program

: and to name the sas log dataset.
: 7. And some SAS input runtime parameters.

: I really don't want to hard-code them each time I
: setup a program in 24x7. This makes the maintenance
: of the jobs much tougher. When we upgrade the SAS
: software, the execution library may change. This
: means that I would have to edit all the jobs in 24x7.

: I need something that is easy to setup and it is
: easy to maintain when the directories change.

: SAS has a tendancy to change the directory path
: when the software version changes.

: Is it possible to have a job template that references
: global variables.

: These global variables would refer to these common
: directories that may change from time to time ?

: example 1a. These would be global variables: sas_lib = c:\program
: files\sas\sas 9.1
: auto_exec_lib = p:\common\macros
: app_pgm_lib = p:\smb\programs
: sas_log_lib = p:\archive\smb

: Example 1b. These would be template prompts: applib = comscat
: appcode = smb
: pgmname = smb00001

: If you have any ideas, it would be greatly appreciated.

: Thanks Vic

Thu Jan 06, 2005 6:13 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.