TechTalk: Self-submitting CL Programs

System Administration
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Q.I am designing a Cost Accounting application for the furniture manufacturing firm where I work. The Finance staff wants me to design many different reports, and each report should be available by taking an option from a menu. My problem is that I end up writing two CL programs: one to prompt for the report options and the other to actually generate the report. The first CL program runs the Submit Job (SBMJOB) command to place the second program in a job queue. I remember doing this hundreds of times on the S/36 with the // IF JOBQ statement. Is there a simple way to do the same on the AS/400?

A.Yes, there's a way. Your CL program needs a 1-byte character variable and the Retrieve Job Attributes (RTVJOBA) command, which can determine if the program is running interactively or in batch. Let's create a self-submitting CL program named PGM1; refer to 5 on page 67.

A.Yes, there's a way. Your CL program needs a 1-byte character variable and the Retrieve Job Attributes (RTVJOBA) command, which can determine if the program is running interactively or in batch. Let's create a self-submitting CL program named PGM1; refer to Figure 5 on page 67.

When this program is called by taking an option from a menu, it runs interactively. The RTVJOBA command assigns &JOBTYPE a value of 1, which makes the IF command fail, so the program displays the options panel with the SNDRCVF command. When the user presses Enter, the CL program runs SBMJOB to submit itself to the job queue.

When the program begins running from the job queue, the RTVJOBA command assigns '0' to variable &JOBTYPE; the IF command then transfers control to tag EXEC, bypassing the SNDRCVF and SBMJOB commands and going directly to the portion that generates the report.


TechTalk: Self-submitting CL Programs

Figure 5 Sample self-submitting CL program

 Figure 5: Sample Self-submitting CL Program PGM1: PGM PARM(&PARM1 &PARM2 &PARM3) DCL VAR(&JOBTYPE) TYPE(*CHAR) LEN(1) DCLF FILE(OPTIONS) RTVJOBA TYPE(&JOBTYPE) IF COND(&JOBTYPE *EQ '0') THEN(GOTO CMDLBL(EXEC)) /* Present options display */ SNDRCVF SBMJOB CMD(CALL PGM(PGM1) PARM(&PARM1 &PARM2 &PARM3)) + JOB(REPORT) JOBQ(QBATCH) RETURN /* Generate report */ EXEC: (etc.) ENDPGM 
BLOG COMMENTS POWERED BY DISQUS