After completing this chapter, you will be able to describe the following.
Interrupt instructions
Stem variables available in REXX to develop simple applications
Instructions that interrupt the flow of an exec can cause the exec to.
Terminate (EXIT)
Skip to another part of the exec marked by a label (SIGNAL)
Go temporarily to a subroutine either within the exec or outside the exec (CALL/RETURN).
The EXIT instruction causes an exec to unconditionally end and return to where the exec was invoked. If the exec was initiated from the PROC section of an ISPF selection panel, EXIT returns to the ISPF panel. If the exec was called by a program, such as another exec, EXIT returns to the program.
In addition to ending an exec, EXIT can also return a value to the invoker of the exec. If the exec was invoked as a subroutine from another REXX exec, the value is received in the REXX special variable RESULT.
If the exec was invoked as a function, the value is received in the original expression at the point where the function was invoked. Otherwise, the value is received in the REXX special variable RC.
The value can represent a return code and can be in the form of a constant or an expression that is computed.
/*********************************REXX*********************************/ /* This exec uses the EXIT instruction to end the exec and return a */ /* value that indicates whether or not a job applicant gets the job. */ /* A value of A means the applicant does not qualify for the job, but */ /* a value of 1 means the applicant gets the job. The value is placed */ /* in the REXX special variable RESULT */ /**********************************************************************/ SAY 'How many months of experience do you have? Please enter' SAY 'the months as a number.' PULL month SAY 'Can you supply 3 references? Please answer Y or N.' PULL reference SAY 'Are you available to start work tomorrow? Please answer Y or N.' PULL tomorrow IF (month > 24) & (reference = 'Y') & (tomorrow = 'Y') THEN job = 1 /* person gets the job */ ELSE job = A /* person does not get the job */ EXIT job |
The CALL instruction interrupts the flow of an exec by passing control to an internal or external subroutine. An internal subroutine is part of the calling exec. An external subroutine is another exec. The RETURN instruction returns control from a subroutine back to the calling exec and optionally returns a value.
When calling an internal subroutine, CALL passes control to a label specified after the CALL keyword. When the subroutine ends with the RETURN instruction, the instructions following CALL are executed.
When calling an external subroutine, CALL passes control to the exec name that is specified after the CALL keyword. When the external subroutine completes, you can use the RETURN instruction to return to where you left off in the calling exec.
The SIGNAL instruction, like CALL, interrupts the normal flow of an exec and causes control to pass to a specified label. The label to which control passes can appear before or after the SIGNAL instruction. Unlike CALL, SIGNAL does not return to a specific instruction to resume execution. When you use SIGNAL from within a loop, the loop automatically ends; and when you use SIGNAL from an internal routine, the internal routine will not return to its caller.
In the following example, if the expression is true, then the language processor goes to the label Emergency: and skips all instructions in between.
SIGNAL is useful for testing execs or to provide an emergency course of action. It should not be used as a convenient way to move from one place in an exec to another.
When working with compound variables, it is often useful to initialize an entire collection of variables to the same value. You can do this easily with a stem.A stem is the first variable name and first period of the compound variable.Thus every compound variable begins with a stem. The following are stems:
FRED
Array
employee
You can alter all the compound variables in an array through the stem. you can alter all the compound variables in an array through the stem.assignment instruction:
employee. = 'Nobody'
As a result, all compound variables beginning with employee. , whether or not they were previously assigned, return the value Nobody. Compound variables that are assigned after the stem assignment are not affected
SAY employee.5/* Displays 'Nobody' */ |
REXX EXECIO and some TSO functions return information in compound variables. In the following example, OUTTRAP function doing this, in which OUTTRAP sets the compound variables LINE.1 through LINE.n, where n is the number of lines returned. In order to tell you how many lines were returned, OUTTRAP sets LINE.0 to that number.
Some other functions and EXECIO do this as well, but please don‘t assume that the 0th element always tells you how many elements there are.
CALL OUTTRAP ('LINE.') “LISTC” DO I = 1 TO LINE.0 SAY LINE.I END |
/*This exec uses stem variable to store students name and their marks */ /*and displays them respectively */ /********************************REXX**********************************/ SAY 'ENTER THE NUMBER OF STUDENT IN THE CLASS' PULL NUM DO I = 1 TO NUM SAY 'ENTER THE NAME OF THE STUDENT' PULL NAME STUDENT.I = NAME DO J=1 TO 3 SAY 'ENTER THE MARKS FOR SUBJECT' J PULL MARKS STUDENT.I.J = MARKS END END /* DISPLAYING THE NAME AND MARKS OF THE STUDENTS */ DO I = 1 TO NUM SAY 'STUDENT NAME :-' STUDENT.I DO J=1 TO 3 SAY 'MARKS FOR SUBJECT' J 'IS :-' STUDENT.I.J END END |
Write a program that adds, subtracts, multiplies, divides, finds the integer quotient, remainder, exponential two numbers A and B where A = 5 and B = 2.
The same program must use "strictly equal" comparative operator to compare between "Jacob" and "JACOB".
Also, use concatenation operators on three strings and display the result.
/********************************REXX********************************/ A = 5 B = 2 SAY 'THE VALUE OF A IS ' A SAY 'THE VALUE OF B IS ' B ADDITION = A + B SAY 'ADDITION OF A AND B GIVES:' ADDITION SUBTRACTION = A - B SAY 'SUBTRACTION OF A AND B GIVES:' SUBTRACTION MULTIPLICATION = A * B SAY 'MULTIPLICATION OF A AND B GIVES:' MULTIPLICATION DECIMALQUOTIENT = A / B INTEGERQUOTIENT = A % B SAY 'DIVISION OF A and B GIVES: ' DECIMALQUOTIENT SAY 'INTEGER QUOTIENT OF A AND B IS:' INTEGERQUOTIENT REMAINDER = A // B EXPONENTIAL = A ** B SAY 'REMAINDER WHEN A IS DIVIDED BY B IS : ' REMAINDER SAY 'EXPONENTIAL OF A AND B IS:' EXPONENTIAL NAME = 'JACOB' NAME1 = 'Jacob' say 'names are : ' name name1 if name == name1 then say 'names are strictly equal' else say 'names are not strictly equal' I = IBM M = MAINFRAME T = TUTORIAL IMT = I || M || T SAY 'IMT:' IMT EXIT |
The program uses the SELECT case structure and IF..ELSE conditional statements for conditional processing
Comments can be introduced, if needed, for better understanding of the program
The code can be written in blocks to enhance the readability of the program
Proper comments must be used for better understanding
Indentation must be appropriate for better readability
Write a program that shows the difference in functioning of the various ways of looping.
/******************************* REXX *********************************/ DO 3 /* REPEATS 3 TIMES */ SAY 'I AM IN COGNIZANT' END DO I = 3 TO 0 BY -1 /* Decrement the counter by 1 */ SAY 'VALUE OF I IS:' I END DO K = 1 TO 8 BY 2 FOR 3 /* LOOP WILL BE EXECUTED 3 TIMES */ SAY 'VALUE OF K IS:' K /* SINCE FOR 3 OVERRIDES THE */ END /* K=1 TO 8 BY 2 */ /* THIS LOOP WOULD DISPLAY: 1, 3, 5, 7 */ /*Note that condition is checked after executing the loop */ DO I = 1 TO 20 BY 2 UNTIL I > 6 SAY 'VALUE OF I IS:'' I END /* THIS LOOP WOULD DISPLAY 1 TO 7*/ /* The condition is evaluated before executing the loop */ SWITCH = 1 /* SWITCH IS A LOGICAL VARIABLE */ DO I = 1 TO 20 WHILE SWITCH SAY 'VALUE OF I IS:' I IF I = 7 THEN SWITCH = 0 END /* THIS LOOPS EXECUTES FORVER. TO EXIT FROM THE LOOP USE LEAVE */ M=0 DO FOREVER SAY 'EXECUTE THIS LOOP FOREVER' M = M+1 IF M=10 THEN LEAVE END EXIT |
The various looping constructs are used to execute a certain statement in a loop.
Comments can be introduced, if needed, for better understanding of the program
The code can be written in blocks to enhance the readability of the program
Avoid using SIGNAL from looping constructs
Proper comments must be used for better understanding
Indentation must be appropriate for better readability
Interrupt instructions interrupt the flow of an execution.
STEM variables can be used as an array and can be populated using looping constructs.
What will the following program display on the screen?
/********************************* REXX *******************************/ Father = 1 Mother = 1 Children = 3 SAY "There are" Father + Mother + Children "people in this family." |
What is the value of:
6 - 4 + 1
6 - (4 + 1)
6 * 4 + 2
6 * (4 + 2)
24 % 5 / 2
In the preceding example of using a comparison expression, what appears on the screen when you respond to the prompts with the following lunch costs?
Yesterday's Today's Lunch Lunch 4.42 3.75 3.50 3.50 3.75 4.42 |
What is the result (0 or 1) of the following expressions?
"Apples" = "Oranges" " Apples" = "Apples" " Apples" == "Apples" 100 = 1E2 100 \= 1E2 100 \== 1E2 |
A student applying to colleges has decided to pick ones according to the following Specifications:
IF (inexpensive | scholarship) & (reputable | nearby) THEN SAY "I'll consider it." ELSE SAY "Forget it!" |
A college is inexpensive, did not offer a scholarship, is reputable, but is over 1000 miles away. Should the student apply?
What are the answers to the following examples?
22 + (12 * 1)
-6 / -2 > (45 % 7 / 2) - 1
10 * 2 - (5 + 1) // 5 * 2 + 15 – 1
What happens when the following exec runs?
DO outer = 1 TO 3 SAY /* Write a blank line */ DO inner = 1 TO 3 SAY 'Outer' outer 'Inner' inner END END |
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!