Sunday, 3 February 2013

COBOL Prog to read record from RRDS file

COBOL Prog to read record from RRDS file :

IDENTIFICATION DIVISION.                       
PROGRAM-ID. FILREAD.                           
ENVIRONMENT DIVISION.                          
CONFIGURATION SECTION.                         
OBJECT-COMPUTER. IBM-390.                      
SOURCE-COMPUTER. IBM-390.                      
INPUT-OUTPUT SECTION.                          
FILE-CONTROL.                                  
    SELECT INFILE ASSIGN TO DD1                
    ORGANIZATION IS RELATIVE                   
    ACCESS MODE IS RANDOM                      
    RELATIVE KEY IS WS-RRN                     
    FILE STATUS IS FS1.                        
DATA DIVISION.                                 
FILE SECTION.
                                  
FD INFILE.                                     
01 INREC.                                      
    05 EID                    PIC X(05).           
    05 FILLER             PIC X(01).           
    05 ENAME            PIC X(06).           
    05 FILLER             PIC X(01).           
    05 ESAL                 PIC 9(05).           
    05 FILLER             PIC X(62).           
WORKING-STORAGE SECTION.                       
01 FS1                          PIC X(02).           
01 WS-RRN                 PIC 9(04).           
PROCEDURE DIVISION.                            
    PERFORM OPEN-PARA.                         
    PERFORM READ-PARA.                         
    PERFORM CLOSE-PARA.                        
    STOP RUN.                                  
OPEN-PARA.                                     
    OPEN INPUT INFILE                          
    DISPLAY ' OPEN FILE STATUS ' FS1.          
    MOVE 3 TO WS-RRN.                          
READ-PARA.                                     
    IF FS1 = '00'                              
       READ INFILE                             

         INVALID KEY                          
           DISPLAY ' RECORD NOT FOUND '       
         NOT INVALID KEY                      
           DISPLAY
' RECORD VALUE IS ' INREC  
       END-READ                               
    END-IF.
                                   
CLOSE-PARA.                                   
    CLOSE INFILE                              
    DISPLAY ' CLOSE FILE STATUS ' FS1.        

No comments:

Post a Comment