SwiftWarrior
SwiftWarrior

Reputation: 1964

in z/OS Assembler, can I read a JCL input stream twice?

Is there a way to read a z/OS JCL input stream more than once? (one that comes from a //SYSIN DD *). I know I could cache the stream the first time I read it, and then read from the cached data, but I'm not interested in that solution.

Note: the language is Assembler

Upvotes: 2

Views: 462

Answers (1)

Hogstrom
Hogstrom

Reputation: 3761

Depends on the language. This answer provides an example in HLASM and a reference to the 'C' Language reference at the end.

For Assembler you'll need to REWIND when you CLOSE the DCB. See the label at FINISH to see how this is done.

There may be other ways but this worked for me on z/OS 2.4

         PRINT NOGEN                                                     
* ------------------------------------------------------------------- *  
*                                                                     *  
*  SYSIN2                                                             *  
*                                                                     *  
*  @author Hogstrom                                                   *  
*                                                                     *  
*  Test to see if one can re-read SYSIN more than one time.           *  
*                                                                     *  
* ------------------------------------------------------------------- *  
R0       EQU   0                                                         
R1       EQU   1                                                         
R2       EQU   2                                                         
R3       EQU   3                 * Number of times to loop               
R4       EQU   4                                                         
R5       EQU   5                                                         
R6       EQU   6                                                         
R7       EQU   7                                                         
R8       EQU   8                                                         
R9       EQU   9                                                         
R10      EQU   10                                                        
R11      EQU   11                                                        
R12      EQU   12                * Base Register                         
R13      EQU   13                                                        
R14      EQU   14                                                        
R15      EQU   15                                                        
*                                                                        
SYSIN2   CSECT                                                           
         STM   R14,R12,12(R13)                                           
         LR    R12,R15                                                   
         USING SYSIN2,12                                                 
*                                                                        
         ST    R13,SaveArea+4                                            
         LA    R0,SaveArea                                               
         ST    R0,8(R13)                                                 
         LA    R13,SaveArea                                              
*                                                                        
         OPEN  (SYSIN,(INPUT))                                           
         OPEN  (SYSOUT,(OUTPUT))                                         
         LA    R3,3              Number of times to read SYSIN 
*                                                                        
GETAGAIN DS   0H                                                         
         GET   SYSIN,INREC       Read the next rec        
         PUT   SYSOUT,INREC      Write that bad boy out   
         B     GETAGAIN                                                  
FINISH   DS   0H                 Invoked at End of Data of SYSIN 
         CLOSE (SYSIN,REWIND)    Close SYSIN and rewind                                        
         OPEN  (SYSIN,(INPUT))   Open it up again 
         BCT   R3,GETAGAIN       Repeat the madness  
*                                                                        
         CLOSE SYSIN                                                     
         CLOSE SYSOUT                                                    
*
         L     R13,SaveArea+4                                           
         LM    R14,R12,12(R13)                                          
         XR    R15,R15                                                  
         BR    R14                                                      
 *                                                                       
 SYSIN    DCB   DSORG=PS,MACRF=(GM),DDNAME=SYSIN,EODAD=FINISH,          *
                RECFM=FB,LRECL=80,BLKSIZE=0                              
 SYSOUT   DCB   DSORG=PS,MACRF=(PM),DDNAME=SYSOUT,                      *
                RECFM=FBA,LRECL=133,BLKSIZE=0                            
 *                                                                       
 INREC          DC  CL132' '                                             
 SaveArea       DS  18F                                                  
                LTORG                                                    
          END                                                            

Assemble the above and execute this JCL

//SYSIN2   JOB (CCCCCCCC),'HOGSTROM',                                         
//             MSGLEVEL=(1,1),                                                
//             MSGCLASS=O,                                                    
//             CLASS=A,                                                       
//             NOTIFY=&SYSUID                                                 
//*                                                                           
//STEP1  EXEC PGM=SYSIN2                                                      
//STEPLIB DD  DSN=USER1.TEST.LOADLIB,DISP=SHR                                 
//*                                                                           
//SYSIN  DD  *                                                                
 REC 1 OF 3                                                                   
 REC 2 OF 3                                                                   
 REC 3 OF 3                                                                   
/*                                                                            
//SYSOUT  DD  SYSOUT=*                                                        
//SYSUDUMP DD  SYSOUT=*                                                       

And you'll get this output

SYSIN2 Job Output

You'll see the same SYSIN data repeated three times.

For a 'C' program this reference in the IBM documentation for the C Compiler provides some hints about rewinding.

To open an in-stream data set, call the fopen() or freopen() library function and specify the ddname of the data set. You can open an in-stream data set only for reading. Specifying any of the update, write, or append modes fails. Once you have opened an in-stream data set, you cannot acquire or change the file position except by rewinding. This means that calls to the fseek(), ftell(), fgetpos(), and fsetpos() for in-stream data sets fail. Calling rewind() causes z/OS XL C/C++ to reopen the file, leaving the file position at the beginning.

What you're looking for is possible but the implementation is language dependent.

Upvotes: 7

Related Questions