Thursday, February 28, 2013

JCL to copy N records from the Mth record of a File


The Following jcl can be used to copy N number of Records from the Mth Column of an Input File to the Output File

//STEP020  EXEC PGM=SORT                        
//SORTIN   DD DSN=<INPUT FILE>, DISP=SHR
//SORTOUT  DD DSN=<OUTPUT FILE>,DISP=SHR
//SYSIN    DD *                                 
  SORT FIELDS=COPY,SKIPREC=50001,STOPAFT=20000
/*                        
//SYSOUT   DD SYSOUT=*    
This will Copy 20000 records starting from the 50001th Record of the input File.

JCL to stop copying records from one file to another

The Following JCL can be used to Stop the copying of records from input file to output after a specific number of records :-

//JOB CARD
//STEP010  EXEC PGM=SORT                              
//SORTIN   DD DSN=<Input file>, DISP=SHR
//SORTOUT  DD DSN=<OUTPUT FILE>,
//            DISP=SHR
//SYSIN    DD *                                       
  SORT FIELDS=COPY,STOPAFT=50000                      
/*                                                    
//SYSOUT   DD SYSOUT=*                                
//SYSUDUMP DD SYSOUT=*                                
//*                                                   
The above jcl will stop the copying after 50000 records

JCL to Extract first N number of records from a File

We can use the ENDREC parameter to get the first 1000 records from a file and copy it to another file. The Sample JCL is as follows :--

//JOBCARD
//STEP01   EXEC  PGM=SORT                                 
//SYSOUT   DD    SYSOUT=*                                 
//SYSPRINT DD    SYSOUT=*                                 
//SORTIN   DD    DSN=<INPUT FILE>,           
//         DISP=SHR                                       
//SORTOUT  DD    DSN=<OUTPUT FILE>,                  
//         DISP=SHR                                       
//SYSIN    DD    *                                         
  SORT FIELDS=COPY                                         
  OUTFIL FILES=OUT,ENDREC=1000                             
/*                                                         

We can give any value in the ENDREC field. Depending on the value, the extraction will happen from the input file.

INCLUDE CONDITION

The Include Condition serves the opposite purpose for the Omit Condition. In this case, the Data mentioned in the Include condition will only be considered for Data Sort. The Sample is as given below :-

//JOB CARD
//*                                                       
//STEP001 EXEC PGM=SYNCSORT                               
//SORTIN  DD DSN=<input File>,                 
//           DISP=SHR                                     
//SORTOUT DD DSN=<output File>,                            
//           DISP=SHR                                     
//SYSOUT DD SYSOUT=*                                      
//SYSIN  DD *                                             
  SORT FIELDS=COPY                                        
  INCLUDE COND=(01,06,CH,EQ,C'VVTEST')                    
/*                                                        
Here the check will happen from the 1st column for the next 6 bytes and will include records if the value of the same is VVTEST.

OMIT Condition

Suppose we have an input file layout as given below :-


(TITLE)        (NAME)     (DOB)
MATHS         RAM         11111991
ENGLISH      KRISH      01011990


Suppose we have to sort the above data excluding the header(TITLE). For this we can use OMIT Condition in the SORT JCL. It can be included as follows :-

//JOB CARD
//*                                                     
//STEP001 EXEC PGM=SYNCSORT                             
//SORTIN  DD DSN=<INPUT FILE NAME>,               
//           DISP=SHR                                   
//SORTOUT DD DSN=<OUTPUT FILE NAME>,            
//           DISP=SHR ( give parameters if u have not created input file)                                   
//SYSOUT DD SYSOUT=*                                    
//SYSIN  DD *                                           
  SORT FIELDS=COPY                                      
  OMIT COND=(01,01,CH,EQ,C'(')                          
/*                                                      
//*                                                

In the omit Condition, the Parameters are as follows :-

OMIT COND=(<start column>,<length of field from starting column>,CH,EQ,C'<field>')