Using Arithmetic Expressions
You can use arithmetic expressions in an exec many different ways. The following
example uses several arithmetic operators to round and remove extra decimal
places from a dollar and cents value.
Example Using Arithmetic Expressions
/****************************** REXX *******************************/
/* This exec computes the total price of an item including sales
*/
/* tax rounded to two decimal places. The cost and percent of the */
/* tax (expressed as a decimal number) are passed to the exec when */
/* it is run.
*/
/*******************************************************************/
PARSE ARG cost percent_tax
total = cost + (cost * percent_tax)
/* Add tax to cost.
*/
price = ((total * 100 + .5) % 1) / 100
/* Round and remove
*/
/* extra decimal places.*/
SAY 'Your total cost is $'price'.'
Exercises - Calculating Arithmetic Expressions
1. What will the following program display on the screen?
Exercise
/***************************** REXX ****************************/
pa = 1
ma = 1
kids = 3
SAY "There are" pa + ma + kids "people in this family."
2. What is the value of:
a. 6 - 4 + 1
b. 6 - (4 + 1)
c. 6 * 4 + 2
d. 6 * (4 + 2)
e. 24 % 5 / 2
ANSWERS
1. There are 5 people in this family.
2. The values are as follows:
a. 3
b. 1
c. 26
d. 36
e. 2
Comparison Operators
Expressions that use comparison operators do not return a number value as do
arithmetic expressions. Comparison expressions return either a true or false
response in terms of 1 or 0 as follows:
1
True
0
False
Using Expressions
30
z/OS V1R1.0 TSO/E REXX User’s Guide
Summary of Contents for TSO/E REXX
Page 1: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Page 2: ......
Page 3: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Page 10: ...viii z OS V1R1 0 TSO E REXX User s Guide ...
Page 12: ...x z OS V1R1 0 TSO E REXX User s Guide ...
Page 14: ...xii z OS V1R1 0 TSO E REXX User s Guide ...
Page 18: ...xvi z OS V1R1 0 TSO E REXX User s Guide ...
Page 20: ...2 z OS V1R1 0 TSO E REXX User s Guide ...
Page 58: ...Tracing Expressions with the TRACE Instruction 40 z OS V1R1 0 TSO E REXX User s Guide ...
Page 78: ...60 z OS V1R1 0 TSO E REXX User s Guide ...
Page 86: ...Built In Functions 68 z OS V1R1 0 TSO E REXX User s Guide ...
Page 128: ...Issuing Other Types of Commands from an Exec 110 z OS V1R1 0 TSO E REXX User s Guide ...
Page 136: ...Debugging Execs 118 z OS V1R1 0 TSO E REXX User s Guide ...
Page 170: ...Protecting Elements in the Data Stack 152 z OS V1R1 0 TSO E REXX User s Guide ...
Page 201: ...Part 3 Appendixes Copyright IBM Corp 1988 2001 183 ...
Page 202: ...184 z OS V1R1 0 TSO E REXX User s Guide ...
Page 222: ...Using Variables 204 z OS V1R1 0 TSO E REXX User s Guide ...
Page 226: ...208 z OS V1R1 0 TSO E REXX User s Guide ...
Page 238: ...220 z OS V1R1 0 TSO E REXX User s Guide ...
Page 241: ......