There are very simple AS/400 utilities written on CL/400.
May be it will be useful for beginners to understand one of my prefered methods:
creating complex program using small bricks of this kind.
The program counts total number of records in all members of physical file
and returns this number as parameter. It is good for use by another CL, RPG
and etc. programs.
The program counts total number of index entries in all members of logical file
and returns this number as parameter. It is good for use by another CL, RPG
and etc. programs.
PARAMETERS:
- INPUT:
&LIB - library name
&FILE - logical file name
- OUTPUT:
&TOTAL - total number of index entries
&PERR - error flag:
'0' - completed successfuly
'1' - error occured
'2' - file does not exist
'3' - file has no members
How to do something with each member of physical file.
The program does an action with EACH member of physical file.
It summarizes and devolopes an idea of the two previous programs,
and is also good for use by another CL, RPG and etc. programs.
PARAMETERS:
- INPUT:
&LIB - library name
&FILE - file name
&PGM - program that does something concrete with member.
It has parameters (&LIB &FILE &MEMBER &NREC &PERR).
The &PGM receives:
&LIB &FILE &MEMBER - member to do;
&NREC is number of records in &MEMBER.
The &PGM returns in &PERR:
'0' if successful complete,
'1' if error.
&STOP - continue processing ('Y'/'N') if &PGM returned
error (P&ERR='1') for a current member
- OUTPUT:
&PERR - error flag:
'0' - completed successfuly
'1' - error occured
'2' - file does not exist
'3' - file has no members
'4' - file is in use (locked)
How to do something with each member of logical file.
VRUNQRYC
Uses mentioned above programs
V89_CL and
V88_CL,
and special program V87_CL that run query for one member.
DESCRIPTION:
As example of using previous program here is simple utility that
perform an run query for all members of physical or logical file.
The program displays query report for EACH member of file.
To pass to program V87_CL additional specific parameter which not included in
its standard parameters list an userspace was used. VRUNQRYC creates an userspace
and populates it whit value of additional parameter &RCDSEL, and V87_CL
retrieves from the userspace value of this parameter.
PARAMETERS:
- INPUT:
&FULLFILE - qualified file name
&RCDSEL - select record for query (Y/N)
YOU CAN:
Create a command VRUNQRY using CMD source file
VRUNQRY: