April 1, 1981 File Manipulation with EXECs You =an, to a limited degree, read and write CMS disk files using EXE:s. You can stack files with a filetype of EXEC in the console stack and
then read them, one record at a time, with &READ control statements. All data are truncated to eight characters. You can write a file, one
record at a time, with the &PUNCH control statement, and then you can
read the spool punch file onto disk. Examples of these techniques
follow. STACKIN3 EXEC FILES There aLe two methods to stack EXEC files in the console stack. One is
illustrated using a CMS EXEC file, as shown in the following PREFIX EXEC: SLNAME = &CONCAT &1 *
LI5TFILE &LNAME SCRIPT * (EXEC EXEC CMS &STACK SLOOP -END gREADFLAG EQ CONSOLE &READ VARS SNAME STYPE &MOD &SaFFIX = &SUBSTR &HAME 3 6 SNEWNAM = SCONCAT &2 &SUFFIX RENAME SNAME f,TYPE &MOD &NEWNAM STYPE &MOD SIF SRETCODE EQ 0 SSKIP &TYPE SNAME &TYPE NOT RENAMED -END
This EXEC procedure is invoked with two arguments, each two characters
in length, which indicate old and new prefixes for filenames. The EXEC renames files with a filetype of SCRIPT that have the first prefix, only the prefix in the filename.
The LISTFILE command, invoked with the EXEC option, creates a CMS EXEC file in the format:
&1 &2 filename SCRIPT mode When the EXEC is invoked with the line: EXEC C!"!S &STACK the arqGment &STACK is substituted for the variable symbol &1 in each
line in the CMS EXEC. The execution of the CMS EXEC effectively stacks,
in the console stack, the complete file identifications of the files
listed: SSTACK filename SCRIPT mode &STACK filename SCRIPT mode
These sta=ked lines are read back into the EXEC, one at a time, and the
tokens "filename", "SCRIPT", and "mode" are substituted for the variable
symbols SNAME, &TYPE, and &MOD. asing the SSUBSTR and &CONCAT built-in functions, the new name for
each file is constructed, and the RENAME command is issued to rename the
files.
294 IBM VM/370 CMS User's Guide
For example, if you invoke the EXEC procedure with the line:
prefix ab xy all SCRIPT files that have filenames beginning with the characters AB
are renamed so that the first two characters of the filename are XY. A sample execution summary of this EXEC is illustrated under "Debugging EXEC Procedures" in "Section 16. Refining Your EXEC Procedures."
you can create a data file, containing fixed-length records, using a
filetype of EXEC. To stack these data lines in the console stack, you
can enter them following an &BEGSTACK (or &EEGSTACK ALL) contrel
statement. For example, the file DATA EXEC is as follows:
&BEGSTACK HARRY 10/12/48 PATTI 1/18/49 DAVID 5/20/70 KATHY 8/6/43 MARVIN 2/28/50
The file BDAY EXEC contains: &CONTROL ERROR EXEC DATA
&IF &READFLAG EQ CONSOLE &GOTO -NO SREAD VARS &NAME &DATE SIP SNAME HE &1 &SKIP -2 -FOUND &IF .&1 EQ • &EXIT &TYPE &1 '5 BIRTHDAY IS &DATE CON WAIT DESBUF &EXIT -NO &TYPE &1 NOT IN LIST &EXIT When the BDAY EXEC is invoked, it expects an argument that is a first
name. The function of the EXEC is to display the birthday of the
specified person. A sample execution of this EXEC might be: bday kathy KATHY'S BIRTHDAY IS 8/6/43
R; BDAY EXEC first executes the DATA EXEC, which stacks names and dates
in the console stack. Then, BDAY EXEC reads one line at a time from the
stack, assigning the variable names &NAME and &DATE to the tokens on
each line. It compares &NAME with the argument read as &1. When it finds
a match, it displays the message indicating the date, and clears the
console stack after waiting for terminal output to finish.
Note that the file DATA EXEC begins with an &BEGSTACK control
statement, but contains no &END statement. The stack is terminated by the end of the EXEC file. "Writing Data Files" describes a technique
you might use to add new names and birth dates to the DATA EXEC file. Section 14. Building EXEC Procedures 295
Previous Page Next Page