/* REXX */
/*
 *
 * %Z%%W% %I%
 *
 * =========================================================================
 * Licensed Materials - Property of IBM
 * "Restricted Materials of IBM"
 * (C) Copyright IBM Corp. 2005, 2008. All Rights Reserved
 * 
 * DISCLAIMER: 
 * The following [enclosed] code is sample code created by IBM 
 * Corporation.  This sample code is not part of any standard IBM product 
 * and is provided to you solely for the purpose of assisting you in the 
 * development of your applications.  The code is provided 'AS IS', 
 * without warranty of any kind.  IBM shall not be liable for any damages 
 * arising out of your use of the sample code, even if they have been 
 * advised of the possibility of such damages.
 * =========================================================================
 *
 * Sample JZOS rexx script which uses the new REXX / SDSF interface
 * to obtain sysout data for a specific jobname(jobid) and write it to stdout.
 *
 * This sample is intended to be invoked as a child process from the
 * Java sample class: com.ibm.jzos.sample.MvsJobOutput
 *
 */

parse source opsys command_type exec_name .
mid = "<"exec_name">"

parse arg jobname jobid
if jobname == '' | jobid = '' then
   do
      say mid 'Invalid syntax; arguments jobname and jobid are required'
      exit 1
   end

rc=isfcalls('ON')
ISFPREFIX = jobname
ISFOWNER  = '*'
Address SDSF "ISFEXEC" "ST"
if RC <> 0 then
   do
   Say mid "ISFEXEC ST RC="RC
   exit 2
   end

do ix=1 to JOBID.0
   if JOBID.ix = jobid then
      do
         Address SDSF "ISFACT ST TOKEN('"TOKEN.ix"') PARM(NP ?) ( prefix JDS_"
         if RC <> 0 then
            do
               Say mid "ISFEXEC ST PARM(NP ?) RC="RC
               exit 2
            end

         Address SDSF "ISFACT ST TOKEN('"TOKEN.ix"') PARM(NP SA)"
         if RC <> 0 then
            do
               Say mid "ISFEXEC ST PARM(NP SA) RC="RC
               exit 2
            end
            
         do jx=1 to isfddname.0
            Address MVS "EXECIO * DISKR" isfddname.jx "(STEM line. FINIS"
            stepid = JDS_DDNAME.jx "/" JDS_STEPN.jx "/" JDS_PROCS.jx
            if RC <> 0 then
               do
                  Say mid "0*** RC="RC "reading DDNAME="isfddname.jx "for stepid ***"
                  exit 2
               end
            sep.0 = 1
            sep.1 = " <<<" stepid ">>>"
            Address MVS "EXECIO 1 DISKW STDOUT (STEM sep."
            Address MVS "EXECIO" line.0 "DISKW STDOUT (STEM line."
         end
      leave
      end
end

exit 0
