Sie sind auf Seite 1von 5

Merge two files horizontally

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.

INPUT FILE - 1 (FILE WITH DUPLICATES)


EMPLOYMENT_DATE EMPLOYEE_NUMBER
27JUN1972 300001
31JAN1992 300002
04MAY1987 300002

11NOV1981 300003
23OCT1997 300004

INPUT FILE - 2 (UNIQUE FILE)


Employee_Number Employee_name
300001 JOHN
300002 DAVID
300003 JEFF

The output should looks like this.


OUTPUT FILE - 3 (HORIZONTALLY MERGED FILE WITH DUPLICATE)
Employee_number Employee_name Employment_date
300001 JOHN 27JUN1972
300002 DAVID 31JAN1992
300002 DAVID 11NOV1981
300003 JEFF 17NOV1985

Below is the JCL to use for SORT


/**************************************************************************/
/**** *********************** Using Sort **************************************/
/**************************************************************************/
//TESTSORT JOB (*),"IBM",CLASS=6,PRTY=10,NOTIFY=&SYSUID,
// MSGCLASS=X,MSGLEVEL=(1,1),TYPRUN=SCAN
//STEP050

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

OUTFIL VTOF, BUILD = (8,16,11X,C'U'),VLFILL=C'$'


//*
//*VTOF converting Variable to Fixed
//*
//STEP100

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).

Below is the JCL to use for ICETOOL


/**************************************************************************/

/**** *********************** Using Sort **************************************/


/**************************************************************************/
//TESTSORT JOB (*),"IBM",CLASS=6,PRTY=10,NOTIFY=&SYSUID,
// MSGCLASS=X,MSGLEVEL=(1,1),TYPRUN=SCAN
//*************
//STEP01

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 *

COPY FROM(IN2) TO(T1) USING(CTL1)


COPY FROM(IN1) TO(T1) USING(CTL2)
SPLICE FROM(T1) TO(OUT) ON 7,6,ZD) VLENOVLY WITHALL WITH(5,1) WITH (27,9) USING CTL3
/*
//CTL1CNTL DD *
INREC BUILD=(1,7,8:C'BB',10:5)
/*
//CTL2CNTL DD *
INREC BUILD=(1,7,8:C'VV',10:15,6,27:5,9)
/*
/*
//CTL3CNTL DD *
OUTFIL FNAMES=OUT,INCLUDE=(8,2,CH,EQ,C'VB'),
BUILD=(1,7,8:7)
/*******************************************************************************

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.

Das könnte Ihnen auch gefallen