z/OS ISPF Dialog Developer's Guide and Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


An example of using panel REXX

z/OS ISPF Dialog Developer's Guide and Reference
SC19-3619-00

The panel shown demonstrates the use of the *REXX statement to invoke REXX code from the )INIT and )PROC sections. The application displays cost, tax, and sales commission values for an order quote.

)PANEL
)ATTR DEFAULT(%+_) FORMAT(MIX)
 ~ TYPE(PT)
 ˋ TYPE(PIN)
 ! TYPE(FP)
 @ TYPE(NT)
 % TYPE(NEF)
 # TYPE(NEF) JUST(RIGHT)
 * TYPE(VOI) JUST(RIGHT)
)BODY WINDOW(70,20) CMD(ZCMD)
@                        ~Widget Order Quotes@                     @
!Command ===>%Z                                          @
@
ˋEnter the number of widgets to be ordered and the quoted price.
@
!Number of Widgets. . .#Z      @
!Quoted Price . . . . .#Z      @
@
!Total Cost ex Tax. . .*Z        @
!Total Tax. . . . . . .*Z        @
!Total Cost . . . . . .*Z        @
@
!Sales Commission . . .*Z        @
@
)INIT
.ZVARS = '(ZCMD NWIDGETS QPRICE TCSTXTAX TOTTAX TOTCOST SCOMM)'
/* Call REXX routine VALUSER to validate the user is allowed to use  */
/* this application.                                                 */
*REXX(ZPANELID,ZUSER,(VALUSER))
/* If the user is not allowed, display a message and protect the     */
/* input fields.                                                     */
IF (.MSG ¬= &Z)
  .ATTRCHAR(#) = 'TYPE(LI)'
)PROC
/* Call REXX routine VALUSER to validate the user is allowed to use  */
/* this application.                                                 */
*REXX(ZPANELID,ZUSER,(VALUSER))
/* If the user is not allowed, display a message and protect the     */
/* input fields.                                                     */
IF (.MSG ¬= &Z)
  .ATTRCHAR(#) = 'TYPE(LI)'
  EXIT
/* Initialize the cursor position variable.                          */
&CPOS = '--------'
&HPRICE = '      '
&LPRICE = '      '
/* Invoke panel REXX to validate input and calculate quote values.   */
*REXX(*,CPOS,LPRICE,HPRICE)
Trace O
upper zcmd
cpos = "'ZCMD'"
/************************************************************/
/* If the CLR command is entered in the command field,      */
/* clear all input/output fields and return to redisplay    */
/* the panel.                                               */
/************************************************************/
If zcmd = 'CLR' then do
  nwidgets = ''
  qprice   = ''
  call Clear_Output
  return
End
/************************************************************/
/* Ensure the output fields are cleared.                    */
/************************************************************/
Call Clear_Output
/************************************************************/
/* Verify the value entered for the number of widgets is    */
/* a positive whole number.                                 */
/************************************************************/
if datatype(nwidgets,'N') = 0 |,
   pos('.',nwidgets) ¬= 0     |,
   pos('-',nwidgets) ¬= 0 then do
  cpos   = 'NWIDGETS'
  zrxmsg = 'TPRX001'
  zrxrc  = 8
  return
end
/************************************************************/
/* Verify the quoted price is a monetary value.             */
/************************************************************/
qprice = strip(qprice)
if substr(qprice,1,1) = '$' then
  qprice = substr(qprice,2)
if datatype(qprice,'N') = 0 |,
   (pos('.',qprice) ¬= 0 & ((length(qprice) - pos('.',qprice)) > 2)) then do
  cpos   = 'QPRICE  '
  zrxmsg = 'TPRX002'
  zrxrc  = 8
  return
end
/************************************************************/
/* Verify the quoted price is above the lowest possible     */
/* value.                                                   */
/************************************************************/
lprice = 12.50
if qprice < lprice then do
  cpos   = 'QPRICE  '
  zrxmsg = 'TPRX003'
  lprice = '$'||lprice
  zrxrc  = 8
  return
end
/************************************************************/
/* Verify the quoted price is above the highest possible    */
/* value.                                                   */
/************************************************************/
hprice = 25.00
if qprice > hprice then do
  cpos   = 'QPRICE  '
  zrxmsg = 'TPRX004'
  hprice = '$'||hprice
  zrxrc  = 8
  return
end
/************************************************************/
/* Calculate the total pre-tax cost.                        */
/************************************************************/
tcstxtax = format(nwidgets*qprice,5,2)
/************************************************************/
/* Calculate the total sales tax at a rate of 6.25%.        */
/************************************************************/
tottax = format(tcstxtax*0.0625,5,2)
/************************************************************/
/* Calculate the total cost after tax.                      */
/************************************************************/
totcost = format(tcstxtax+tottax,5,2)
/************************************************************/
/* Calculate the sales commission at a rate of 12.5% of the */
/* profit.                                                  */
/************************************************************/
scomm = format((tcstxtax-(nwidgets*lprice))*0.125,5,2)
/************************************************************/
/* Format the output fields for display.                    */
/************************************************************/
qprice = '$'||strip(qprice)
tcstxtax = '$'||strip(tcstxtax)
totcost = '$'||strip(totcost)
tottax = '$'||strip(tottax)
scomm = '$'||strip(scomm)
return
/************************************************************/
/* This routine clears the output fields.                   */
/************************************************************/
clear_output:
 tcstxtax = ''
 tottax   = ''
 totcost  = ''
 zcmd     = ''
 scomm    = ''
return
*ENDREXX
IF (.MSG ¬= &Z)
  .CURSOR = &CPOS
  REFRESH(*)
ELSE
 .CURSOR = ZCMD
/* IF (.MSG ¬= &Z AND .MSG NE TPRX000 AND &ZVERB NE CANCEL) .RESP = ENTER */
)END

