Friday, 1 February 2013

Read KSDS file with alternate index

1) Define KSDS -

//STEP010     EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//SYSIN        DD *
                                      
         DEFINE CLUSTER                         -
         (                                                         -                                            

           NAME(NAXXXXA.TEST.KSDS) -
           KEYS(5,0)                                       -
           CYL(3,3)                                         -
           CISZ(4096)                                     -
           FREESPACE(10,15)                      -
           RECORDSIZE(80,80)                   -
           INDEXED                                      -
           )
 
/*   

2) COPY data to KSDS -

//STEP010     EXEC PGM=IDCAMS
//SYSPRINT  DD SYSOUT=*
//SYSOUT     DD SYSOUT=*
//IN01            DD *

21400 SANDIP 33333
21500 MANDIP 44444
21600 RANDIP 55555
21700 BALDIP 66666
                                                               
//OUT01       DD DSN=NAXXXXA.TEST.KSDS,DISP=OLD
//SYSIN        DD *
     REPRO                                 -
     INFILE(IN01)                       -
     OUTFILE(OUT01)

/*                                                                                                                                                                                                           

3) Define AIX -
                                                              
//STEP020     EXEC  PGM=IDCAMS                          
//SYSPRINT DD    SYSOUT=*                            
//SYSOUT    DD    SYSOUT=*                         
//SYSIN        DD    *
                                        
      DEFINE AIX                                                         -    
      (                                                                              -    
       NAME(NAXXXXA.TEST.KSDS.AIX)              -    
       RELATE(NAXXXXA.TEST.KSDS)                  -    
       KEYS(6,6)                                                            -    
       CYL(2,3)                                                               -    
       RECORDSIZE(80,80)                                           -    
       UPGRADE                                                            -    
      )                                                                                                      

 /*                                                                                                                

4) Define Path

//STEP020     EXEC  PGM=IDCAMS                        
//SYSPRINT DD    SYSOUT=*                          
//SYSOUT    DD    SYSOUT=*                          
//SYSIN        DD    *
                                 
      DEFINE PATH                                                            -  
      (                                                                                    -  
       NAME(NAXXXXA.TEST.KSDS.AIX.PATH)         -  
       PATHENTRY(NAXXXXA.TEST.KSDS.AIX)         -  
       UPDATE                                                                      -  
      )
                                            
/*
                                                
5) BLDINDEX - Copy data from base cluster to AIX

//STEP020     EXEC  PGM=IDCAMS                                 
//SYSPRINT DD    SYSOUT=*                                   
//SYSOUT   DD    SYSOUT=*                                   
//IN01          DD    DSN=NAXXXXA.TEST.KSDS,DISP=SHR             
//OUT01      DD    DSN=NAXXXXA.TEST.KSDS.AIX,DISP=OLD         
//SYSIN     
DD    *                                          
      BLDINDEX                                  -           
      INFILE(IN01)                              -           
      OUTFILE(OUT01)
                                        
/*   

 6) Cobol Program to Access data thru AIX -

       IDENTIFICATION DIVISION.                                        
       PROGRAM-ID. RDKSDS.                                             
      
ENVIRONMENT DIVISION                                          
       INPUT-OUTPUT SECTION.                                           
       FILE-CONTROL
.                                                   
           SELECT INFILE ASSIGN TO DD1                                 
          
ORGANIZATION IS INDEXED                                     
           ACCESS MODE IS RANDOM
                                       
           RECORD KEY IS EID                                           
           ALTERNATE KEY IS ENAME                                      
           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(06).                                   
           05 FILLER        PIC X(61).                                   
       WORKING-STORAGE SECTION.                                        
       01 FS1                   PIC X(02).                                   
       01 SWITCH          PIC X(01).                                   
           88 EOF              VALUE 'Y'.                                   
           88 NOT-EOF     VALUE 'N'.                                   
       PROCEDURE DIVISION.                                             
           PERFORM OPEN-PARA.                                          
           PERFORM READ-PARA.                                          
           PERFORM CLOSE-PARA.                                         
           STOP RUN.                                                   

       OPEN-PARA.                                                     
           OPEN INPUT INFILE                                          
           DISPLAY ' OPEN FILE STATUS ' FS1.                          
           MOVE 'MANDIP' TO ENAME.                                    
       READ-PARA.                                                     
           IF FS1 = '00'                                              
               READ INFILE                                            
                KEY IS ENAME                                          
                 INVALID KEY                                          
                    DISPLAY ' KEY IS INVALID'                         
                 NOT INVALID KEY                                      
                    DISPLAY INREC                                     
               END-READ                                               
           END-IF.                                                    
       CLOSE-PARA.                                                    
           CLOSE INFILE                                               
           DISPLAY ' CLOSE FILE STATUS ' FS1.                         








JCL to execute this cobol program -
 //STEP010     EXEC IGYWCLG,MEM=RDKSDS
//SYSPRINT DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//GO.DD1     DD DSN=XX1234A.KSDS.VSAM,DISP=SHR
//GO.DD11   DD DSN=XX1234A.KSDS.VSAM.PATH,DISP=SHR
//COBOL.SYSIN DD DSN=XX1234A.JCLLIB.SELFTEST.Y2013.COB(&MEM),
//                   DISP=SHR
//LKED.SYSLMOD DD DSN=XX1234A.COBOL.LOADLIB(&MEM),

//                   DISP=SHR
//*

4 comments:

  1. Thank you so much for explaining in a great way!!

    ReplyDelete
  2. how GO.DD11 for path will be use in program

    ReplyDelete
  3. Thank you so much dear

    ReplyDelete
  4. Thank you so much dear

    ReplyDelete