I am converting an Easytrieve program to cobol and the existing program is having a control statement on 3 fields is there any way to change the control statement in easytrieve Control statement to DFSORT
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
Hi D,
You are right, they seem to be like summaries.
The logic maybe,
If year,product & type are same, then add the amount fields and produce one record with year,product,total.
Then finally a subtotal record of Year & product with total.
On MHO, I would write this in COBOL rather than DFSORT, since a lot of logic is involved.
Answers to few questions in the posts:
1. Eazytrive gives the desired output in one run. But when trying to
convert to cobol cobol gives the file which I mentioned as Input. So get
desired output I was thinking of DFSORT instead of writing a complex
logic as that Input file having 3-4 field to sum.
2. The requirement is exactly same which Vasanth has mentioned
I will check it out the solution given above and I will be very thankful if anyone explain how this sort card work
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
chandan.inst,
Since you wanted 3 different breaks , we achieve that in 2 passes of data.
The first SORT operation will handle 2 breaks
Break 1 on Year,Product and Type is achieved by SUM Fileds sorting on all the 3 columns. You only showed 3 bytes for amount, so in order to account for overflow after summation we padded amount with 5 leading zeros and sum it as 8 byte field instead of 3 byte field
Break 2 is achieved using SECTIONS on OUTFIL which will total the amount value based on the Year and Product.
The second COPY operation will handle the final break on (Year) . This is done using SECTIONS and we total the Summed values and write out the output
Btw just so you know the logic isn't that complex as you think , It is quite simple and can be done in cobol very easily
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
Hello,
A bit late to the party and apologies if i'm barging in. . .
Quote:
So get desired output I was thinking of DFSORT instead of writing a complex logic as that Input file having 3-4 field to sum.
There should be no complexity. . .
As Kolusu mentioned:
Quote:
It is quite simple and can be done in cobol very easily
To elaborate just a little, the first thing is to get the data into the proper sequence - if the volume is not huge, i'd use the cobol internal sort specifying USING & OUTPUT PROCEDURE. In the output procedure, return the records and if the control info is the same as previous, accumulate the amount. If the control info changes, print the accumulated total, add the total to the next higher level accumulator, and zero out that level. When all of the records have been returned from the sort, process the last set of totals including the final total.
If you have doubts about how to do this, it would be a good learning exercise. I believe the code will be far less complex and more easily understood by others (which will be important if the requirement grows later).
After reading your reply I am agree that there will be no complexity as I didnt thougt about about Cobol internal Sort and tried to do it with Cobol Read storing current data and comparing with previous data..