I have been noticing that many programmers are neglecting one of the nicest things on the AS/400: user define commands.
We use AS/400 commands all day long. Why not use commands for our own applications?
Have you ever had to convert numbers to strings just to send them as parameters?
Have you ever had to define CLP numeric parameter as 15(5) just to send a numeric parameter from the command line?
Have you ever had to call a program using hexadecimal format just to send a numeric parameter as pack (e.g. X'12345F') ?
If you answered yes, continue reading ...
We will be viewing a technique for submitting a report using a homegrown command.
* Please note that the parmeters go through with no hassle.
* It is possible to prompt on the command like any other AS/400 command.
* Commands source usually reside in QCMDSRC.
Source for command DEM601C
*********************************************
- Note the usage of DFT keyword
- The JOBTYP will control the flow of the program
I = prompt the user & submit the job
B = Go directly to the batch processing part
(Very useful if you want to debug the application interactively without
using STRSRVJOB)
CMD PROMPT('Command usage sample')
PARM KWD(JOBTYP) TYPE(*CHAR) LEN(1) RSTD(*YES) +
DFT(I) VALUES(I B) PROMPT('Job type')
PARM KWD(DATE_F) TYPE(*DEC) LEN(8 0) PROMPT('From +
Date')
PARM KWD(DATE_T) TYPE(*DEC) LEN(8 0) PROMPT('To +
Date')
PARM KWD(PART_C) TYPE(*CHAR) LEN(10) PROMPT('Part +
code')
PARM KWD(TRAN_C) TYPE(*CHAR) LEN(4) DFT(IS02) +
PROMPT('Transaction code')
Source for display file DEM601C
*********************************************
A DSPSIZ(24 80 *DS3)
A INDARA
A PRINT
A ERRSFL
A CF03(03)
A CF21(21)
A R REQUSET
A JOBTYP 1A H TEXT('Job type')
A 5 2'Date range.........'
A DATE_F 8Y 0B 5 22EDTWRD(' / / ')
A DSPATR(CS)
A 5 33'-'
A DATE_T 8Y 0B 5 35EDTWRD(' / / ')
A DSPATR(CS)
A 7 2'Part code..........'
A PART_C 10A B 7 22
A 9 2'Transaction code...'
A TRAN_C 4A B 9 22
A 23 3'F3=Exit'
A COLOR(BLU)
A 23 16'F21=Print list'
A COLOR(BLU)
Source for CL program DEM601C
*********************************************
PGM PARM(&JOBTYP &DATE_F &DATE_T &PART_C &TRAN_C)
DCLF FILE(DEM601C)
IF COND(&JOBTYP = B) THEN(DO) /* Jump to Batch */
GOTO CMDLBL(BATCH)
ENDDO
REQUEST: SNDRCVF RCDFMT(REQUSET)
IF COND(&IN21) THEN(DO)
SBMJOB CMD(DEM601C JOBTYP(B) DATE_F(&DATE_F) +
DATE_T(&DATE_T) PART_C(&PART_C) +
TRAN_C(&TRAN_C)) LOG(4 00 *MSG)
ENDDO
IF COND(&IN03) THEN(DO)
RETURN
ENDDO
GOTO CMDLBL(REQUEST)
RETURN
/*==================================================================*/
BATCH: /* Batch processing part */
ENDPGM
************************************************************
This was first published in May 2001