What’s new at MAINFRAMES 360
(Updates May '11)...
- We are a cosmopolitan community of 400 members, from around the globe.
- Working on writing and publishing articles on CICS.
- Special article on "How do I learn Mainframe Programming"

Wednesday, July 29, 2009

Sort, Merge and Copy Files


Q. What is DFSORT?

DFSORT is a free software-program supplied by IBM. This powerful software can help you sort(arrange) the data, merge it, copy and analyse it, and generate different Reports.

With DFSORT Tool, you could aggregate(SUM-up) data. For example, I have a list of the Employees working in the company, the Department under which they work and the salaries they are paid.

Image292

Say, you want to know the breakup of the total-Salary, by each department. Just like the Auto-sum facility in Microsoft-Excel, I can run the DFSORT Tool to Sum-up the cell-values on the Salary column(15,5), by each Department(10,2) and generate a report. I just code couple of these instructions for DFSORT.  

Image293

And, voila! Here’s what the report looks like.

Image294 
With DFSORT Software, you can analyse data and produce different Business-reports. DFSORT is not just another sort-tool, it is a complete power-packed analysis and reporting tool from IBM.

Q. How do I run the DFSORT Tool?

To use the DFSORT Tool, you run the free-software Program SORT. The SORT Software-Program expects you to supply four Files.

         Image295

When you work with the SORT Software, //SYSIN DD File(the Brain of SORT Program) is where SORT Expects to read the Processing-Instructions. These special-instructions control the processing. Hence, you need to craft the SYSIN Control-Instructions skillfully or with dexterity. You would hear Mainframe Programmers, refer to "Control-Instructions" as the SORT Control-Card.

This is how I write a Job, to run the SORT Software-Program. I have set SORTIN DD Statement to point to my Input-Data File SYSADM.EMPLOYEE.LIST. This list of Employees Data is processed by the SORT Program, according to the Processing-Instructions given at SYSIN DD Statement. Just as you would keep all your Holiday Trip-photo's together in one folder, it's good to create a Library or PDS of the frequently used SORT Control-cards. My Personal Library for all SORT Control-Cards is  SYSADM.DEMO.CNTLCARD. Under it, I have stored the Control-Instructions in a Member SUMSAL.

Image296

After processing the Data, the Output Records are stored in SORTOUT File which points to SYSADM.EMPLOYEE.SORT.OUT. The Log of the SORT Program is stored in SYSOUT File. To run the SORT Program, keep the above JCL in your Back-pocket as a pre-defined template. All you'd need to do, is plug-in the right SORT Control-card.

Q. What are the rules to be followed while writing a SORT Control Card?
Any Control Instructions like SORT, MERGE etc. scan be written anywhere between Columns 2-71.

Image297

All SORT Control Instructions follow the same general format. They consist of an Operation like SORT or MERGE and so on, followed by operands. The operand has a Parameter - FIELDS. The FIELDS Parameter is assigned values, in the form of parameter=value or parameter=(value1,value2,...).
Q. What are the different Data-Formats in SORT Software-Program?

DFSORT supports different Data-Formats. To process data, you need to tell DFSORT what's the type of data – are they Textual Character Strings,  or is it Numeric Integer data – in DISPLAY, Binary or Packed Decimal format, or are they Floating-point numbers, are you processing Dates or Times, what is the data-format exactly?

I've prepared a List of the different Data-Formats commonly used in DFSORT, and the corresponding COBOL Data-type.

  Image298 

Q. How do I sort the data in the File on Key Fields?

On an MS-Excel Spreadsheet, every cell named like A1, B2 and so on. Like-wise, when data is stored in a Mainframe-file each field or column is numbered. How do you tell SORT Software Program, the data in which column or Field is to be processed? How do you refer to a particular-field or column?

Image299

To refer to any column, you must know the position and the Length. For example, the first-name start at Position 1, and have Length=7. Thus, the first-name column is (1,7). Like-wise the Middle-name column is
(11,10). The Last-name Column would be (21,10). 

The above EMPLOYEE Input Data File has First-name, Middle-name and Last-name as the Key-Fields. I want to sort the Data-Records in Alphabetical order of the Key-Fields. How to write the SORT Control-Card?

To arrange(sort) the data-records, in order of the Key-Fields, you code SORT Operation. The SORT operation takes a parameter FIELDS. FIELDS Parameter specifies the Key-Fields of the Data-Record. I wrote the SORT Control Card like this -

Image300

FIELDS Parameter specifies the key fields, followed by the Data-format. Since , first-name , middle-name and Last-name are Textual Character Strings, I’ve specified the format as CH. I want to arrange the data in Ascending order, so I’ve coded A. D stands for Descending.

When you run the SORT Software Program, with above Control-Card, the Output Dataset looks like this -

Image301

Q. How do you Merge Datasets?

Say, you have got a List of Books present on the Physics Shelf of a Library. stored in the Mainframe File SYSADM.PHYSICS.BOOK.LIST. The Books are sorted alphabetically by the Title.

Image302

The Mainframe File SYSADM.CHEM.BOOK.LIST contains the List of Books kept on the Chemistry Shelf of the Library. The Chemistry Books are arranged as well by the title.

Image303

The Librarian proposes to have a new shelf for Basic Sciences, which shall house both Physics and Chemistry Books. For this , the Librarian  needs a combined list of Physics and Chemistry books, in the right alphabetical order of the Title. How do I Merge the Physics-books with the Chemistry-books, such that the Output is sorted? How to write the SORT Control-Card?

To Merge-and-mix the Data Records of two Files, you code the MERGE Operation. Like the SORT Operation, the MERGE Operation has a FIELDS Parameter. The FIELDS Parameter, specifies the Key-Field or column, on which the two files are to be Merged. This is how, I've coded the SORT Control Card, to merge the Two Datasets on the Title Column -

Image304

The data-records are to be merged by Alphabetical-order of the Title Field, which starts at Position 1, and is 39 Bytes wide. The Title Column is thus referred to as (1,39) in the FIELDS Parameter. The Title is Textual Character string, so the Data-Format is CH, and I want to arrange in the Ascending Order – A.

When you run the SORT-Software with the above Control-Card, the Output Dataset SYSADM.BASIC.SCIENCES.MERGE.OUT looks like this -

Image305

When you run the SORT-Software, to process many Files(not just 1 Dataset), say you wanna Merge 2 Files, or 3 Files, instead of coding //SORTIN DD Card, you code //SORTIN01 DD, //SORTIN02 DD, //SORTIN03 DD Cards and so on..

Image306 

Related Posts Plugin for WordPress, Blogger...

Note :

Protected by Copyscape Online Copyright Protection
© Copyright – Quasar Chunawalla, 2010.
Note : The copyrights of all the material, text and pictures posted in this website belong to the author. Any instance of lifting the material from this website, shall be considered as an act of plagiarism. For any clarifications, please drop me a line at
 
back to top