Command Procedures
This chapter describes the components of command procedures.
1. Control Variables
The following is a list of control variables used in command procedures.
Control Variable | Description |
---|---|
&LASTCC |
Recent return codes. The following describes command procedures' unique return codes and their meanings.
|
&MAXCC |
Maximum value of the return code. |
&SYS#CC |
Completion code of a completed job. It is set when an ENDJOBNAME event is raised. |
&SYS#EVENT |
Name of a raised event. This control value has one of the following values.
|
&SYS#EVTNO |
Stores the event that corresponds to the event number specified when an event occurs if multiple values are specified in a single operand in the WAIT command. |
&SYS#FMSG |
Stores the entire outputted message. Set when a MESSAGE event or MSGID event is raised. |
&SYS#JN |
Job name of the completed job. Set when an ENDJOBNAME event is raised. |
&SYS#MSG |
Stores the main text of the outputted message. Set when either a MESSAGE event or an MSGID event is raised. |
&SYS#PFX |
Stores the identifier of the outputted message. Set when either a MESSAGE event or MSGID event is raised. |
&SYSASIS |
|
&SYSCONLIST |
|
&SYSDATE |
Current date in the mm/dd/yy format. |
&SYSDVAL |
String in which the user recently entered to the terminal. |
&SYSENV |
|
&SYSFLUSH |
|
&SYSICMD |
Name of a command procedure. Used only when a command procedure is not executed explicitly by using the EXEC command in an implicit execution. |
&SYSNEST |
|
&SYSPCMD |
A recently executed TSO command (excluding parameters). The default value is EXEC. |
&SYSPREF |
Prefix of the data set name. |
&SYSSCAN |
Specifies the maximum number of times for scanning (the process of substituting a symbol parameter with a value) to be performed before executing each command procedure command. |
&SYSSDATE |
Current date in the yy-mm-dd format. |
&SYSSTIME |
Current time in the hh:mm format. |
&SYSSTOP |
Maximum number of commands that can be executed in a command procedure. |
&SYSSYMLIST |
|
&SYSTIME |
Current time in the hh:mm:ss format. |
&SYSTMID |
Name of the currently connected terminal. |
&SYSUID |
TSO session user ID. |
2. Built-in Functions
The following is a list of the built-in functions used in command procedures.
Built-in Function | Description |
---|---|
&DATATYPE (expr) |
Returns NUM if the result of the expression expr is a number, and returns CHAR if it is a string. |
&EVAL (expr) |
Returns the operation result of the formula expr. |
&LENGTH (expr) |
Returns the character length of the operation result of the expression expr. |
&NRSTR (expr) |
Substitutes the symbol parameters of expression expr, but returns the results without a superposition substitution. Does not execute mathematical operations. |
&STR (expr) |
Substitutes the symbol parameters of expression expr and returns the result of processing built-in functions. Does not execute mathematical operations. |
&SUBSTR (from:to,str) |
Returns the substring extracted from the "from" position to the "to" position of the string str. Only extracts one character from the "from" position if "to" is omitted. |
&SYS#EPRM (eprm) |
Returns the value of the virtual parameter eprm. For information about virtual parameter configuration, refer to Chapter 1. |
&SYSDSN (d) |
Checks the status of the data set "d", and returns "OK" if in a usable status and returns an error message if otherwise. |
&SYSINDEX (needle,haystack,start) |
Returns the position of the string needle in the string haystack. Finds the needle in the entire haystack if "start" is "0" or omitted. If "start" is a positive number, then finds the needle from the starting character of the haystack. Returns 0 if the needle is not found. |
&SYSNSUB (level,expr) |
Substitutes the symbol parameter of the expression expr, but substitutes it in the maximum level of times. |
3. Operators
Expressions can be used in some command procedures such as the IF command. An expression is a concatenation of operands such as integers, strings, symbol parameters, control variables, or built-in functions using operators.
Operators are categorized into arithmetic operators, comparison operators, and logical operators. The following tables describe each type.
-
Arithmetic Operators
Arithmetic Operators Description +
Addition
-
Subtraction
*
Multiplication
/
Division
**
Exponent (if the right side is negative, then the result of the operation is 0)
//
Remainder
-
Comparison Operators
Comparison Operator Description EQ or =
The left side and the right side are the same.
NE or ^=
The left side and the right side are not the same.
LT or <
The left side is smaller than the right side.
GT or >
The left side is greater than the right side.
LE or <=
The left side is less than or equal to the right side.
GE or >=
The left side is greater than or equal to the right side.
NG or ^>
The left side is not greater than the right side.
NL or ^<
The left side is not smaller than the right side.
-
Logical Operators
Logical Operator Description AND or &&
Logical product
OR or |
Logical sum
4. Command Procedure Commands
The following table describes the types of command procedure commands and their functions.
Command Procedure Command | Description |
---|---|
Sets the interrupt handler. For syntax check only. |
|
Closes the data set. |
|
Specifies options related to executing command procedures. |
|
Separates the TSO command and the screen output data area. |
|
Repeatedly executes one or more command procedure commands. |
|
Sets the error handler. |
|
Stops the execution of a command procedure and returns control to the parent command procedure. |
|
Reads a record from a data set. |
|
Declares a symbol parameter shared between nested command procedures. |
|
Branches to a specified location. |
|
Executes different actions according to specified conditions. |
|
Specifies the data set where the screen output data will be stored. For syntax check only. |
|
Opens a data set. |
|
Defines the symbol parameter received from the parent command procedure. |
|
Writes a record in a data set. |
|
Stores the data received from the user through the terminal in the symbol parameter. |
|
Stores the information of the control variable &SYSDVAL in the specified symbol parameter. |
|
Returns control to the command procedure command that is after the command procedure command in which an error is raised. |
|
Stores a value in the symbol parameter or a control variable. |
|
Passes control to the terminal in order to receive user input. For syntax check only. |
|
Displays a string on the terminal. |
4.2. CLOSFILE Command
Closes the data set opened by the OPENFILE command.
Syntax
Item | Description |
---|---|
ddname |
DD name of the data set opened in the OPENFILE command. |
Example
The following uses the CLOSFILE command.
CLOSFILE SYSUT1
4.3. CONTROL Command
Specifies options related to executing command procedures.
Syntax
Item | Description |
---|---|
end |
Ending string of a DO group. |
Operands
The following table describes the operands mentioned previously.
Operand | Description |
---|---|
PROMPT |
Uses terminal prompting. For syntax check only. |
NOPROMPT |
Does not use terminal prompting. For syntax check only. |
SYMLIST |
Displays the command executed before substituting symbol parameters on the terminal. |
NOSYMLIST |
Does not display the command executed before substituting symbol parameters on the terminal. |
LIST |
Displays the command. For syntax check only. |
NOLIST |
Does not display the command. For syntax check only. |
CONLIST |
Displays the command executed after substituting symbol parameters on the terminal. |
NOCONLIST |
Does not display the command executed after substituting symbol parameters on the terminal. |
CAPS |
Converts lower case letters to upper case letters before executing a command. |
NOCAPS |
Does not convert lower case letters to upper case letters before executing a command. |
ASIS |
Does not convert lower case letters to upper case letters before executing a command. |
MSG |
Displays the information message. For syntax check only. |
NOMSG |
Does not display the information message. For syntax check only. |
FLUSH |
Does not execute succeeding command procedures if an error is raised while executing a command procedure. |
NOFLUSH |
Executes succeeding command procedures even if an error is raised while executing a command procedure. |
MAIN |
Means that a command procedure has not been called by another command procedure. |
END |
Specifies the ending string of a DO group. |
Example
The following uses the CONTROL command.
CONTROL END(FIN)
4.4. DATA-ENDDATA Command
Separately processes the data outputted between the DATA command and the ENDDATA command, and assumes the data outputted between the DATA command and the ENDDATA command as a TSO command if an operand is not specified. For information about how to specify operands, refer to the operand explanation.
Syntax
Operands
The following table describes the operands mentioned previously.
Operand | Description |
---|---|
PROMPT |
Assumes the data outputted between the DATA command and the ENDDATA command as prompting data. Substitutes if a symbol parameter exists. |
TEXT |
Assumes the data outputted between the DATA command and the ENDDATA command as text. Does not substitute even when a symbol parameter exists. |
Example
The following uses the DATA-ENDDATA command.
DO DATA PROFILE NOPREFIX ENDDATA END
4.5. DO-END Command
Executes the TSO command between the DO command and the END/DOEND command, and the command procedure command (hereafter DO group).
Syntax
Item | Description |
---|---|
expression |
Condition for repeating a DO group as an expression. |
Operands
The following table describes the operands mentioned previously.
Operand | Description |
---|---|
UNTIL |
Repeatedly executes a DO group while the value of the expression specified after UNTIL is false. |
WHILE |
Repeatedly executes a DO group while the value of the expression specified after WHILE is true. |
Example
The following uses the DO-END command.
DO WHILE &LASTCC LE 4 SET A=&A+1 CALL TESTPGM '&A' END
4.6. ERROR Command
Specifies a job to be executed (hereafter error handler) when the return code of a child TSO command or command procedure command is not 0 while executing a command procedure. If the EXIT command, RETURN command, or GOTO command is encountered between an ERROR DO and END, then the error handler is terminated at that position. &LASTCC resets to 0 after executing the error handler.
Syntax
Item | Description |
---|---|
action |
Error handler. To describe various jobs, describe it between the DO command and the END command. |
Operands
The following describes the operand mentioned previously.
Operand | Description |
---|---|
OFF |
Deselects an already specified error handler. |
Example
The following uses the ERROR command.
ERROR DO WRITE &LASTCC RETURN END
4.7. EXIT Command
Stops the execution of a command procedure, and returns control to the parent command procedure.
Syntax
Item | Description |
---|---|
code |
Return code. |
Operands
The following table describes the operands mentioned previously.
Operand | Description |
---|---|
CODE |
Specifies a return code. If a CODE operand is omitted, then the &LASTCC value becomes the return code. |
QUIT |
Returns control to the parent command procedure specified where CONTROL NOFLUSH or MAIN is specified. |
Example
The following uses the EXIT command.
ERROR DO EXIT CODE(&MAXCC) END
4.8. GETFILE Command
Reads a record from a data set. The record is stored in a symbol parameter that has a name identical to the specified DD name.
Syntax
Item | Description |
---|---|
ddname |
DD name of the data set opened in the OPENFILE command. |
Example
The following uses the GETFILE command.
OPENFILE FILE1 UPDATE GETFILE FILE1 SET FILE1=UPDATED PUTFILE FILE1 CLOSFILE FILE1
4.9. GLOBAL Command
Declares a symbol parameter shared between nested command procedures. The top-level command procedure must have declared all the symbol parameters to be shared with lower-level command procedures.
Lower-level command procedures can use all or some of the symbol parameters declared in the GLOBAL command of the top-level command procedure after declaring them with separate names in the GLOBAL command.
The nth symbol parameter of a GLOBAL command of upper-level command procedures refers to the same value as the nth symbol parameter of the GLOBAL command of lower-level command procedures.
Syntax
Item | Description |
---|---|
variable |
Symbol parameter name. |
Example
The following uses the GLOBAL command. COMP1 calls COMP2, and COMP2 calls COMP3. GA1, GB1, and GC1 refer to the same value. GA2, GB2, and GC2 refer to the same value. GA3 and GC3 refer to the same value. GA4 and GC4 refer to the same value.
-
COMP1
PROC 0 AP1,AP2 GLOBAL GA1,GA2,GA3,GA4 SET &GA1=&AP1 SET &GA2=&AP2 SET &GA3=0 SET &GA4=&AP1+2 EXEC COMP2
-
COMP2
GLOBAL GB1,GB2 EXEC COMP3
-
COMP3
GLOBAL GC1,GC2,GC3,GC4
4.10. GOTO Command
Branches to a specified location.
Syntax
Item | Description |
---|---|
dest |
Label of the location to be branched to. |
Example
The following uses the GOTO command.
SET &CNT=2 GOTO TAG&CNT TAG1: WRITE CNT IS NOT TWO TAG2: WRITE CNT IS TWO
4.11. IF-THEN-ELSE Command
Executes different actions according to the expression value.
Syntax
Item | Description |
---|---|
expression |
Basis of a decision. If the value is true, then_action is executed, and if the value is false, else_action is executed. |
then_action |
TSO command or command procedure command to be executed when the expression value is true. Can be a DO group. |
else_action |
TSO command or command procedure command to be executed when the expression value is false. Can be a DO group. |
Syntax
The following uses the IF-THEN-ELSE command.
IF &LASTCC EQ 0 THEN- WRITE ZERO ELSE- WRITE NONZERO
4.12. INDATA Command
Specifies the data set where prompting data will be stored. For syntax check only.
Syntax
4.13. OPENFILE Command
Opens a data set.
Syntax
Item | Description |
---|---|
ddname |
DD name of the data set. |
Operand
The following table describes the operand mentioned previously.
Operand | Description |
---|---|
INPUT |
Opens a data set in input mode. This is the default mode. |
OUTPUT |
Opens a data set in output mode. |
UPDATE |
Opens a data set in update mode. |
Example
The following uses the OPENFILE command.
ALLOC DD(INP) DS(MY.DATA) OPENFILE INP
4.14. PROC Command
Defines the symbol parameter received from the parent command procedure. A keyword-specified symbol parameter must be described after a location-specified symbol parameter.
Syntax
Item | Description |
---|---|
n |
Parameter count of a location-specified symbol parameter. |
name |
Parameter name. |
default_value |
Default value of the parameter. |
Example
The following uses the PROC command.
PROC 3 PP1 PP2 PP3 KP1(DEFVAL1) KP2()
4.15. PUTFILE Command
Records data that is contained in the symbol parameter with the same name as the specified DD name in the data set.
Syntax
Item | Description |
---|---|
ddname |
DD name of the data set opened in the OPENFILE command. |
Example
The following uses the PUTFILE command.
OPENFILE FILE1 UPDATE GETFILE FILE1 SET FILE1=UPDATED PUTFILE FILE1 CLOSFILE FILE1
4.16. READ Command
Stores the data received from the user through the terminal in a symbol parameter. This command is stored in &SYSDVAL if omitting an operand.
Syntax
Item | Description |
---|---|
param |
Variable name that stores the data received from the data through the terminal. |
Example
The following uses the READ command.
READ ANS1
4.17. READDVAL Command
Stores the content of &SYSDVAL in a symbol parameter. This command does nothing if an operand is omitted.
Syntax
Item | Description |
---|---|
param |
Variable name in which the content of &SYSDVAL is stored. |
Example
The following uses the READDVAL command.
SET READDVAL=&STR(SMITH JONES KELLY) READDVAL NAME1,NAME2,NAME3
4.18. RETURN Command
Returns control to the command procedure command that is after the command procedure command that raised an error.
Syntax
Example
The following uses the RETURN command.
ERROR DO WRITE &LASTCC RETURN END
4.19. SET Command
Stores the value of an expression in a symbol parameter or control variable.
Syntax
Item | Description |
---|---|
param |
Name of a symbol parameter of a control variable. |
expression |
An expression. |
Example
The following uses the SET command.
SET A=2*3+1
4.20. TERMIN Command
Passes control to the terminal to receive user input. For syntax check only.
Syntax
4.21. WRITE/WRITENR Command
Outputs a string in the terminal. For the WRITE command, the cursor is moved to the next line after outputting a string. For the WRITENR command, the cursor is not moved to the next line after outputting a string.
Syntax
Item | Description |
---|---|
text |
String to be printed to the terminal. |
Example
The following uses the WRITE command.
WRITE HELLO WORLD