How to submit a JCL from CICS

 

There are couple of ways in which you can submit a JOB from your CICS application program , the simplest way to do this is by using CICS Spool Interface commands to write your JCL directly to JES Spool , we will explore this in detail here, and also by using an extra partition TDQ to write you JCL and submit it by closing the queue .

 

Submitting a JCL using CICS JES Interface

Introduced as part of CICS/ESA 3.1, CICS provides a programing interface to JES (Job entry sub system of MVS) that allows CICS applications to create and retrieve spool files.  To use the JES interface you CICS installation should have the DHFSIT SPOOL parameter set to YES (DFHSIT SPOOL=YES) .

CICS  provides the below 4 SPOOL interface commands

  • SPOOLOPEN (INPUT|OUTPUT)
  • SPOOLREAD
  • SPOOLWRITE
  • SPOOLCLOSE

All access to a JES spool file must be completed within one logical unit of work or in one task in a CICS program, it should be noted that any task that process data sets larger than 1000 records, either for INPUT or for OUTPUT, are likely to have a performance impact on the rest of CICS.

Submitting a batch Job typically consist of 3 steps , we will see each step in detai

 

Screen Shot 2015-05-01 at 1.58.59 PM

 

STEP 1 : SPOOLOPEN OUTPUT

This command opens a spool report for write from CICS and defines its characteristics. It results in allocation of an output file and enables the user to acquire a token for the report which will be written . This token is unique for the report and will be used to identify the report in write and close spool statements. A task can create multiple output spool files, and it can have more than one open at a time; operations on different files are kept separate by the token.

EXEC CICS SPOOLOPEN OUTPUT                        

        NODE(‘LOCAL’)                                    

        USERID(‘INTRDR’)                                 

        TOKEN(WS-TOKEN)                                  

        RESP(WS-RESP)                                    

END-EXEC.

USERID : Specifies the 8-character identifier of the destination userid that processes the report.One such destination is the JES internal reader, which normally has the reserved name INTRDR. If you want to submit a job to an MVS system, you write a spool file to its internal reader and file must contain all the JCL statements required to execute the job, in the same form and sequence as a job submitted through TSO.

NODE : Specifies the 8-character identifier of a destination node that the system spooler uses to route the file. Node can be given as “LOCAL” if your Job is to run on local system.

TOKEN : Specifies the 8-character CICS-allocated token used to identify a report.

STEP 2 : SPOOLWRITE

This command writes data to a spool report , in our case to the JES internal reader , the report to which data needs to be written is identified using the unique token supplied by the SPOOLOPEN in step1 . Spool files are sequential, each SPOOLWRITE adds one record to the file and when the file is complete, the task releases the file to JES for delivery or processing by issuing a SPOOLCLOSE

EXEC CICS SPOOLWRITE                      

        TOKEN(WS-TOKEN) 

        FROM(WS-JCL-STMT)

        FLENGTH(WS-JCL-LENGTH)  

        RESP(WS-RESP)                                                  

END-EXEC.

 FLENGTH : Specifies the fullword binary variable that is to be set to the length of the data that is transferred

TOKEN: 8-character unique token allocated for the report by the SPOOL OPEN command in step1

FROM : Data area from which data needs to be taken for writing.

STEP 3 : SPOOLCLOSE

The SPOOLCLOSE command closes a CICS spool report,issuing a SYNCPOINT or RETURN command implicitly issues a SPOOLCLOSE command for any open report.

     EXEC CICS SPOOLCLOSE                                                     TOKEN(WS-TOKEN)              

          RESP(WS-RESP)                                 

     END-EXEC. 

TOKEN :  8-character unique token allocated for the report by the SPOOL OPEN command in step1

CICS Program to submit JCL using  JES Interface Commands

IDENTIFICATION DIVISION.
PROGRAM-ID. PGM1.
DATA DIVISION.                                              
WORKING-STORAGE SECTION.
01  WS-ARRAY.                                                 
     05  WS-JCL-LINE             PIC X(80) OCCURS 6 TIMES INDEXED BY I.  
