Save job output from SDSF into a PDS and using ISPF functions in REXX

323 Views Asked by At

We periodically runs jobs and we need to save the output into a PDS and then parse the output to extract parts of it to save into another member. It needs to be done by issuing a REXX command using the percent sign and the REXX member name as an SDSF command line. I've attempted to code a REXX to do this, but it is getting an error when trying to invoke an ISPF service, saying the ISPF environment has not been established. But, this is SDSF running under ISPF.

My code has this in it (copied from several sources and modified):

  parse arg PSDSFPARMS "(" PUSERPARMS
  parse var PSDSFPARMS PCURRPNL PPRIMPNL PROWTOKEN PPRIMCMD .
  PRIMCMD=x2c(PPRIMCMD)

  RC = isfquery()
  if RC <> 0 then
  do
    Say "** SDSF environment does not exist, exec ending."
    exit 20
  end

  RC = isfcalls("ON")

  Address SDSF "ISFGET" PPRIMPNL "TOKEN('"PROWTOKEN"')" ,
    " (" VERBOSE ")"
  LRC = RC

  if LRC > 0 then
    call msgrtn "ISFGET"
  if LRC <> 0 then
    Exit 20

  JOBNAME = value(JNAME.1)
  JOBNBR  = value(JOBID.1)

  SMPDSN   = "SMPE.*.OUTPUT.LISTINGS"
  LISTC. = ''
  SMPODSNS. = ''
  SMPODSNS.0 = 0
  $ = outtrap('LISTC.')
  MSGVAL = msg('ON')
  address TSO "LISTC LVL('"SMPDSN"') ALL"
  MSGVAL = msg(MSGVAL)
  $ = outtrap('OFF')
  do LISTCi = 1 to LISTC.0
    if word(LISTC.LISTCi,1) = 'NONVSAM' then
    do
      parse var LISTC.LISTCi . . DSN
      SMPODSNS.0 = SMPODSNS.0 + 1
      i = SMPODSNS.0
      SMPODSNS.i = DSN
    end
    IX = pos('ENTRY',LISTC.LISTCi)
    if IX <> 0 then
    do
      IX = pos('NOT FOUND',LISTC.LISTCi,IX + 8)
      if IX <> 0 then
      do
        address ISPEXEC "SETMSG MSG(IPLL403E)"
        EXITRC = 16
        leave
      end
    end
  end

  LISTC. = ''
  if EXITRC = 16 then
    exit 0

  address ISPEXEC "TBCREATE SMPDSNS NOWRITE" ,
                  "NAMES(TSEL TSMPDSN)"

I execute this code by typing %SMPSAVE next to the spool output line on the "H" SDSF panel and it runs fine until it gets to this point in the REXX:

    114 *-* address ISPEXEC "TBCREATE SMPDSNS NOWRITE" ,
                             "NAMES(TSEL TSMPDSN)"
        >>>   "TBCREATE SMPDSNS NOWRITE NAMES(TSEL TSMPDSN)"
 ISPS118S SERVICE NOT INVOKED. A VALID ISPF ENVIRONMENT DOES NOT EXIST.
        +++ RC(20) +++

Does anyone know why it says I don't have a valid ISPF environment and how I can get around this?

I've done quite a bit in the past with REXX, including writing REXX code to handle line commands, but this is the first time I've tried to use ISPEXEC commands within this code.

Thank you, Alan

1

There are 1 best solutions below

0
Lionel B Dyck On

This is a challenge that many have had - I wrote a tool many years ago that did this and then last year created a new tool using the SDSF REXX API that is more generalized.

If nothing else you can borrow from it for your own needs or use as is.

You can find it here: https://github.com/lbdyck/sdsfxdd

The syntax may look convoluted but it actually fairly simple:

%sdsfxdd JOBname(jobname(jobid)) +
   STEPname(stepname) +
   DDname(ddname) +
   HLQ(high-level-qualifier) +
   QUALifier(qualifier) +
   SUFfix(suffix) +
   LISt(list) +
   OWNer(owner) +
   SYStem(sys) +
   DATE(date)

This allows you to run it as a step within your job (probably the last step).

Hope this helps