在 z/OS 汇编程序中,我可以读取 JCL 输入流两次吗?

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

有没有办法多次读取 z/OS JCL 输入流? (一个来自 //SYSIN DD *)。我知道我可以在第一次读取流时缓存它,然后从缓存的数据中读取,但我对该解决方案不感兴趣。

注意:语言为汇编语言

取决于语言。这个答案在 HLASM 中提供了一个示例,并在末尾提供了对 'C' 语言参考的引用。

对于 Assembler,当您 CLOSE DCB 时,您需要 REWIND。请参阅 FINISH 处的标签,了解这是如何完成的。

可能还有其他方法,但这在 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 以上并执行这个 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=*                                                       

你会得到这个输出

您将看到相同的 SYSIN 数据重复三次。

对于 'C' 程序,C Compiler 的 IBM 文档中的此参考提供了一些关于倒带的提示。

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.

您正在寻找的是可能的,但实现取决于语言。