01  WS-JCL-STMT                  PIC X(80)
01  WS-TOKEN                     PIC X(08)
01  WS-RESP                      PIC S9(4) COMP.
01  WS-JCL-LENGTH                PIC S9(8) COMP VALUE 80.
01 WS-MESSAGES.
   02 WS-MSG-1                   PIC X(30) VALUE "SPOOL OPEN ERROR".
   02 WS-MSG-2                   PIC X(30) VALUE "SPOOL WRITE ERROR".
   02 WS-MSG-3                   PIC X(30) VALUE "SPOOL CLOSE ERROR".

COPY DFHAID. 
PROCEDURE DIVISION.                                         
0000-MAINLINE.                                       
  PERFORM 1000-MOVE-PARA
     THRU 1000-EXIT.
  PERFORM 2000-SPOOL-OPEN
     THRU 2000-EXIT.
  PERFORM 3000-SPOOL-WRITE
     THRU 3000-EXIT.
  PERFORM 4000-SPOOL-CLOSE
     THRU 4000-EXIT.
 EXEC CICS
      RETURN
 END-EXEC.
STOP RUN.

1000-MOVE-PARA.
 MOVE ‘//CICSJOB1  JOB 'FILE DELETE ' MSGCLASS=J,CLASS=A’                    
                               TO WS-JCL-LINE(1).          
   MOVE ‘//STEP001    EXEC PGM=IEFBR14′                  
                               TO WS-JCL-LINE(2).              
   MOVE ‘//DELDD  DD DSN=TEST.DATE.FILE1,'
                               TO WS-JCL-LINE(3).             
   MOVE ‘//          DISP=(MOD,DELETE,DELETE),UNIT=DASD’      
                               TO WS-JCL-LINE(4).             
   MOVE ‘//*** END oF JOB  *****’                  
                               TO WS-JCL-LINE(5).              
   MOVE ‘/*EOF'                            ’ 
                               TO WS-JCL-LINE(6).    
1000-EXIT.
  EXIT. 
 
2000-SPOOL-OPEN.
   EXEC CICS SPOOLOPEN OUTPUT                        
      NODE(‘LOCAL’)                                   
      USERID(‘INTRDR’)                                
      TOKEN(WS-TOKEN)                                 
      RESP(WS-RESP)                                    
   END-EXEC.  
                                        
   EVALUATE WS-RESP
      WHEN DFHRESP(NORMAL)
           CONTINUE
      WHEN OTHER
           EXEC CICS SEND
                FROM (WS-MSG-1)
                LENGTH(LENGTH OF WS-MSG-1)
                ERASE
          END-EXEC          
          EXEC CICS
              RETURN
          END-EXEC       
    END-EVALUATE.

2000-EXIT
  EXIT.

3000-SPOOL-WRITE.
   PERFORM VARYING I FROM 1 BY 1 UNTIL I > 
       MOVE WS-JCL-LINE(I) TO WS-JCL-STMT
       EXEC CICS SPOOLWRITE                           
            TOKEN(WS-TOKEN)                                    
            FROM(WS-JCL-STMT)                                 
            FLENGTH(WS-JCL-LENGTH)                                  
            RESP(WS-RESP)                                    
      END-EXEC                                           
      EVALUATE WS-RESP
      WHEN DFHRESP(NORMAL)
           CONTINUE
      WHEN OTHER
           EXEC CICS SEND
                FROM (WS-MSG-2)
                LENGTH(LENGTH OF WS-MSG-2)
                ERASE
          END-EXEC
          EXEC CICS
              RETURN
          END-EXEC       
      END-EVALUATE
   END-PERFORM.
3000-EXIT
  EXIT.

4000-SPOOL-CLOSE.
   EXEC CICS SPOOLCLOSE                                                  
      TOKEN(WS-TOKEN)                                  
      RESP(WS-RESP)                                    
   END-EXEC.                                           
   EVALUATE WS-RESP
      WHEN DFHRESP(NORMAL)
           CONTINUE
      WHEN OTHER
           EXEC CICS SEND
                FROM (WS-MSG-3)
                LENGTH(LENGTH OF WS-MSG-3)
                ERASE
          END-EXEC
          EXEC CICS
              RETURN
          END-EXEC       
   END-EVALUATE.
4000-EXIT
  EXIT
Mainframe Wiki © 2015 Frontier Theme