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

Sort an array in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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: 2481
Location: Netherlands, Amstelveen

PostPosted: Wed Jan 05, 2011 3:24 pm
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
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: 1788
Location: Bloomington, IL

PostPosted: Wed Jan 05, 2011 3:59 pm
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
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Jan 05, 2011 5:23 pm
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
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
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

Senior Member


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

PostPosted: Wed Jan 05, 2011 6:22 pm
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
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Jan 06, 2011 1:06 pm
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top