Tags

, , , , ,

SORT JOIN – UNPAIRED RECORDS INDICATOR

Records from 2 files can be joined used SORT. An indicator can used to see from which the file the record has been written to the output file.

//JKE5 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTJNF1 DD DSN=FIRST.FILE,DISP=SHR
//SORTJNF2 DD DSN=SECOND.FILE,DISP=SHR
//F1ONLY DD SYSOUT=*
//F2ONLY DD SYSOUT=*
//BOTH DD SYSOUT=*
//SYSIN DD *
* Control statements for JOINKEYS application
JOINKEYS FILE=F1,FIELDS=(1,10,A),SORTED,NOSEQCK
JOINKEYS FILE=F2,FIELDS=(7,10,A),SORTED,NOSEQCK
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(F1:1,14,F2:1,20,?)
* Control statements for main task (joined records)
OPTION COPY
OUTFIL FNAMES=F1ONLY,INCLUDE=(35,1,CH,EQ,C’1′),
BUILD=(1,14)
OUTFIL FNAMES=F2ONLY,INCLUDE=(35,1,CH,EQ,C’2′),
BUILD=(15,20)
OUTFIL FNAMES=BOTH,INCLUDE=(35,1,CH,EQ,C’B’),
BUILD=(1,14,/,15,20)
/*

IF1 file. FILE=F1 tells DFSORT that the ddname for the F1 file is |SORTJNF1. FIELDS=(1,10,A) tells DFSORT that the key is in positions |1-10 ascending. Since SORTED is specified, indicating that the records are already in order by the specified binary key, DFSORT will copy |the SORTJNF1 records. Since NOSEQCK is specified, DFSORT will not |check that the records are in order by the key. (Only use NOSEQCK |if you know for sure that the records are in order by the key.)

The second JOINKEYS statement defines the ddname and key for the |F2 file. FILE=F2 tells DFSORT that the ddname for the F2 file is |SORTJNF2. FIELDS=(7,10,A) tells DFSORT that the key is in positions |7-16 ascending. Since SORTED is specified, indicating that the records |are already in order by the specified binary key, DFSORT will copy |the SORTJNF2 records. Since NOSEQCK is specified, DFSORT will not |check that the records are in order by the key. (Only use NOSEQCK |if you know for sure that the records are in order by the key.)

The JOIN statement tells DFSORT that the joined records should |include the unpaired F1 and F2 records as well as the paired F1/F2 |records.

The REFORMAT statement defines the fields to be extracted for the |joined records in the order in which they are to appear, and includes |an indicator in the last position that will be set to ‘1’ if the key |is found only in the F1 file, ‘2’ if the key is found only in the |F2 file, or ‘B’ if the key is found in the F1 file and in the F2 file. | FIELDS=(F1:1,14,F2:1,20,?) tells DFSORT to create the joined records |as follows:

Joined Record Positions Extracted from

|———————– —————–

|1-14 F1 positions 1-14

|15-34 F2 positions 1-20

|35 Indicator of where key was found

The OPTION COPY statement tells DFSORT to copy the joined records. | The OUTFIL statements use the indicator in position 35 to determine |where to find the F1 or F2 fields in the joined records and where |to write the fields (F1ONLY, F2ONLY or BOTH).

If you would like to Earn Free Stocks, Credit card Points and Bank account Bonuses, Please visit My Finance Blog

You may also like to look at:

Important SQL CODES and ABEND CODES
SORT JOIN – TO JOIN TWO FILES BASED ON A KEY
KNOW YOUR MAINFRAME
REXX – INITIAL SETUP
HOW TO SUBMIT A BATCH JOB FROM THE CICS PROGRAM
CICS – EXEC interface block – EIBRESP Values
CICS – EXEC interface block Fields
Flow of control between COBOL programs, run units, and CICS
CICS INTERVIEW QUESTIONS
CICS TIPS
COBOL – COPY and INCLUDE statements
COBOL – PERFORMANCE IMPROVEMENT
COBOL – SIGN STORED IN COMP, COMP-3 AND DISPLAY FORMATS
SHORTEST COBOL PROGRAM
RESTART LOGIC IN COBOL DB2 Program
GOBACK – EXIT PROGRAM – STOP RUN
Continuation lines in COBOL
Computational items – COMP, COMP 1 , COMP 2, COMP 3
COBOL program format
cobol indicator area column-7 and area a and area b
COBOL INTERVIEW QUESTIONS
COBOL TIPS
COBOL COMPILER OPTIONS
The IDENTIFICATION DIVISION