NOTES:
EXECIO:
WRITE Parms:
STEM varname OPEN|FINISH
READ Parms:
(FIFO | OPEN FINISH SKIP )
LIFO |
STEM Varname
When you use EXECIO, you must ensure that you use
quotation marks around any operands, such as DISKW, STEM,
FINIS, or LIFO. Using quotation marks prevents the
possibility of the operands being substituted as
variables.
Lines:
The number of lines to be processed. This operand can be
a specific decimal number or an arbitrary number
indicated by *. When the operand is * and EXECIO is
reading from a data set, input is read until EXECIO
reaches the end of the data set.
DISKR
DISKRU
ddname
linenum
FINIS:
OPEN:
STEM var-name
The stem of the set of variables into which information
is to be placed. To place information in compound
variables, which allow for easy indexing, the var-name
should end with a period. For example,
MYVAR.
DROP MYVAR.
MYVAR. = ''
LIFO
Places information on the data stack in LIFO (last in
first out) order.
FIFO
Places information on the data stack in FIFO (first in
first out) order. FIFO is the default when neither
LIFO or FIFO is specified.
SKIP
Reads the specified number of lines but does not place
them on the data stack or in variables. When the number
of lines is *, EXECIO skips to the end of the data set.
ILLUSTRATIONS:
PARSE ARG name numlines /* Get data set name and size from user */
"ALLOC DA("name") F(UPDATEDD) OLD"
eof = 'NO' /* Initialize end-of-file flag */
DO i = 1 to numlines WHILE eof = no
"EXECIO 1 DISKRU UPDATEDD " /* Queue the next line on the stack */
IF RC = 2 THEN /* Return code indicates end-of-file */
eof = 'YES'
ELSE
DO
PARSE PULL line
SAY 'Please make changes to the following line.'
SAY 'If you have no changes, press ENTER.'
SAY line
PARSE PULL newline
IF newline = '' THEN NOP
ELSE
DO
PUSH newline
"EXECIO 1 DISKW UPDATEDD"
END
END
END
"EXECIO 0 DISKW UPDATEDD (FINIS"
9) This exec reads the first 100 records (or until EOF) of
the data set allocated to INVNTORY. Records are placed
on the data stack in LIFO order. A message is issued
that gives the result of the EXECIO operation.
eofflag = 2 /* Return code to indicate end of file */
"EXECIO 100 DISKR INVNTORY (LIFO"
return_code = RC
IF return_code = eofflag THEN
SAY 'Premature end of file.'
ELSE
SAY '100 Records read.'
EXIT return_code
10) This exec erases any existing data from the data set
FRED.WORKSET.FILE by opening the data set and then
closing it without writing any records. By doing this,
EXECIO just writes an end-of-file marker, which erases
any existing records in the data set.
Note that in this example, the EXECIO ... (OPEN command followed by
the EXECIO ... (FINIS command is equivalent to:
12) This exec opens the data set MY.WRKFILE and sets the
current record number to record 8 so that the next
EXECIO DISKR command begins reading at the eighth
record.
/*******************************************************************/
/* Read all records from 'sample1.data' and append them to the */
/* end of 'all.sample.data'. */
/*******************************************************************/
exec_RC = 0 /* Initialize exec return code */
"EXECIO * DISKR MYINDD1 (STEM NEWVAR. FINIS" /* Read all records */
if rc = 0 then /* If read was successful */
do
/*****************************************************************/
/* At this point, newvar.0 should be 20, indicating 20 records */
/* have been read. Stem variables newvar.1, newvar.2, ... through*/
/* newvar.20 will contain the 20 records that were read. */
/*****************************************************************/
say "-----------------------------------------------------"
say newvar.0 "records have been read from 'sample1.data': "
say
do i = 1 to newvar.0 /* Loop through all records */
say newvar.i /* Display the ith record */
end
"EXECIO" newvar.0 "DISKW MYOUTDD (STEM NEWVAR." /* Write exactly
the number of records read */
if rc = 0 then /* If write was successful */
do
say
say newvar.0 "records were written to 'all.sample.data'"
end
else
do
exec_RC = RC /* Save exec return code */
say
say "Error during 1st EXECIO ... DISKW, return code is " RC
say
end
end
else
do
exec_RC = RC /* Save exec return code */
say
say "Error during 1st EXECIO ... DISKR, return code is " RC
say
end
If exec_RC = 0 then /* If no errors so far... continue */
do
/***************************************************************/
/* At this time, the stem variables newvar.0 through newvar.20 */
/* will contain residual data from the previous EXECIO. We */
/* issue the "DROP newvar." instruction to clear these residual*/
/* values from the stem. */
/***************************************************************/
DROP newvar. /* Set all stems variables to their */
uninitialized state */
/***************************************************************/
/***************************************************************/
/* Read all records from 'sample2.data' and append them to the */
/* end of 'all.sample.data'. */
/***************************************************************/
"EXECIO * DISKR MYINDD2 (STEM NEWVAR. FINIS" /*Read all records*/
if rc = 0 then /* If read was successful */
do
/*************************************************************/
/* At this point, newvar.0 should be 10, indicating 10 */
/* records have been read. Stem variables newvar.1, newvar.2,*/
/* ... through newvar.10 will contain the 10 records. If we */
/* had not cleared the stem newvar. with the previous DROP */
/* instruction, variables newvar.11 through newvar.20 would */
/* still contain records 11 through 20 from the first data */
/* set. However, we would know that these values were not */
/* read by the last EXECIO DISKR since the current newvar.0 */
/* variable indicates that only 10 records were read by */
/* that last EXECIO. */
/*************************************************************/
say
say
say "-----------------------------------------------------"
say newvar.0 "records have been read from 'sample2.data': "
say
do i = 1 to newvar.0 /* Loop through all records */
say newvar.i /* Display the ith record */
end
"EXECIO" newvar.0 "DISKW MYOUTDD (STEM NEWVAR." /* Write
exactly the number of records read */
if rc = 0 then /* If write was successful */
do
say
say newvar.0 "records were written to 'all.sample.data'"
end
else
do
exec_RC = RC /* Save exec return code */
say
say "Error during 2nd EXECIO ...DISKW, return code is " RC
say
end
end
else
do
exec_RC = RC /* Save exec return code */
say
say "Error during 2nd EXECIO ... DISKR, return code is " RC
say
end
end
"EXECIO 0 DISKW MYOUTDD (FINIS" /* Close output file */
"FREE FI(MYINDD1)"
"FREE FI(MYINDD2)"
"FREE FI(MYOUTDD)"
exit 0