IBM
supplied a utility to sort, Merge, Copy a PS dataset into another PS dataset.
DFSORT
gives you versatile data handling capabilities.
The
input to this operation is a dataset which contains record which you want to
sort, Merge, Copy into output dataset.
So
Input dataset will remain as it is and according to given condition your output
dataset will change like rec. In ascending or descending order etc.
Sorting
Dataset.
SORT
means Arrange a dataset.
It’s
easy to sort a dataset having few records manually but when a records are more
then you need to use DFSORT utility.
Utility
name is DFSORT but while defining a program the name of program must be SORT.
SYNTAX:
Step1 exec PGM=SORT
I
will show you all the Sort option with program so you will understand.
1)SORT by Ascending Order
Here
my input dataset contains below 5 records now i have to sort It with Ascending
order and put the ascending output records in AK999.PS.NEW which is my output
dataset.
Nextt
step is write a SORT program.
SORTIN
is the name of my input dataset.
SORTOUT
is my output dataset which i am going to create so i have given its all
parameter.
If
you have already a dataset created then use DISP=OLD.
SYNTAX
of SORT card:
SORT FIELDS=(1,5,CH,A)
(1,5)-This is my key field to tell
operating system that the starting position of my input dataset column is from
1 and it will continues next 5 bytes so Sort the record by reffering these key
field.
CH- This is format of my dataset record.
It will tell the operating system that my data contain character as well as
number fields. This is commonly used parameter also we can use
ZD- will tell operating system that my
data is numeric one though it contain + or –ve sign.
A or D- A for Ascending Order and D is for
Descending order.
After
submitting job will gives me MAXCC=00 and my output dataset contents are:
2)SORT by Descending Order
This
will arrange records in descending order.
Just
one change in above program in the SORT control card just replace A by D.
SYNTAX:
SORT
FIELDS=(1,5,CH,D)
Can I SORT my input file itself
Ascending or Descending?
Yes
you can just open the input file in edit mode
In
command window just type SORT A or SORT D and press enter you will see the
changes in input file itself.
My
input file records are:
My
Command :
OUTPUT:
If
you want to use multiple columns then see below command will also accept :
How to SORT the records by
considering multiple Key Fields?
Suppose
my input dataset has following data:
First
field is Name of Employee
Second
field is Shift allowance
Third
field is Department
My
requirement is I have to sort the records according to Name field and Shift
allowance field
So
my SORT card will tell the operating system please check both two fields and
satisfy both condition and arrange data for me in my output dataset.
Name
field is within column 1-7 (6 bytes) and
Shift
allowance field is within column 9-14 (5 bytes).
Order
is Ascending or Descending.
Sort
Program:
SORT
card is:
Or
same command you can hit on command line when you open file in EDIT mode like
below:
If my input dataset has duplicate
records How can i eliminate?
See
following data in my input file:
Here
Avinash is duplicate record and i have to eliminate duplicate records while
rearranging so i just add one line in my control card i.e.
SUM
FIELDS=NONE
Program
:
OUTPUT:
If i want to copy all eliminated
records in one dataset then i use XSUM field as well as add SORTXSUM Dataset
name in program like below.
How to SUM up the column values?
Input dataset:
Now
i have to add middle column so i use below program to sum up middle columns
value:
It
will give me the output
Copying dataset using SORT option.
If
i want to copy a dataset as it is through DFSORT utility as i can copy it
through IEBCOPY utility also.
Input
file:
Program:
Output:
No comments:
Post a Comment