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
 

 

Sort an array in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
santohsks1987
Warnings : 1

New User


Joined: 29 Dec 2010
Posts: 31
Location: Mumbai

PostPosted: Wed Jan 05, 2011 3:12 pm    Post subject: Sort an array in COBOL
Reply with quote

I have to sort an array with 3 fields i.e Name, date and code. Then i have to compare the records in the array with a table and put the records which are not present in the table into another table.
Please help me how to sort it and how to compare it also.
How to compare the date field?
Back to top
View user's profile Send private message

santohsks1987
Warnings : 1

New User


Joined: 29 Dec 2010
Posts: 31
Location: Mumbai

PostPosted: Wed Jan 05, 2011 3:14 pm    Post subject: Read a file
Reply with quote

Hi everyone,

I have to read a VSAM file and populate an array. This has three elements in it. Please give me the code how this can be achieved.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Jan 05, 2011 3:24 pm    Post subject:
Reply with quote

Now thats a bad start for 2011 for a software engineer (sic), asking for code without offering something.
Back to top
View user's profile Send private message
santohsks1987
Warnings : 1

New User


Joined: 29 Dec 2010
Posts: 31
Location: Mumbai

PostPosted: Wed Jan 05, 2011 3:27 pm    Post subject:
Reply with quote

i have a vsam file with many fields. but i have to read only the first name, DOB and relationship code and put in an array.

what other information is required
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1738
Location: Bloomington, IL

PostPosted: Wed Jan 05, 2011 3:59 pm    Post subject:
Reply with quote

santohsks1987 wrote:
i have a vsam file with many fields. but i have to read only the first name, DOB and relationship code and put in an array.

what other information is required

The amount that you will be paying one of us to produce code for which you will take credit.
Back to top
View user's profile Send private message
Dsingh29

Active User


Joined: 16 Dec 2008
Posts: 132
Location: IBM

PostPosted: Wed Jan 05, 2011 5:09 pm    Post subject:
Reply with quote

there is ascending/descending clause available while working with cobol tables....google more for it..and u can use it in ur code.
Back to top
View user's profile Send private message
santohsks1987
Warnings : 1

New User


Joined: 29 Dec 2010
Posts: 31
Location: Mumbai

PostPosted: Wed Jan 05, 2011 5:18 pm    Post subject:
Reply with quote

no. I have a vsam file and put the contents into an array in a sorted order. give me sample code for this. take an example of 3 fields that i have to consider while sorting. that is i have to sort that based on all the three keys
icon_sad.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Wed Jan 05, 2011 5:23 pm    Post subject:
Reply with quote

Quote:
Please help me how to sort it and how to compare it also.
There is a link to manuals at the top of the page. Click it, find the COBOL Language Reference manual, and read up on the SORT verb -- follow up with reading in the COBOL Programming Guide manual. Then, research the IF statement and how to use it.
Back to top
View user's profile Send private message
Dsingh29

Active User


Joined: 16 Dec 2008
Posts: 132
Location: IBM

PostPosted: Wed Jan 05, 2011 5:23 pm    Post subject:
Reply with quote

did u googled for it....????
I think it doesnot matter to cobol tables from where the data is coming...when u r populating the cobol table....so the asc/desc clause will work just fine....

And please stop asking for sample codes....you have to build your own code...
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Wed Jan 05, 2011 6:20 pm    Post subject: Re: sort an array
Reply with quote

santohsks1987 wrote:
I have to sort an array with 3 fields i.e Name, date and code. Then i have to compare the records in the array with a table and put the records which are not present in the table into another table.
Please help me how to sort it and how to compare it also.
How to compare the date field?

As you have put the requirement, you don't have to sort. I would suggest this approach:

    1. Read input record
    2. If EOF, you are done.
    3. Look up the key in the compare table (you even don't have to fetch any data - use EXISTS in DB2)
    4. If you got a row not found result from the lookup, perform logic to insert the infile information into table.
    5. Read input record
    6. Proceed from step 2

This assumes that you can select unique observations on all keys; if not, you will have to retrieve the not used key variables and compare them in the lookup code to establish if a match has been found.
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Wed Jan 05, 2011 6:22 pm    Post subject:
Reply with quote

gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme gimme

Oh yeah - thanks.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Wed Jan 05, 2011 6:37 pm    Post subject:
Reply with quote

santohsks1987 wrote:
i have a vsam file with many fields. but i have to read only the first name, DOB and relationship code and put in an array.

what other information is required

Is this information enough to make a unique match?
Back to top
View user's profile Send private message
santohsks1987
Warnings : 1

New User


Joined: 29 Dec 2010
Posts: 31
Location: Mumbai

PostPosted: Thu Jan 06, 2011 12:58 pm    Post subject:
Reply with quote

I have to sort an array based on three key fields. Is it possible using bubble sort....
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Thu Jan 06, 2011 1:06 pm    Post subject: Reply to: sort an array
Reply with quote

Quote:
I have to sort an array based on three key fields. Is it possible using bubble sort....

YES!
or any other algorithm You feel comfortable with
there are quite a few examples that can be found by GOOGLING!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jan 06, 2011 1:37 pm    Post subject:
Reply with quote

you can even pass the COBOL Internal Table via linkage to a sub-module,
which would be a COBOL Sort program (one that uses SD's, SORT Procedure statements, etc....)
which would RELEASE each item of the COBOL Internal Table to SORT
and then repopulate the COBOL Internal Table with the RETURN statement results.

That you even have to ask about sorting,
means you are probably incapable of a timely implementation of a routine to perform a bubble sort.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Jan 06, 2011 1:39 pm    Post subject:
Reply with quote

Santosh,

If you are that unfamiliar with comparing values and how to structure a fairly simple requirement as you revealed in your original posting, I will advice against implementing your own sorting algoritm.

It makes your program harder to maintain, and can probably only be justified if you have a simple sort key, and a limited number (<100?) of rows to sort.

Check the Cobol manual for how to code an internal sorting. Internal sorting will call a utility sort, IBM's DFHSORT or other, depending on your installation. Sort utilities will choose a suitable and efficient sort method for you, and use internal or external temporary storage as needed.
Back to top
View user's profile Send private message
santohsks1987
Warnings : 1

New User


Joined: 29 Dec 2010
Posts: 31
Location: Mumbai

PostPosted: Thu Jan 06, 2011 1:49 pm    Post subject:
Reply with quote

ya that is fine but i am actually working in online mode. will this work even in the online mode????
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Jan 06, 2011 1:59 pm    Post subject:
Reply with quote

Ahh, a requirement you didn't tell us about!

What on earth are you doing with sequential unsorted data in a real-time environment?

Is there any possibility to convert this task into a asynchroneous (offline) one?
Back to top
View user's profile Send private message
santohsks1987
Warnings : 1

New User


Joined: 29 Dec 2010
Posts: 31
Location: Mumbai

PostPosted: Fri Jan 07, 2011 11:35 am    Post subject:
Reply with quote

Thank you all for your replies...... It really helped me a lot in thinking in different views.
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 Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am


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