Thursday, 31 January 2013

Abends :

When JCL/JOB terminates abnormally/unsuccessfully, it is called as job abend. It will give some specific abend code for specific reasons.


for example :

1) S322 - Time abend, when sufficient time is not provided to job.
2) SOC7 - Bad data
3) SO13 - Member not found
4) S806 - load module not found
5) S722 - When there is no space to write ouput in sysout.
6) S222 - Cancelled by operator.
7) S522 - SYSOUT filled with display messages and there is no space to write output in SYSOUT area.

Wednesday, 30 January 2013

GDG : Generation data groups 

In production there are daily, weekly, quarterly, monthly or yearly running jobs, so in order to take BKUP of data, generally we use GDGs, there is no need to provide different names to datasets when you create, system on it's own will take care of it. 

These datasets are chronologically and functionally similar datasets.

Note : Under one GDG base datasets can be created with different combination of record length, record formats.


to create GDG datasets first we need to create GDG base, then GDG dataset can be created.
Maximum 255 datasets can be defined under one GDG base.

1) Create GDG base 

//OZA201AS JOB (GENERAL),'CRE GDG BASE',CLASS=A,   
//         NOTIFY=OZA201                     

//*     
//STEP1 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//SYSIN       DD *
DEFINE GDG -
(NAME(XA7384A.GDG.BASE) - 
LIMIT(10) -
NOEMPTY -
SCRATCH -
)
//*

This JCL will create GDG base.


Parameters : 

1) LIMIT - 
It specifies maximum number of datasets that can be created under one GDG base.

2) NOEMPTY - It specifies older version.

3) EMPTY      - It specifies all versions. 
Either EMPTY or NOEMPTY can be used at one time. 

4) SCRATCH - It will delete dataset. 

5) NOSCRATCH - It will uncatalog dataset.  
Either SCRATCH or NOSCRATCH can be used at one time. 

Different combinations - 

LIMIT(10)
NOEMPTY 
SCRATCH
This combination will allow to create maximum 10 datasets when 11th dataset will be created it will delete 1st dataset(Older version). 


LIMIT(10)

NOEMPTY 
NOSCRATCH
This combination will allow to create maximum 10 datasets when 11th dataset will be created it will Uncatalog 1st dataset(Older version). 

LIMIT(10)
EMPTY 
SCRATCH
This combination will allow to create maximum 10 datasets when 11th dataset will be created it will Delete all previous 10 versions. 

LIMIT(10)
EMPTY 
NOSCRATCH
This combination will allow to create maximum 10 datasets when 11th dataset will be created it will Uncatalog all previous 10 versions. 



JCL to create GDG dataset :

//OZA201AS JOB (GENERAL),'CRE GDG DS',CLASS=A,   
//         NOTIFY=OZA201                     
//*     
//STEP1 EXEC PGM=IEFBR14
//SYSPRINT DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//DD1          DD DSN=XX7384A.GDG.BASE(+1),
//                DISP=(NEW,CATLG,DELETE),
//                UNIT=SYSDA,
//                DCB=(LRECL=80,RECFM=FB,BLKSIZE=800),
//                SPACE=(CYL,(2,3))
//* 

here +1 indicates new version,

0 indicates current version
-1 indicates previous version
-2 older then -1 and so on.... 

XA7384A.GDG.BASE              
XA7384A.GDG.BASE.G0001V00     
XA7384A.GDG.BASE.G0002V00
XA7384A.GDG.BASE.G0003V00



Note : GDG dataset will be updated after completion of JCL only. 

Monday, 28 January 2013

Procedures :

when same code is used repetitively, then that code is coded seperately either in instream of JCL or as a member of PDS, which can be called in JCL. 
There are two tyes of procedures 
1) Cataloged procedures : 
Procedures which are saved as member of PDS. It doesn't have PEND statement at end.

CATPROC procedure saved in XX7384A.CATPROC.LIB

//CATPROC PROC
//STEP1      EXEC PGM=IEFBR14
//SYSPRINT DD SYSOUT=*
//SYSOUT    DD SYSOUT=*
//DD1          DD DSN=XX7384A.NEW.PS,
//                DISP=(NEW,CATLG,DELETE),
//                UNIT=SYSDA,
//                DCB=(LRECL=80,RECFM=FB,BLKSIZE=800),
//                SPACE=(CYL,(2,3))
//*


