0% found this document useful (0 votes)
70 views1 page

DFSORT MERGE Files

The document explains the MERGE operation used to combine multiple sorted datasets into a single sorted dataset, assuming the input datasets are already sorted. It provides syntax rules, examples of merging datasets based on specified key fields, and emphasizes the importance of pre-sorting the input datasets. Additionally, it outlines the necessary parameters for sorting and provides scenarios for simple and multiple key field merges.

Uploaded by

josephdcruz.sgma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views1 page

DFSORT MERGE Files

The document explains the MERGE operation used to combine multiple sorted datasets into a single sorted dataset, assuming the input datasets are already sorted. It provides syntax rules, examples of merging datasets based on specified key fields, and emphasizes the importance of pre-sorting the input datasets. Additionally, it outlines the necessary parameters for sorting and provides scenarios for simple and multiple key field merges.

Uploaded by

josephdcruz.sgma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

 %

HOME › UTILITIES › DFSORT

MERGE Files

Search topics in this tutorial..

( END

( SORT FIELDS

 MERGE Files

( Including or +

omitting records

( Summing Records +

( Reformatting with +

fixed fields

( Join Records

Other JCL Utilities

( IDCAMS

( IEBCOPY

( IEBGENER

( ICETOOL

( IEFBR14

( IKJEFT01

MERGE Files

← →

The MERGE operation is used to combine


multiple sorted datasets into a single
sorted dataset. Unlike SORT, MERGE
assumes that the input datasets are
already sorted and simply merges them
into a final output in sorted order based on
specified key fields.

The purpose of SORT merge -

Combines multiple sorted datasets


Maintains sorting order

Syntax -

//SYSIN DD *
SORT FIELDS=(field1_starting_pos
A or D, ...)
/*

field1_starting_position Specifies the


starting position
of field1 in the file

field1_length Specifies the


length of the
field1 used for
sorting.

field1_format Specifies the


format of the
field1.

A or D Specifies the
sorting order. A
for ascending and
D for descending.

Rules to Remember -

All input datasets must be pre-sorted


on the key fields that you specify in
the MERGE operation. If the input
datasets are not sorted, the MERGE
will not work correctly.
Each dataset should have similar
record formats.

Examples -
Scenario1 - Simple MERGE on a Character
Field.

//STEP01 EXEC PGM=SORT


//SORTIN01 DD DSN=MATEPK.INPUT.FILE1
//SORTIN02 DD DSN=MATEPK.INPUT.FILE2
//SORTOUT DD DSN=MATEPK.OUTPUT.FILE
// DISP=(NEW,CATLG,DELET
// SPACE=(CYL,(100,10)),
//SYSIN DD *
SORT FIELDS=(1,10,CH,A)
/*

This merges two sorted datasets based on


a 10-character field starting at position 1, in
ascending order. The input datasets
MATEPK.INPUT.FILE1 and
MATEPK.INPUT.FILE2 must already be
sorted on the same key fields. The merged
output is written to MATEPK.OUTPUT.FILE.

Scenario2 - MERGE with Multiple Key


Fields.

//STEP01 EXEC PGM=SORT


//SORTIN01 DD DSN=MATEPK.INPUT.FILE
//SORTIN02 DD DSN=MATEPK.INPUT.FILE
//SORTOUT DD DSN=OUTPUT.DATASET,DIS
// SPACE=(CYL,(100,10)),
//SYSIN DD *
SORT FIELDS=(1,5,CH,A,10,3,ZD,D)
/*

The first key is a 5-character field starting


at position 1, sorted in ascending order.
The second key is a 3-byte Zoned Decimal
(ZD) field starting at position 10, sorted in
descending order. The datasets are
merged based on these two key fields.

FULL EXAMPLE 

PREVIOUS TOPIC NEXT TOPIC



SORT FIELDS Including or

omitting
records

About

ABOUT US

CAREERS

PRIVACY POLICY

TERMS AND
CONDITIONS

HELPING

CONTACT US

FOLLOW US

      

© 2014 - 2025 Mainframestechhelp. All


Rights Reserved.

You might also like