Beruflich Dokumente
Kultur Dokumente
In mainframe there will be occasion when we want to merge files horizontally for
report purpose or to reformat to the next successive execution. During those
instances instead of writing new program there are two tools available handy which
can be used through JCL.
1) Via SORT facility
2) Using ICETOOL
Though ICETOOL does very good job of reformatting and executing, it has
limitation while running in production. So SORT can be used instead. But for
Test environment ICETOOL works very well
Here is the requirement.. File-1 has duplicates records and File-2 is unique.
We should merge horizontally both the files based upon key fields.
Key point to note is that both input files should be of the same record length and
same format type.
I.e. For each occurrence of File-1 should merge with file-2 based upon unique key
field. Here key field is EMPLOYEE_NUMBER.
1) LRECL = 20 and RECFM = VB
2) In Data - 2, the Key field is in position - 1 (EMPLOYEE_NUMBER) and format is
numeric
In Data - 1, the Key field is in position - 11(EMPLOYEE_NUMBER) and format is
numeric
3) The position and other fields to be merged are,
Fields Position
Employee_Name - 5 char (Data - 1)
Employment_date - 1 Numeric (Data - 2)
4) First file has duplicate records.
Example.
11NOV1981 300003
23OCT1997 300004
EXEC PGM=SORT
//SYSOUT
DD SYSOUT=*
//SORTIN
DD DSN=TSO.USER.SORT (UNIQFILE),DISP=SHR
//SORTOUT
DD DSN=&&T1, DISP=(,PASS),SPACE=(TRK,(50,50),RLSE)
//SYSIN
DD *
//SORT FIELDS=COPY
EXEC PGM=SORT
//SYSOUT
DD SYSOUT=*
//SORTIN
DD DSN=TSO.USER.SORT(DUPSFILE)DISP=SHR
//SORTOUT
DD DSN=&&T1,DISP=(,PASS),SPACE=(TRK,(50,50),RLSE)
//SYSIN
DD *
//SORT FIELDS=COPY
OUTFIL VTOF, BUILD=(18,6,X,24:5,10,C'D')
//*
//STEP150
EXEC PGM=SORT
//SYSOUT
DD SYSOUT=*
//SORTIN
DD DSN=&&T1,DISP=SHR
//SORTOUT
DD SYSOUT=*
//SYSIN
DD *
//SORT FIELDS=(1,6,CH,a)EQUALS
OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(29:SEQNUM,8,ZD,RESTART=(1,6))),
IFTHEN=(WHEN=GROUP,BEGIN=(34,8,ZD,EQ,1),PUSH=(1:1,19))
OUTFIL FTOV,VLTRIM=C' ',
INCLUDE=(33,1,CHEQ,C'D',AND,7,13,CH,GT,C' '),
IFTHEN=(WHEN=INIT,BUILD=(1,32)),
IFTHEN=(WHEN=INIT,FINDREP=(IN=C'$',OUT=C''))
//*
//*FINDREP indicates that you want to do a find and replace operation. IN identifies
the constant you are looking for (the "find" constant) and OUT identifies the
constant you want instead (the "replace" constant).
EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG
DD SYSOUT=*
//IN1
DD DSN=TSO.USER.SORT(DUPSFILE),DISP=SHR
//IN2
DD DSN=TSO.USER.SORT(UNIQFILE),DISP=SHR
//T1
DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,
(55)),DISP=(MOD,PASS),LRECL=32
//OUT
DD DSN=TSO.USER.SORT(OUTFILE)
//TOOLIN
DD *
Here
The first COPY operator creates reformatted IN1 records in TEMP1.
The second COPY operator creates reformatted IN2 records in TEMP1. The
reformatted IN1 records have blanks where the reformatted IN2 WITH fields will go.
The reformatted IN2 records have the ON field from IN2 in the same place as in the
reformatted IN1 records, and have the IN2 data where we want it to go in the
reformatted IN1 records. We made the reformatted IN1 and reformatted IN2 records
the same size so we can put them all in the TEMP1 data set and use TEMP1 as input
to the SPLICE operator.
The SPLICE operator sorts the records from TEMP1 using the ON field. TEMP1 has
the reformatted IN1 records before the reformatted IN2 records. The spliced records
are created from the base records and the overlay records in TEMP1. Whenever two
records are found with the same ON field, the WITH field from the second record
(reformatted IN2 overlay record) is overlaid on to the first record (reformatted IN1
base record). The resulting spliced records are written to the COMBINE data set.
The base records and overlay records are the same length. This is always required
for fixed-length records, and is required for variable-length records unless VLENMAX
or VLENOVLY is specified.