The user of this application enters the number of widgets to be ordered and the price quoted to the customer. The panel REXX coded directly in the )PROC section receives all the panel input and output fields for processing. It also receives the CPOS variable used to set the cursor position, and the LPRICE and HPRICE variables used to check that the quoted price is in a valid range. This panel REXX performs these functions:

  • Validates the values entered by the user. If any values are invalid, variable ZRXRC is set to 8, the appropriate error message ID is set in variable ZRXMSG, the appropriate field name is stored in the variable CPOS, and control is returned to ISPF.
  • Calculates and formats the values displayed for the cost (ex tax), tax, total cost, and sales commission.
  • Checks if the user has entered 'CLR' in the command. If so, all the input/output fields on the panel are set to blanks.

The panel REXX routine in member VALUSER is invoked in the )INIT and )PROC sections. This routine receives the system variables ZPANELID and ZUSER and checks if the user is allowed to use the panel. This is the REXX code for VALUSER:

Figure 1. Sample member VALUSER to invoke panel REXX
/********************************************************/
/* Call ISPPRXVP to get the ISPF dialog variables into  */
/* REXX.                                                */
/********************************************************/
Call ISPPRXVP 'I'
/********************************************************/
/* This common REXX routine checks whether the user is  */
/* allowed to use the panel being displayed.            */
/********************************************************/
say 'zpanelid = ' zpanelid
say 'zuser = ' zuser
found = 0
users = ''
/********************************************************/
/* Set up the user list based on the panel Id.          */
/********************************************************/
if zpanelid = 'SQUOTE' then
  users = 'ADAMS MITCHELL JACKSON JAMES JONES WEBSTER'
else
if zpanelid = 'PORDER' then
  users = 'BRADLEY CONNOR EVANS PRINCE WALLS'
else
if zpanelid = 'INVENTRY' then
  users = 'BAXTER HILL NELSON SWAN WILSON'
/********************************************************/
/* Check that the user Id is in the user list.          */
/********************************************************/
do i = 1 to words(users)
  if zuser = word(users,i) then do
    found = 1
    leave
  end
end
/********************************************************/
/* If not found, pass back error message TPRX009 in     */
/* dialog variable ZRXMSG and set a return code of 8    */
/* in dialog variable ZRXRC.                            */
/********************************************************/
if ¬found then do
  zrxmsg = 'TPRX009'
  zrxrc  = 8
end
/********************************************************/
/* Call ISPPRXVP to get update the ISPF dialog          */
/* variables with the changes made in this REXX.        */
/********************************************************/
Call ISPPRXVP 'T'
Return

Member VALUSER contains compiled REXX, so processing commences with a call to ISPPRXVP to initialize REXX variables for the ISPF dialog variables ZPANELID, ZUSER, ZRXRC and ZRXMSG. Before returning to ISPF there is also a call to ISPPRXVP to update these dialog variables with the values in the corresponding REXX variables.

These are the messages used by this application:

TPRX001  'Invalid number          ' .TYPE=N NOKANA
'The value entered is not a positive whole number.'
TPRX002  'Invalid price           ' .TYPE=N NOKANA
'The value entered is not in the form $xx.yy'
TPRX003  'Quoted price too low    ' .TYPE=N NOKANA
'The quoted price cannot be lower than &LPRICE'
TPRX004  'Quoted price too high   ' .TYPE=N NOKANA
'The quoted price cannot be greater than &HPRICE'
TPRX009  'Not available           ' .TYPE=A .W=NORESP NOKANA
'This application is not available to user &ZUSER'

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014