SAY exec: for expression evaluation

The following code example is a listing of the SAY exec. SAY evaluates an expression supplied as an argument and displays the results.

The REXX command INTERPRET is used to evaluate the supplied expression and assign it to a variable. Then that variable is used in a formatted reply message.

Exec to do calculations

/* EXEC TO DO CALCULATIONS */
Address REXXTDLI
Arg Args
If Args='' Then
   Msg='SUPPLY EXPRESSION AFTER EXEC NAME.'
Else Do
   Interpret 'X='Args           /* Evaluate Expression */
   Msg='EXPRESSION:' Args '=' X
End
'ISRT IOPCB MSG'
Exit RC

This exec shows an example of developing applications with IMS Adapter for REXX . It also shows the advantages of REXX, such as dynamic interpretation, which is the ability to evaluate a mathematical expression at run-time.

A PDF EDIT session is shown in the following figure. This figure shows how you can enter a new exec to be executed under IMS.

Figure 1. PDF EDIT session on the SAY exec
 EDIT ---- USER.PRIVATE.PROCLIB(SAY) - 01.03 ------------------ COLUMNS 001 072
 COMMAND ===>                                                  SCROLL ===> PAGE
 ****** ***************************** TOP OF DATA ******************************
 000001 /* EXEC TO DO CALCULATIONS */
 000002 Address REXXTDLI
 000003 Arg Args
 000004 If Args='' Then
 000005    Msg='SUPPLY EXPRESSION AFTER EXEC NAME.'
 000006 Else Do
 000007    Interpret 'X='Args           /* Evaluate Expression */
 000008    Msg='EXPRESSION:' Args '=' X
 000009 End
 000010
 000011 'ISRT IOPCB MSG'
 000012 Exit RC
 ****** **************************** BOTTOM OF DATA ****************************
To execute the SAY exec, use IVPREXX and supply an expression such as:
IVPREXX SAY 5*5+7

This expression produces the output shown in the following figure.

Figure 2. Example output from the SAY exec
 EXPRESSION: 5*5+7 = 32
 EXEC SAY ended with RC= 0