Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

how to get the record maximum records

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: how to get the record maximum records
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: 1439
Location: Bangalore,India

PostPosted: Tue Mar 20, 2007 3:46 pm    Post subject:
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: 1439
Location: Bangalore,India

PostPosted: Tue Mar 20, 2007 3:47 pm    Post subject:
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    Post subject: maximum record
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: 3158
Location: Tucson AZ

PostPosted: Tue Mar 20, 2007 5:29 pm    Post subject:
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

Site Director


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

PostPosted: Tue Mar 20, 2007 9:57 pm    Post subject:
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    Post subject:
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    Post subject: Re: how to get the record maximum records
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

Site Director


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

PostPosted: Wed Mar 21, 2007 7:14 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us