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.

Syntax:

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)




Example JCLs

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


Screen 1

(Click on the image for better view)
(Click on the image for better view)

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

Screen 2

(Click on the image for better view)
(Click on the image for better view)

The following is the JCL which gives the above result

Screen 3

(Click on the image for better view)
(Click on the image for better view)

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

Screen 4

(Click on the image for better view)
(Click on the image for better view)

More by this Author


Comments

No comments yet.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working