JCL to execute CATPROC procedure - 
//OZA201AS JOB (GENERAL),'CATPROC CALL',CLASS=A,NOTIFY=OZA201
//*
// JCLLIB ORDER=XX7384A.CATPROC.LIB
//STEP1  EXEC CATPROC
//* 
in this JCL CATPROC cataloged proceure is executed. 


2) Instream procedures : 
Procedure written instream of JCL is known as Instream procedure. Instream procedures are defined before exec statement. It starts with PROC statement and ends with PEND statment. Maximum 15 Instream procedures can be coded in on JOB.


//OZA201AS JOB (GENERAL),'INPROC CALL',CLASS=A,NOTIFY=OZA201
//*
//INPROC PROC
//STEP1       EXEC PGM=IEFBR14
//SYSPRINT DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//DD1         DD DSN=XX7384A.NEW.PS,
//               DISP=(NEW,CATLG,DELETE),
//               UNIT=SYSDA,
//               DCB=(LRECL=80,RECFM=FB,BLKSIZE=800),
//               SPACE=(CYL,(2,3))
//             PEND
//*
//STEPX EXEC INPROC
//*

Here stepx is executing INPROC procedure. 

Sunday, 27 January 2013

IBM UTILITIES


IBM Utilities are system defined utilities which will be invoked and executed when provided on step statement by PGM=Utility. Utilities are nothing but the load modules(Executable source in machin language which only machine will understand) which are defined by IBM (or system defined) there no need to provide path of load libraries for these Utilities.

Commonly used Utilities are as below -
1) IEFBR14     - To create, delete catlg or uncatlg datasets(PS or PDS).
2) IEBGENER - To copy data from PS file to PS file.
3) IEBCOPY   - To copy data from PDS file to PDS file.
4) IDCAMS    - Mainly IDCAMS utility is used to do operations like create & delete for VSAM or GDGs and copy for VSAM, GDGs or PS files. 
5) SORT         - There are many operations that can be performed thru SORT utility like - to sort file, to format output file or to copy records.
There are two types of SORT -   
1) DFSORT        - DFSORT is IBM product.
2) SYNCSORT  - SYNCSORT is SYNCSORT product.

From sysout messages we can identify which sort is getting invokded.

Like -
END SYNCSORT -  OZA201AS ( for SYNCSORT ) 
END OF DFSORT - OZA201AS ( for DFSORT)


IEFBR14 :
 Create PS file 

//OZA201AS JOB (GENERAL),'IEFBR14',CLASS=A,NOTIFY=OZA201
//*
//STEP1  EXEC  PGM=IEFBR14
//SYSPRINT DD  SYSOUT=*
//SYSOUT   DD   SYSOUT=*
//DD1        DD   DSN=OZA201.TEST.OUT,
//                     DISP=(NEW,CATLG,DELETE),
//                     SPACE=(TRK,(2,4)),UNIT=SYSDA,
//                     DCB=(LRECL=80,RECFM=FB,BLKSIZE=800,DSORG=PS)
//*


Output : This step will create PS file - OZA201.TEST.OUT.

IEBGENER :
IEBGENER utility is used to copy data from PS file to PS file.

