IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how to get the record maximum records


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ratn006

New User


Joined: 28 Apr 2006
Posts: 14

PostPosted: Tue Mar 20, 2007 3:28 pm
Reply with quote

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Tue Mar 20, 2007 3:46 pm
Reply with quote

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Tue Mar 20, 2007 3:47 pm
Reply with quote

Quote:
You need to steps/programs for this.


as

Code:
You need two steps/programs for this.     


Sorry for the same. icon_redface.gif
Back to top
View user's profile Send private message
ratn006

New User


Joined: 28 Apr 2006
Posts: 14

PostPosted: Tue Mar 20, 2007 3:52 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Mar 20, 2007 5:29 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 20, 2007 9:57 pm
Reply with quote

Hello,

Is this
Quote:
cde 11 9
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 icon_confused.gif
Back to top
View user's profile Send private message
ratn006

New User


Joined: 28 Apr 2006
Posts: 14

PostPosted: Wed Mar 21, 2007 8:42 am
Reply with quote

thakns Dick for correcting me up.
The expected o/p should be
abc 10 35
cde 11 10
Back to top
View user's profile Send private message
mainframe_a2z

New User


Joined: 16 Mar 2007
Posts: 2
Location: India

PostPosted: Wed Mar 21, 2007 4:08 pm
Reply with quote

Hi,

You can use INPUT/OUTPUT procedures in SORT for achieving this. Let me know if you require code for this.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Mar 21, 2007 7:14 pm
Reply with quote

Hello ratn - you're welcome icon_smile.gif

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 icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top