Using the READ statement

The READ statement makes terminal input available to a CLIST in the form of symbolic variables. You normally precede a READ statement with one or more WRITE or WRITENR statements to let the user know that the CLIST is expecting input, and what sort of input it is expecting.

You can include one or more symbolic variables on a READ statement. If a READ statement does not include any variables, the CLIST stores the information the user enters into the control variable &SYSDVAL.

Assume that a WRITE statement requests that the user enter four names. The accompanying READ statement can be coded as follows:
READ A,B,C,D

Note that variables on a READ statement do not require ampersands.

If the user's response to the previous WRITE statement is:
SMITH,JONES,KELLY,INGALLS,GREENE
The CLIST assigns the names to the symbolic variables on the READ statement as follows:
&A has the value SMITH.
&B has the value JONES.
&C has the value KELLY.
&D has the value INGALLS.

Because the READ statement only includes four variables, the CLIST ignores the fifth name (GREENE).

You can also code READ statements without variables:
READ
If the user responded with the same five names, they all need to be stored in the control variable &SYSDVAL. To preserve the input strings, the CLIST does not remove the delimiters. For example, if the user responds to the previous READ statement by entering SMITH,JONES,KELLY,INGALLS,GREENE, &SYSDVAL has the following value:
SMITH,JONES,KELLY,INGALLS,GREENE
To assign a null value to one of the variables on a READ statement, the user can enter either a double comma or a double apostrophe (two single quotation marks). For example, assume that the CLIST sends a message to the user requesting four numbers. The READ statement to obtain these numbers is:
READ NUM1,NUM2,NUM3,NUM4
If the user responds either:
15,24,,73
or
'15' '24' '' '73'
The symbolic variables on the READ statement then have the following values:
&NUM1 has the value 15.
&NUM2 has the value 24.
&NUM3 has a null value.
&NUM4 has the value 73.

The fact that single quotation marks are valid delimiters requires that you exercise care when reading fully-qualified data set names into variables. Precautions are necessary because, if the user enters the data set name within single quotation marks (according to TSO/E naming conventions), the CLIST normally reads them as delimiters, not data. If a WRITE statement requests the name of a fully-qualified data set, the CLIST can obtain the data set name as entered by the user, with single quotation marks preserved, by using the READ statement with the &SYSDVAL control variable.

The following CLIST uses a READ statement and &SYSDVAL to preserve single quotation marks around a data set name. It also checks for the quotation marks to see if the user entered a fully-qualified data set name and, if not, adds the quotation marks and the user's prefix to the name.
PROC 0
WRITE Enter the name of a data set.
READ
SET &DSN = &SYSDVAL            /* Get name from &SYSDVAL; */
IF &SUBSTR(1:1,&DSN) ¬= &STR(') THEN + 
 DO                            /* If not fully qualified, */
  SET &DSN = '&SYSPREF;.&DSN'  /* add prefix and quotation marks.  */
 END
WRITE &DSN
You can also use the READ statement to obtain values for PROC statement keywords that were not supplied on the invocation of the CLIST. For example, suppose a PROC statement defines &ALPHA as a keyword with a default null value. Assume &ALPHA contains the number of golf balls on the moon and that the user does not assign a value to &ALPHA when invoking the CLIST. However, a variable, &SPACEVENTS, in the CLIST results in code being executed that requires a non-null value for &ALPHA. To obtain a value for &ALPHA, the following code sends a message to the user requesting a value for &ALPHA. Then, it issues a READ statement with &ALPHA as a parameter.
PROC 0 ALPHA()
⋮
SET SPACEVENTS = &ALPHA
DO WHILE &SPACEVENTS =  /* Null */
 WRITE Enter the number of golf balls there
 WRITE are on the moon.  A null value is unacceptable.
 READ ALPHA
 SET SPACEVENTS = &ALPHA
END
If a user ends a line of READ input with a plus sign or hyphen, the READ statement treats it as a continuation symbol and waits for another line of input. For more information, see Continuation symbols.