//OZA201AS JOB (GENERAL),'IEBGENER',CLASS=A,NOTIFY=OZA201
//*
//STEP1  EXEC  PGM=IEBGENER
//SYSPRINT DD  SYSOUT=*
//SYSOUT   DD   SYSOUT=*
//SYSUT1   DD   DSN=OZA201.TEST.IN,DISP=SHR
//SYSUT2   DD   DSN=OZA201.TEST.OUT,
//                    DISP=(NEW,CATLG,DELETE),
//                    SPACE=(TRK,(2,4)),UNIT=SYSDA,
//                    DCB=(LRECL=80,RECFM=FB,BLKSIZE=800,DSORG=PS)
//SYSIN      DD  DUMMY
/*

Output : This JCL will copy data from input file to output file.        

   
IEBCOPY :
IEBCOPY is used to copy data from PDS file to PDS file.

//OZA201AS JOB (GENERAL),'IEBCOPY',CLASS=A,NOTIFY=OZA201
//*
//STEP1   EXEC  PGM=IEBCOPY
//SYSPRINT  DD  SYSOUT=*
//SYSOUT      DD  SYSOUT=*
//IN01            DD  DSN=OZA201.TEST.IN.PDS,DISP=SHR
//OUT01        DD  DSN=OZA201.TEST.OUT.PDS,DISP=OLD
//SYSIN         DD  *
         COPY INDD=IN01,OUTDD=OUT01
/*
//

Output : If 3 members are present in input PDS file then it will copy all 3 members in outpput file.


         COPY INDD=IN01,OUTDD=OUT01
         SELECT MEMBER=(MEM1,MEM2)

Output : This will copy MEM1 & MEM2 members in output file.

         COPY INDD=IN01,OUTDD=OUT01
         EXCLUDE MEMBER=MEM1

Output : This will copy all members except MEM1.


 
IDCAMS :
IDCAMS is used to perform create, delete and copy operations on VSAM files. PS files also can be copied by using IDCAMS. GDG base is created with IDCAMS utility.



1) Below JCL will perform below listed operations.
Copy data from PS file to PS
Copy data from VSAM file to VSAM
Copy data from VSAM file to PS
Copy data from PS file to VSAM file.

//OZA201AS JOB (GENERAL),'IDCAMS',CLASS=A,  
//         NOTIFY=OZA201                    
//*                                         
//STEP010  EXEC PGM=IDCAMS                  
//SYSOUT   DD  SYSOUT=*                     
//SYSPRINT DD  SYSOUT=*                     
//DD1      DD  DSN=OZA201.TEST.IN1,         
//             DISP=SHR                     
//DD2      DD  DSN=OZA201.TEST.OUT,DISP=OLD 
//SYSIN    DD  *                            
    REPRO INFILE(DD1) OUTFILE(DD2)          
                                            
/*                                          
//*                                       
  


2) To check whether file is empty or not. If file is empty job will give MAXX=04 and file is contains data it will give MAXCC=00 and will display first record in SYSPRINT.


//OZA201AS JOB (GENERAL),'IDCAMS',CLASS=A,
//         NOTIFY=OZA201                  
//*                                       
//STEP010  EXEC PGM=IDCAMS                
//SYSOUT   DD  SYSOUT=*                   
//SYSPRINT DD  SYSOUT=*                   
//DD1      DD  DSN=OZA201.TEST.IN,DISP=SHR
//SYSIN    DD  *                          
    PRINT INFILE(DD1) CHAR COUNT(1)                                        
/*                                        
//*                                       


NOTE : VSAM fiie operations and GDG creation will be covered later in respective topics.


SORT :
SORT can be used for many opertations like COPY output record formation, remove duplicates, copy selected rows or columns, comapre two files.

1) Sort file on the basis of emp-code

Input file Layout :
21400       sandip
21200       mandip     
21100       randip

emp-code starts from 1st column and length is 5 chars, emp-name starts from 7th column and lenght is 6 chars.


//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR       
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD
//SYSIN    DD  *                           
    SORT FIELDS=(01,05,CH,A)
/*                                         
//*                                        



Output :
21100       randip
21200       mandip     
21400       sandip

Note : Both input and output files are FB, if input and output files are VB then 4 bytes needs to added in starting position field.
ex : (05,05,CH,A)

2) SORT to copy the data as it is
//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR       
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD
//SYSIN    DD  *                           
    SORT FIELDS=COPY
/*                                         
//*
     


Output : This sort will copy data from input file to output file as it is.


3) SORT to copy required number of  records

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR       
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD
//SYSIN       DD  *                           
    SORT FIELDS=COPY,               

    SKIPREC=02,STOPAFT=05  
/*                                         
//*     


SKIPREC will skip the records and STOPAFT will stop copyin records.

Input file data :
aaa rec1
bbb rec2
ccc rec4
ddd rec5
eee rec6
ggg rec7
hhh rec8
kkk rec9

Output file data :
ccc rec4
ddd rec5
eee rec6
ggg rec7
hhh rec8

4) SORT to format output data :

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR    *(LRECL=80,RECFM=FB) 
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input)
//SYSIN      DD  *                           
    SORT FIELDS=COPY               

    OUTREC FIELDS=(01:01,03,05:05,03,1X,10:C'OUTPUT RECS',61X)   
/*                                         
//*
   


Input file data :
AAA REC
BBB REC


Output file data :
AAA REC OUTPUT RECS                                                           
BBB REC OUTPUT RECS
                                                           



5) SORT to remove duplicate records :

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR    *(LRECL=80,RECFM=FB) 
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input)
//SYSIN    DD  *                           
    SORT FIELDS=(07,06,CH,A)
    SUM FIELDS=NONE
        

/*                                         
//* 
Input File data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21400 SANDIP                                                           
21500 SANDIP                                                           
21200 RANDIP                                                           
21300 MANDIP                                                           
21700 KULDIP                                                           
21800 MANDIP                                                           
21900 MANDIP                                                           


Output file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21700 KULDIP                                                           
21800 MANDIP                                                           
21200 RANDIP                                                           
21400 SANDIP                                                           


 

6) SORT to copy duplicate records in seaperate file :

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN   DD  DSN=OZA201.SORT.IN,DISP=SHR    *(LRECL=80,RECFM=FB) 
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input)

//SORTXSUM DD  DSN=OZA201.SORT.XSUM,DISP=OLD *(same as of input)
//SYSIN    DD  *                           
    SORT FIELDS=(07,06,CH,A)
    SUM FIELDS=NONE,XSUM
        

/*                                         
//*
 


Input File data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21400 SANDIP                                                           
21500 SANDIP                                                           
21200 RANDIP                                                           
21300 MANDIP                                                           
21700 KULDIP                                                           
21800 MANDIP                                                           
21900 MANDIP                                                           


Output file data (SORTOUT) :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21700 KULDIP                                                           
21800 MANDIP                                                           
21200 RANDIP                                                           
21400 SANDIP      


Output file data (SORTXSUM) :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21900 MANDIP                                                           
21300 MANDIP                                                           
21500 SANDIP
                                                           

NOTE : SORTXSUM functionality doesn't work with DFSORT product, it only works with SYNCSORT. 

  
7) SORT to compare two input files for matching records :This sort will compare two input files on the basis emp-code field, if matches it will write records to output file.

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTJNF1 DD  DSN=OZA201.SORT.IN1,DISP=SHR  *(LRECL=80,RECFM=FB) 
//SORTJNF2 DD  DSN=OZA201.SORT.IN2,DISP=SHR  *(same as of input1)

//SORTOUT DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input1)
//SYSIN    DD  *        

      JOINKEYS FILE=F1,FIELDS=(01,05,A)
      JOINKEYS FILE=F2,FIELDS=(01,05,A)
      REFORMAT FIELDS=(F1:01,80)      
      SORT FIELDS=COPY
                
/*
//

Input1 file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21400 SANDIP KPO                                                       
21200 RANDIP BPO                                                       
21300 MANDIP BPO                                                       
21700 KULDIP KPO                     


Input2 file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21400                                                                  
21200                                                                  
21500                                                                  
21900                                                                   


Output file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21200 RANDIP BPO                                                       
21400 SANDIP KPO                                                       


To copy unmatching records in output file.

      JOINKEYS FILE=F1,FIELDS=(01,05,A)
      JOINKEYS FILE=F2,FIELDS=(01,05,A)

      JOIN UNPAIRED,F1,ONLY 
      REFORMAT FIELDS=(F1:01,80)      
      SORT FIELDS=COPY
   


Output file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
21300 MANDIP BPO                                                       
21700 KULDIP KPO                                                       




1) Compare two files and write all matching records to output file. (INNER JOIN - ONLY MATCHING ROWS) 

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    REFORMAT FIELDS=(F1:1,13,F2:1,12)      
    SORT FIELDS=COPY               
//*

OUTPUT:
21400 SANDIP 21400 PUNE
21500 RANDIP 21500 MUMBAI


=======================================================================
2) Compare two files and write matching as well as non-matching rows from File1 (LEFT OUTER JOIN - Matching and non-matching from F1) 

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED,F1
    REFORMAT FIELDS=(F1:01,13,F2:01,12)
    SORT FIELDS=COPY
//*

OUTPUT
21400 SANDIP 21400 PUNE
21500 RANDIP 21500 MUMBAI
21600 KULDIP
21800 MANDIP
21900 BALDIP 

=======================================================================
3) Compare two files and write NON-MATCHING rows from F1 ONLY. 
F2 we should not use in REFORMAT it will blank values 

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED,F1,ONLY 
    REFORMAT FIELDS=(F1:01,13) 
    SORT FIELDS=COPY
//*

OUTPUT: 
21600 KULDIP
21800 MANDIP
21900 BALDIP

=======================================================================
4) Compare two files and write matching as well as non-matching rows from File2 (RIGHT OUTER JOIN - Matching and non-matching from F2) 

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED,F2
    REFORMAT FIELDS=(F2:01,13) 
    SORT FIELDS=COPY
//*

OUTPUT: 
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN

=======================================================================
5) Compare two files and write ONLY non-matching rows from File2  

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED,F2,ONLY 
    REFORMAT FIELDS=(F2:01,13) 
    SORT FIELDS=COPY
//*

OUTPUT: 
22100 THANE
22200 KALYAN

=======================================================================
6) Compare two files and write matching as well non-matching rows (FULL OUTER JOIN)  

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//MATCH       DD SYSOUT=*
//NOMATCH1 DD SYSOUT=*
//NOMATCH2 DD SYSOUT=*
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED=F1,F2
    REFORMAT FIELDS=(F1:01,13,
                                  F2:01,13,?)
    SORT FIELDS=COPY
*
    OUTFIL FNAMES=MATCH,
    INCLUDE=(27,01,CH,EQ,C'B'),
    BUILD=(01,27,)
*
    OUTFIL FNAMES=NOMATCH1,
    INCLUDE=(27,01,CH,EQ,C'1'),
    BUILD=(01,13,27,01)     
*
    OUTFIL FNAMES=NOMATCH2,
    INCLUDE=(27,01,CH,EQ,C'2'),
    BUILD=(14,13,27,01)
//*

OUTPUT: 
MATCH:
21400 SANDIP 21400 PUNE     B
21500 RANDIP 21500 MUMBAI B  

NOMATCH1:
21600 KULDIP 1
21800 MANDIP 1
21900 BALDIP 1

NOMATCH2:
22100 THANE  2
22200 KALYAN 2

*****Similar type to above **** 
Write matching and unmatching both records from both files in two output files -
//SORTJNF1 DD *
21400 SANDIP PUNE
21500 BALDIP MUMBAI 
21600 KULDIP HYDERABAD
21700 RANDIP THANE
//SORTJNF2 DD *
21400 TIETO
21700 SYNTEL
21800 TCS
21900 HSBC
//MATCH DD SYSOUT=*
//NOMTACH DD SYSOUT=*
//SYSIN DD * 
  JOINKEYS FILE=F1,FIELDS=(1,5,A)
  JOINKEYS FILE=F2,FIELDS=(1,5,A)
  REFORMAT FIELDS=(F1:01,25,F2:01,15,?)
  SORT FIELDS=COPY
  OUTFIL FNAMES=MATCH,INCLUDE=(41,01,CH,EQ,C'B'),
  BUILD=(01,40,40X)
  OUTFIL FNAMES=NOMATCH,INCLUDE=(41,01,CH,EQ,C'1',OR,
                                                         41,01,CH,EQ,C'2'),
  IFTHEN=(WHEN=(41,CH,EQ,C'1'),BUILD=(1,25)),
  IFTHEN=(WHEN=(41,CH,EQ,C'2'),BUILD=(26,15))
//*
MATCH OUTPUT
21400 SANDIP PUNE       21400 TIETO
21600 KULDIP THANE      21700 SYNTEL

NOMATCH OUTPUT
21500 BALDIP MUMBAI 
21600 KULDIP HYDERABAD
21800 TCS
21900 HSBC
      
=======================================================================
7) Compare two files and write ONLY non-matching rows from F1 & F2  

//SORTJNF1
21400 SANDIP
21500 RANDIP
21600 KULDIP
21800 MANDIP
21900 BALDIP
//SORTJNF2
21400 PUNE
21500 MUMBAI
22100 THANE
22200 KALYAN
//SORTOUT       DD SYSOUT=*
//SYSIN DD *
    JOINKEYS FILE=F1,FIELDS=(1,5,A)
    JOINKEYS FILE=F2,FIELDS=(1,5,A)
    JOIN UNPAIRED=F1,F2,ONLY
    REFORMAT FIELDS=(F1:01,13,
                                  F2:01,13,?)
    SORT FIELDS=COPY

OUTPUT: 
MATCH:
21600 KULDIP                      1
21800 MANDIP                     1
21900 BALDIP                      1
                     22100 THANE  2
                     22200 KALYAN 2 

1 in the output file is printed because "?" was given in REFROMAT FIELDS.
==================================================


8) SORT to replace value of repetitive field :

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN    DD  DSN=OZA201.SORT.IN,DISP=SHR    *(LRECL=80,RECFM=FB) 
//SORTOUT  DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input)

//SYSIN      DD  *         
    SORT FIELDS=COPY                             
    OUTREC FINDREP=(IN=C'ABCD',OUT=C'ZZZZ')
      

/*

Input file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
SSSSSABCDSSSSSSSABCDSSSSSSSSSS                                         


Output file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
SSSSSZZZZSSSSSSSZZZZSSSSSSSSSS                                         


9) SORT to separate Odd and Even records from file :

This SORT will separate records on the basis of record number, if record number is odd, it will write record to ODD file, if record number is even then it will add record to EVEN file.

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN    DD  DSN=OZA201.SORT.IN,DISP=SHR   *(LRECL=80,RECFM=FB) 
//ODD        DD  DSN=OZA201.SORT.ODD,DISP=OLD *(same as of input)

//EVEN       DD  DSN=OZA201.SORT.EVEN,DISP=OLD *(same as of input)
//SYSIN      DD  *         
    SORT FIELDS=COPY             
    OUTFIL FNAMES=(ODD,EVEN),SPLIT

/*
//

Input file data :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
AAAAAAAAAAAAAAAAAAAAAAAAAA                                             
BBBBBBBBBBBBBBBBBBBBBBBBBB                                             
CCCCCCCCCCCCCCCCCCCCCCCCCC                                             
DDDDDDDDDDDDDDDDDDDDDDDDDD                                             
EEEEEEEEEEEEEEEEEEEEEEEEEE                                             
FFFFFFFFFFFFFFFFFFFFFFFFFF                                             


Output file data (ODD) :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
AAAAAAAAAAAAAAAAAAAAAAAAAA                                             
CCCCCCCCCCCCCCCCCCCCCCCCCC                                             
EEEEEEEEEEEEEEEEEEEEEEEEEE                                             


Output file data (EVEN) :
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
BBBBBBBBBBBBBBBBBBBBBBBBBB                                             
DDDDDDDDDDDDDDDDDDDDDDDDDD                                             
FFFFFFFFFFFFFFFFFFFFFFFFFF                                             


10) SORT to do addition of numeric field :

This SORT will perform addition of numeric field.

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//STEP010  EXEC PGM=SORT                   
//SYSOUT   DD  SYSOUT=*                    
//SYSPRINT DD  SYSOUT=*                    
//SORTIN    DD  DSN=OZA201.SORT.IN,DISP=SHR   *(LRECL=80,RECFM=FB) 
//SORTOUT DD  DSN=OZA201.SORT.OUT,DISP=OLD *(same as of input)

//SYSIN    DD  *         
   

    SORT FIELDS=(05,01,CH,A) 
    SUM FIELDS=(14,05,ZD)
    

/*
//


Input File data :
21300 SANDIP 10000                                                     
21400 MANDIP 15000                                                     
21500 RANDIP 15000                                                     
21600 KULDIP 20000                                                     
21700 BALDIP 25000                          


Output File data :                            
21300 SANDIP 85000



11) SORT to copy all duplicate records in one file and unique records in one file - For Syncsort v1.4 :


//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A,
//         NOTIFY=OZA201              
//*                                   
//STEP010  EXEC PGM=SORT              
//SYSOUT   DD  SYSOUT=*               
//SYSPRINT DD  SYSOUT=*               
//SORTIN    DD  *

01 SANDIP
02 MANDIP
03 RANDIP
04 BALDIP
//               DD  * 
02 MANDIP
04 MANJIT
//SORTOUT   DD  SYSOUT=*
//SORTXDUP DD  SYSOUT=*
//SYSIN    DD  *            
    SORT FIELDS=(01,09,CH,A)
    DUPKEYS ALLDUPS,XDUP

/*
//



11) SORT to add header & trailer in sort alongwith dates in different formats. ( used DFSORT)  


//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A,
//         NOTIFY=OZA201              
//*                                   
//STEP010  EXEC PGM=SORT              
//SYSOUT     DD  SYSOUT=*               
//SYSPRINT   DD  SYSOUT=*                

//SYSNAMES  DD  *                
MDT,S'&YR4.&LMON.&LDAY'
SDT,S'&LYR2.&LMON.&LDAY'
//SORTIN      DD  *
21400 SANDIP PUNE
21500 MANDIP PUNE
//SORTOUT   DD  SYSOUT=*
//SYSIN    DD  *            
       SORT FIELDS=COPY
   OUTFIL FILES=OUT,
   HEADER1=('00HEADER','YYYYMMDD:',MDT,'YYMMDD:',SDT),
   TRAILER1=('99TRAILER',COUNT=(M11,LENGTH=8)),REMOVECC
/*
//




SORTOUT data :   
00HEADERYYYYMMDD:20140219YYMMDD:140219
21400 SANDIP PUNE
21500 MANDIP PUNE
99TRAILER00000002

Instead of MDT & SDT If we give
DATENS=(4MD) ==> 20140219 (YYYYMMDD) 
DATENS=(DM4) ==> 19022014 (DDMMYYYY)
DATE=(4MD-)   ==> 2014-02-19 (YYYY-MM-DD)
DATE=(DM4-)   ==> 19-02-2014 (DD-MM-YYYY)
DATE=(4MD/)   ==> 2014/02/19 (YYYY/MM/DD)

DATE=(DM4/)   ==> 19/02/2014 (DD/MM/YYYY)

Format for time 

//SYSNAMES DD * 
TIM,S'&LHR.&LMIN.&LSEC'


NOTE : We can use SYSNAMES not only for header record but also for detail record also. 

Type SYM command in spool area and press ENTER it will show system names available.

                         

ICETOOL :
ICETOOL to find out number of records present in the file.

//OZA201AS JOB (GENERAL),'SANDIP WALSINGE',CLASS=A, 
//         NOTIFY=OZA201                   
//*                                        
//SANDIP   EXEC PGM=ICETOOL                   
//TOOLMSG  DD  SYSOUT=*                         
//DFSMSG   DD  SYSOUT=*                         
//IN            DD  DSN=OZA201.TEST.IN,DISP=SHR 
//TOOLIN    DD  *                                
     COUNT FROM(IN)         
   

/*

OutPput:
    COUNT FROM(IN)                            SYNCSORT CALLED WITH IDENTIFIER "0001"          
NUMBER OF RECORDS PROCESSED: 000000000000008    
OPERATION COMPLETED WITH RETURN CODE 0          
                                                
SYNCTOOL PROCESSING COMPLETED WITH RETURN CODE 0



                                  

6) HOW to reverse file in JCL SORT:

//STEP1 EXEC PGM=SORT
//SORTIN DD *
SANDIP 123 DDD AAAAAAAA
MANDIP 345 AAA BBBBBBBBBBBBBBBBBBBBB
RANDIP 456 HHH QQQQQQQQQQQQQ
KULDIP GGGGG AAAAAAAAAA
//SORTOUT DD SYSOUT=*
//SYSIN DD *
    INREC FIELDS=(01,80,SEQNUM,08,ZD)
    SORT FIELDS=(81,08,ZD,D)
    OUTREC FIELDS=(01,80)
//*

OUTPUT:
KULDIP GGGGG AAAAAAAAAA
RANDIP 456 HHH QQQQQQQQQQQQQ 
MANDIP 345 AAA BBBBBBBBBBBBBBBBBBBBB
SANDIP 123 DDD AAAAAAAA