View previous topic :: View next topic
|
Author |
Message |
ratn006
New User
Joined: 28 Apr 2006 Posts: 14
|
|
|
|
Hi All,
I am a new learner to Cobol.
Problem is like
I have the input file layout like
Field1 field2 field3
abc 10 34
abc 10 35
abc 10 01
cde 11 10
cde 11 9
Now I need an output file from the Cobol program to get the records ie field 1 field 2 and field 3 .Condition the field3 value for all the records should be maximum among for a particular recods
ie the outpur expected from my cobol program should be like
abc 10 35
cde 11 9
I dnt have the freedom to write the JCL sort and inout file is a flat file. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
You need to steps/programs for this.
First program -
Use cobol sort method to sort the file. Key combination - FIELD3 (descending) + Field1 (any order)
Second program -
Read the previous step OP file sequentially. Since you had sorted fiel3 in descending order, first occurence of FIELD1 gives the maximum value for the particular FILED1 key.
Your IP file to first program -
Code: |
abc 10 34
abc 10 35
abc 10 01
cde 11 10
cde 11 9 |
OP file of first program/IP file to second program-
Code: |
abc 10 35
abc 10 34
abc 10 01
cde 11 10
cde 11 9 |
First occurence of abc gives maximum value of FIELD3 (i.e., 35), for cde its 9. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Quote: |
You need to steps/programs for this. |
as
Code: |
You need two steps/programs for this. |
Sorry for the same. |
|
Back to top |
|
|
ratn006
New User
Joined: 28 Apr 2006 Posts: 14
|
|
|
|
Murali,
Thats fine I can do it in two steps the alternative way could be a one step sort which will sort the file based on the field3 and cobol program will read and will give the desired result.
I need to code this whole thing in one cobol program !
thanks for your thought |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
If the maximum number of field1/field2 combinations is reasonable, define an array with that maximum and start filling it with either new entries or adding to existing entries. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Is this
the desired output?
Is not "cde 11 10" higher than "cde 11 9"?
The posted "desired result" seems to have one result that is the largest value ant the other that is not |
|
Back to top |
|
|
ratn006
New User
Joined: 28 Apr 2006 Posts: 14
|
|
|
|
thakns Dick for correcting me up.
The expected o/p should be
abc 10 35
cde 11 10 |
|
Back to top |
|
|
mainframe_a2z
New User
Joined: 16 Mar 2007 Posts: 2 Location: India
|
|
|
|
Hi,
You can use INPUT/OUTPUT procedures in SORT for achieving this. Let me know if you require code for this. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello ratn - you're welcome
As a2z posted, you can do this with cobol and an internal sort that processes your input and created the needed output file.
Also, as a2z posted, we can offer suggestions for the code.
Good luck |
|
Back to top |
|
|
|