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.

  • 300: Attempted to modify an unmodifiable control variable.

  • 312: Incorrect GLOBAL command.

  • 332: Invalid data set name.

  • 340: Incorrect operand of the OPENFILE command.

  • 348: Unable to open a data set specified in the OPENFILE command.

  • 352: Data set specified in the GETFILE command is not open.

  • 360: Data set specified in the PUTFILE command is not open.

  • 368: Data set specified in the CLOSFILE command is not open.

  • 372: The PUTFILE command was executed before executing the GETFILE command for the data set opened in update mode.

  • 400: Reached the end of file while executing the GETFILE command.

  • 848: Variable other than the integers in arithmetic expressions are described.

  • 900: No keyword is defined after ampersand(&).

  • 912: The "from" value is larger than the "to" value for the &SUBSTR function.

  • 916: Either the "from" or "to" value of the &SUBSTR function is not an integer, or the CODE operand value of the EXIT command is not an integer.

  • 920: Either the "from" or "to" value of the &SUBSTR function is an integer, or the CODE operand value of the EXIT command is an integer.

  • 932: Either the "from" or "to" value of the &SUBSTR function exceeded the range of the string.

  • 936: Incorrect type for the built-in function.

  • 952: Cannot find a branch specified in the GOTO command.

  • 956: No branch is described in the GOTO command.

  • 972: Used the TERMIN command in a batch job.

  • 999: Failed to call a command procedure.

&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.

  • TIME

  • DATE

  • WEEK

  • INTERVAL

  • READYJOBNAME

  • ENDJOBNAME

  • MESSAGE

  • MSGID

  • SYSTEM

  • USEREVENT

  • DATASET

  • MOUNT

  • SYSOUT

  • ONDEVICE

&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

  • ON: Does not convert lower case letters to upper case letters before executing a command.

  • OFF: Converts lower case letters to upper case letters before executing a command.

&SYSCONLIST

  • ON: Displays a command to the terminal after substituting a symbol parameter.

  • OFF: Does not display a command to the terminal after substituting a symbol parameter.

&SYSDATE

Current date in the mm/dd/yy format.

&SYSDVAL

String in which the user recently entered to the terminal.

&SYSENV

  • BACK: Set when a command procedure is being executed as a part of a batch job.

  • FORE: Set when a command procedure is not being executed as a part of a batch job.

&SYSFLUSH

  • ON: Does not execute succeeding command procedures if an error is raised while executing a command procedure.

  • OFF: Executes succeeding command procedures even if an error is raised while executing a command procedure.

&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

  • YES: A command procedure is called by another command procedure.

  • NO: A command procedure is not called by another command procedure.

&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

  • ON: Displays the command executed before substituting a symbol parameter.

  • OFF: Does not display the command executed before substituting a symbol parameter.

&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

ATTN

Sets the interrupt handler. For syntax check only.

CLOSFILE

Closes the data set.

CONTROL

Specifies options related to executing command procedures.

DATA-ENDDATA

Separates the TSO command and the screen output data area.

DO-END

Repeatedly executes one or more command procedure commands.

ERROR

Sets the error handler.

EXIT

Stops the execution of a command procedure and returns control to the parent command procedure.

GETFILE

Reads a record from a data set.

GLOBAL

Declares a symbol parameter shared between nested command procedures.

GOTO

Branches to a specified location.

IF-THEN-ELSE

Executes different actions according to specified conditions.

INDATA

Specifies the data set where the screen output data will be stored. For syntax check only.

OPENFILE

Opens a data set.

PROC

Defines the symbol parameter received from the parent command procedure.

PUTFILE

Writes a record in a data set.

READ

Stores the data received from the user through the terminal in the symbol parameter.

READDVAL

Stores the information of the control variable &SYSDVAL in the specified symbol parameter.

RETURN

Returns control to the command procedure command that is after the command procedure command in which an error is raised.

SET

Stores a value in the symbol parameter or a control variable.

TERMIN

Passes control to the terminal in order to receive user input. For syntax check only.

WRITE/WRITENR

Displays a string on the terminal.

4.1. ATTN Command

Sets the interrupt handler. For syntax check only.

Syntax
figure attn stmt
ATTN Command

4.2. CLOSFILE Command

Closes the data set opened by the OPENFILE command.

Syntax
figure closfile stmt
CLOSFILE Command
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
figure control stmt
CONTROL Command

image

image

image

image

image

image

image

image

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
figure data stmt
DATA-ENDDATA Command

image

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
figure do stmt
DO-END Command

image

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
figure error stmt
ERROR Command
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
figure exit stmt
EXIT Command

image

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
figure getfile stmt
GETFILE Command
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
figure global stmt
GLOBAL Command
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
figure goto stmt
GOTO Command
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
figure if stmt
IF-THEN-ELSE Command

image

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
figure indata stmt
INDATA Command

4.13. OPENFILE Command

Opens a data set.

Syntax
figure openfile stmt
OPENFILE Command
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
figure proc stmt
PROC Command

image

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
figure putfile stmt
PUTFILE Command
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
figure read stmt
READ Command
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
figure readdval stmt
READDVAL Command
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
figure return stmt
RETURN Command
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
figure set stmt
SET Command
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
figure termin stmt
TERMIN Command

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
figure write stmt
WRITE/WRITENR Command
Item Description

text

String to be printed to the terminal.

Example

The following uses the WRITE command.

WRITE HELLO WORLD