DFSORT – Simple sort with multiple columns using SORT FIELDS

1 min


This tutorial will teach you the very basics of IBM’s DFSORT. DFSORT’s main purpose is to sort, however it does a lot more than the sort – basically SORT can do almost any types of data processings.

Lets say you have a sequential dataset (PS) with below data. It has 3 fields –

  • employee name
  • employee salary
  • department that employee belongs to

INPUT DATA:

----+----1----+----2----+----3----+----4----+----5
SAM   11234 ACCOUNTS
JOHN  78916 IT
STEVE 62541 ACCOUNTS
TIM   90013 HR

Now we want to sort it based on department, employee name then the salary.

To achieve this we need to tell SORT from which columns each of the fields are starting and their sort order.

To sort the department column which starts from column 13 by ascending order we need to feed below to SORT:

(13,8,CH,A) 

13 = Starting column
8 = Length of the string
CH = Character type data
A = Ascending Order

Similarly for employee name and salary we can put the followings:

Putting it all together, SORT input would be –

(13,8,CH,A,1,5,CH,A,7,5,CH,A)

Complete JCL:

//YOUR.JOB.CARD.HERE
//*
//STEP1 EXEC PGM=SORT
//** You can give your input PS file here instead of in stream data
//SORTIN DD *
SAM   11234 ACCOUNTS
JOHN  78916 IT
STEVE 62541 ACCOUNTS
TIM   90013 HR
/*
//** You can give your Output PS file here instead of in stream data
//SORTOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(13,8,CH,A,1,5,CH,A,7,5,CH,A)
/*

OUTPUT:

----+----1----+----2----+----3----+----4----+----5
SAM   11234 ACCOUNTS
STEVE 62541 ACCOUNTS
TIM   90013 HR
JOHN  78916 IT

Drop a comment if you like this article or face any problem using the above code.


We bring the latest tech, software news and stuff that matters. Stay in touch via Telegram, Twitter, YouTube, and Facebook and never miss an update!

SEE ALSO:   DFSORT - Merge two files using SORT
Join our Telegram channel and stay informed on the move.

Also Read


Like it? Share with your friends!

Arindam

Creator of debugpoint.com. All time Linux user and open-source supporter. Connect with me via Telegram, Twitter, LinkedIn, or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x