Previous Topic: Use the API with TSO/E REXXNext Topic: Use the Local 3270 Device Interface


Sample REXX Procedure

A sample REXX procedure that invokes the API follows. This sample is provided in the APISAMP member of the sysview.CNM4BSAM data set. This procedure displays all jobs using a resource like a data set name.

Important! This procedure uses the REXX POS function to get the offsets of the fields in the data. This procedure avoids problems with fields that change position on the display. Do not assume that the fields are always in a particular order or that they are always at the same offset.

/* REXX ==============================================================*/
/*                                                                    */
/* This sample REXX procedure will display jobs which have issued     */
/* an enqueue for a specific resource like a data set name.           */
/*                                                                    */
/* Input parameter: res - The resource name to test                   */
/*                                                                    */
/*====================================================================*/
/*--------------------------------------------------------------------*/
/* Change to TRACE I for testing                                      */
/*--------------------------------------------------------------------*/
TRACE N
/*--------------------------------------------------------------------*/
/* Check for required parameter                                       */
/*--------------------------------------------------------------------*/
PARSE UPPER ARG res
IF res = '' THEN
  DO
    SAY 'Required resource parameter missing'
    EXIT(-1)
  END
/*--------------------------------------------------------------------*/
/* Initialization                                                     */
/*------------------------------------------------------------------- */
accum = 0
msg. = ''
ADDRESS 'LINK' 'GSVXRXAA'             /* Init SYSVIEW address env    */
/*--------------------------------------------------------------------*/
/* Get enqueues for specified resource                                */
/*--------------------------------------------------------------------*/
ADDRESS 'SYSVIEWE' "C(ENQUEUE "res")"
IF QUEUED() = 0 THEN                  /* Error occurred if no data    */
  DO
    SAY 'Error - No data returned from ADDRESS SYSVIEWE'
    SIGNAL EXIT
  END
/*--------------------------------------------------------------------*/
/* Extract 1st line. Should be a 'M' (Msg line).  Msg follows...      */
/*--------------------------------------------------------------------*/
PARSE PULL msgline
/*--------------------------------------------------------------------*/
/* Find header line                                                   */
/*--------------------------------------------------------------------*/
ltype = ''
DO WHILE QUEUED() > 0
  PARSE UPPER PULL ltype 2 ldelim 3 ldata
  IF ltype = 'H' THEN LEAVE
END
IF ltype ¬= 'H' THEN                  /*Error occurred if no header   */
  DO
    SAY 'Error - Header line not returned from ADDRESS SYSVIEWE'
    SIGNAL EXIT
  END
/*--------------------------------------------------------------------*/
/* Get the offsets of required fields                                 */
/*--------------------------------------------------------------------*/
rnameo    = POS('RNAME',ldata)          /*Get offset of Rname field   */
jobnameo  = POS('JOBNAME',ldata)        /*Get offset of Jobname field */
typeo     = POS('TYPE',ldata)           /*Get offset of Type field    */
/*--------------------------------------------------------------------*/
/* Process rest of returned data looking for data lines               */
/*--------------------------------------------------------------------*/
DO WHILE QUEUED() > 0
  PARSE PULL ltype 2 ldelim 3 ldata
  IF ltype 'D' THEN                      /* Process if data line      */
    DO
      PARSE VAR ldata =(rnameo) rname =(jobnameo) jobname =(typeo) type
      PARSE VAR rname rname (ldelim)    /* Parse rname to delimiter   */
      IF rname = res THEN               /* Process if rname matches   */
        DO
          PARSE VAR jobname jobname (ldelim) /*Parse jobname field    */
          PARSE VAR type    type    (ldelim) /*Parse type field       */
          accum = accum + 1                  /* Increment accumulator */
          msg.accum = jobname'    'type      /* Save jobname and type */
        END
    END
END
/*--------------------------------------------------------------------*/
/* If any jobs found, display them                                    */
/*--------------------------------------------------------------------*/
IF accum > 0 THEN
  DO
    SAY '*** Number of jobs using resource 'res' is 'accum' ***'
    SAY 'Jobname     Type'               /* Display header            */
    SAY '-------     ----'
    DO i = 1 TO accum                   /* Display each job           */
       SAY msg.i
    END
    SAY '-------     ----'              /* Display end line           */
  END
ELSE SAY '*** Resource 'res' not in use ***'
/*--------------------------------------------------------------------*/
/* Exit procedure                                                     */
/*--------------------------------------------------------------------*/
EXIT:
/*--------------------------------------------------------------------*/
/* Formal termination of the API is required.                         */
/* Abends will occur if this step is omitted.                         */
/*--------------------------------------------------------------------*/
ADDRESS 'SYSVIEWE' "C(END)"            /* TERMINATE SYSVIEW SESSION   */
/*--------------------------------------------------------------------*/
/* Discard any residual output, so TSO won't try to execute it.
/*--------------------------------------------------------------------*/
CALL CLEAREDQ                          /* Discard any residual output */
EXIT 0
/* ===================================================================*/
/* CLEAREDQ Subroutine:  Clean out the external data queue            */
/* ===================================================================*/
CLEAREDQ: PROCEDURE
TRACE N
   DO WHILE QUEUED () > 0
   PULL line
   END
RETURN