Join Contents of Files
Two files can be merged in JCL using JOINKEYS operand of SORT utility. This is similar to the JOIN clause in SQL DB2.
The sample JCL is used with both files mentioned in SORTJNF1 and SORTJNF2 and REFORMAT operand. The sort card is substituted as per the requirement.
//EXEC PGM=SORT |
Sample Input File 1(colours):
Orange |
Sample Input File 2(fruits):
Apple |
Below are the control statements used for each criteria:
- Matched Records from Both Files (INNER JOIN)
In this case, both the matching records from file 1 and 2 will be copied.
SYSIN card:
//SYSIN DD * |
Output
Orange Orange |
- Matched Records and Non Matched Records from File 1(LEFT OUTER JOIN)
In this case, both the matching records and non matching records from file 1 will be copied.
SYSIN card:
//SYSIN DD * |
Output
Orange Orange |
- Matched Records and Non Matched Records from File 2(RIGHT OUTER JOIN)
In this case, both the matching records and non matching records from file 2 will be copied.
SYSIN card:
//SYSIN DD * |
Output
Apple |
- Matched Records and Non Matched Records from both files(FULL OUTER JOIN)
In this case, both the matching records and non matching records from both files will be copied.
SYSIN card:
//SYSIN DD * |
Output
Orange Orange |