Sum fields in sort jcl
Sort JCL to Sum Values - SUM FIELDS
Aggregation or Summation is the process of adding the fields based on list of Items to find the SUM total.
The Aggregation/Summation can be done with the help of SUM FIELDS. The following is the syntax for SUM FIELDS.
SUM FIELDS = (Start-Position,Length,Format)
For example to SUM the field which starts at position 50 and having length 8 and format = Zoned decimal we should write as:
SUM FIELDS = (50,8,ZD)
Consider you have given a file and asked you sum the values which are present at position 16,17 in the file. how could you do that ?
The following example explains how we can do this with the help of SUM FIELDS option of SORT utility.
Following is the file which we are considering to SUM the values
In the above screen shot we can see that at position 16,17 we have a numeric values. Our requirement is to sum all these values and final result should be as shown in the below screen shot
The following is the JCL which gives the above result
What above JCL does
In the above JCL we can see that there two files
File1(SORTIN file): TEST.SORT.SUMFILDS.INPUT.FILE
File2(SORTOUT file): TEST.SORT.SUMFILDS.OUTPUT.FILE
The contents in the File1 are as shown in the screen 1(see above screen shot). The above JCL sorts the contents of File1 by considering all the record as key and sums the values in the specified position(i.e position 16 and length 1) and writes the output to the SORTOUT file(i.e File2)
After this JCL is executed the output of the File2 is as shown in the screen shot screen 2
The following JCL code also does the above discussed functionality
More by this Author
Sort can be used to split the file into multiple files. SORT parameter OUTLIM is used to copy the contents of file into multiple files. The following are the examples to split the file using OUTLIM
In our previous tutorial we have learned how to send an email from mainframe JCL. This part of the tutorial explains how we can send an email with an attachment from mainframe with JCL code. IBM utility IEBGENER is...
No comments yet.