Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
Hi,
I have an input file which looks like below:
Code:
ACTIVE 1A 1000
ACTIVE 3A 1000
INACTIVE 1B 1000
INACTIVE 3B 1000
Now I have to add two more columns in the above file showing the Percentage as status level and of total, i.e., my output file should look like:
Code:
STATUS CODE COUNT % SUB % TOTAL
ACTIVE 1A 1000 50.00% 25.00%
ACTIVE 3A 1000 50.00% 25.00%
SUB TOTAL 2000
INACTIVE 1B 1000 50.00% 25.00%
INACTIVE 3B 1000 50.00% 25.00%
SUB TOTAL 2000
GRAND TOTAL 4000
I'm thinking of writing a program, but before that I'm posting here to get any ideas/suggestions if I can do it using SORT. I'm using SYNCSORT FOR Z/OS 1.4.1.0R
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
Quote:
How are you calculating percentage (Formula)
% SUB Calculation:
There are two types of ACTIVE Status Code. Their sum is 2000. So for each Code type It will be (1000/2000)*100 = 50 %. Same with inactive.
% TOTAL Calculation:
There are total four recordds. Their total sum is 4000. So percentage for each status code is (1000/4000)*100 = 25%.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
By the time you print the first line, you already need to know the Total and Subtotal.
Is the number of lines fixed, or limited in some other way?
I don't think your SyncTool has RESIZE, which would have allowed you to easily get all the records into one record, leaving you just the task of formatting the output from one record.
Without RESIZE, you have to do the work of RESIZE yourself. Using GROUPs on a field set with SEQNUM, PUSHing all the data you need, for a decreasing number of RECORDS=.
INCLUDE= the final SEQNUM only into OUTFIL. Calculate and format.
The output., subject to typos, should be one long record containing all the input records. The first 80 bytes are the last record, then one byte count (set to '4') then 80 bytes from the first record, then 80 bytes from the second record, then 80 bytes from the third record.
If you take out the OUTFIL, you will see four long records, and you can get the idea of how the data is built up, The RECORDS= are for neatness and reuse. If there are only four input records, they are not needed. The SEQNUM is used so that the data from each individual record will end up in its own position on the long record.
Then just mess with the data and use BUILD with /, the slash-operator, to produce the required format output on multiple records/lines.
Obviously the whole 80 bytes are not needed, but I've no time to count columns or test.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Yes, when there is only one value for a data-item, or when the multiples can be dealt with easily (there are two, and only two, sub-totals) then symbols/SYMNAMES can be used by pre-processing the file and obtaining the values.
In the case of repetitions of the grouped data, symbols/SYMNAME will not work conveniently, or not work at all.
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
Thanks Ashwin, Pandora box and Bill.
Number of lines is not fixed and can have duplicates. I had posted here some represenational data, related to the part of the report where I was facing problems.
Thank you all for posting yur ideas here. I have found a working solution, using the methods that have been suggested here.
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
Sorry I have not been very clear. I just needed an idea. So I chose to remove certain details which I felt I can handle. I just wanted to keep my post simple and to the point.
The whole report consists of several sections. One of the section was to calculate the percentage calculation.
So I have created seperate SORT steps to produce each of the section. one or two steps for each section.
For this particular section, There could have been duplicates in the Input file, which I found later, after I had posted here.
i.e My input file may have records like below:
Code:
ACTIVE 1A 1000
ACTIVE 1A 500
ACTIVE 3A 1000
INACTIVE 1B 1000
INACTIVE 3B 1000
So my first step is to remove the duplicates and calculate the Sub total and Grand total.
Now in next steps were to calculate the Percentage and get the alignement. I'm still halfway..I will post my final solution for this particular section.