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
 

 

Sorting a array

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

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Thu Jan 27, 2011 2:46 am    Post subject: Sorting a array
Reply with quote

Hi All,

I have coded a program it works fine but when I take a bigger input file with 200,000 records it takes 46 min to run because I am using bubble sort.

Can we sort an array by defining a SD section and save the result to other array? All the example I have seen are using files.

Thanks.
Back to top
View user's profile Send private message

Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Thu Jan 27, 2011 3:43 am    Post subject:
Reply with quote

Sure, just substitute an input array element (from element 1 to n) for an input file record in an INPUT PROCEDURE and substitute a new array element (from element 1 to n) for an output file record in an OUTPUT PROCEDURE.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 27, 2011 3:45 am    Post subject: Reply to: Sorting a array
Reply with quote

By chance, is the Input file that needs to be sorted a VSAM KSDS or ESDS?

Bill
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 27, 2011 3:51 am    Post subject: Reply to: Sorting a array
Reply with quote

If you count the number of records you're sending to SORT, you can remove the array from WS to LINKAGE, where you can define it as a true OCCURS DEPENDING ON and obtain dynamic storage for this array via the LE Callable routine "CEEGTST", using the record-count, the record-length and four-bytes for the OCCURS DEPENDING ON Binary-Fullword, which will house the WS record-count value.

At program end, Call "CEEFRST", free the dynamic storage and you're done.

OCCURS DEPENDING ON arrays in WS are always allocated for the maximum amount, regardless.

So (for example), if there's 1MB allocated for the WS array and you really only need 250K, you've saved 750K after moving it to LINKAGE.

LINKAGE items don't occupy any storage until they're addressed and populated, in various different manners.

Bill
Back to top
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Thu Jan 27, 2011 5:27 am    Post subject: Reply to: Sorting a array
Reply with quote

Thanks Bill.
Back to top
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Thu Jan 27, 2011 9:38 am    Post subject:
Reply with quote

Hi All,

I defined the array as
05 WS-ERROR-CODE-TBL-SORTED OCCURS 200000 TIMES

DEPENDING ON WS-ERR-TBL-LOOP

INDEXED BY WS-ERR-CODE-SORT-IDX.



10 WS-ERR-POL-NUMBER-SORT PIC X(10).

10 WS-ERR-CODE-SORT PIC X(06).

10 WS-ERR-SEV-CODE-SORT PIC 9(01).

10 WS-ERR-CODE-TYPE-SORT PIC X(08).

10 WS-ERR-CODE-DESC-SORT PIC X(31).


Sort stmt is

SORT SD-FILE ASCENDING KEY SD-ERR-POL-NUMBER-SORT

USING WS-ERROR-CODE-TBL-SORTED

GIVING WS-ERROR-CODE-T-SORTED.




IGYPS2074-S "WS-ERROR-CODE-TBL-SORTED" was defined as a type that was invalid in this context and was discarded.

IGYPS2074-S "WS-ERROR-CODE-T-SORTED" was defined as a type that was invalid in this context and was discarded.

Could you please let me know what is wrong in this.

Thanks.
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: Thu Jan 27, 2011 10:29 am    Post subject:
Reply with quote

Hello,

Quote:
Could you please let me know what is wrong in this.

You have specified using/giving for something that is not a file (read about the rules for the internal SORT).

Suggest you change your code to use INPUT PROCEDURE and OUTPUT PROCEDURE.
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 27, 2011 2:51 pm    Post subject:
Reply with quote

also,
why use a second COBOL internal Table? dumb and a waste of resources.
just load the results of the sort into the original COBOL internal Table.

arrays in cobol are host variables for db2.
if it is not a host variable for db2,
then it is a COBOL internal Table
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 743
Location: Germany

PostPosted: Thu Jan 27, 2011 4:56 pm    Post subject:
Reply with quote

@ rgupta71

Sir, why not using a separate Sort-Step before executing the Cobol-Step in your JCL.
Back to top
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Thu Jan 27, 2011 7:44 pm    Post subject:
Reply with quote

THank you all for your response.

@All
The problem is that I have coded the program.It works fine but when when we increase the number of records it run time is very high because I am using bubble sort.So,for that I was trying to implement COBOL internal sort.Is there any other way I can do this?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 27, 2011 8:09 pm    Post subject: Reply to: Sorting a array
Reply with quote

Actually, UmeySan's suggestion is a good idea.

Pre-sort the file in a prior step and create a temporary sorted-file as input to your program. Internal SORTS within a COBOL program can be much slower than a standalone SORT step.

Do you still need to load the file into an internal array with the intent of using a SEARCH ALL on the table/array entries?

If so, you can pass the number of records in the sorted input-file to your program, move the OCCURS DEPENDING ON array to LINKAGE, obtain the amount of storage required using CEEGTST and read each record into the array until it's filled. Pseudo code -
Code:


COMPUTE STG-AMT = (RECORD-LGTH * NBR-RECS) + 4.

The 4 is for the OCCURS DEPENDING ON Binary-Fullword length (S9(09) COMP)) at the beginning of the Dynamic Array, which is needed by COBOL for the SEARCH ALL. If it's set higher than the number of actual records, you'll get a S0C4.

Bill
Back to top
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Thu Jan 27, 2011 8:48 pm    Post subject:
Reply with quote

@Bill,

The input file for the program is being formatted by the program and then I need to sort it based on different fields.So,I think can't pre-sort the data.
Yes,I again need to sort the sorted array on different field but not for search all.

Now the only option remaining is write the input array to a file and read it after sorting it with DFSORT icon_sad.gif


Thanks.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 27, 2011 9:22 pm    Post subject: Reply to: Sorting a array
Reply with quote

OK, then it sounds like we're back to an Internal COBOL SORT.

If at all possible, the more optimized method would be a USING/GIVING along with the compile option FASTSRT.

But, not too sure if this will work for you.

Other than USING/GIVING, you're left to use an INPUT/OUTPUT SORT Procedure. But, FASTSRT has no effect on this method.

But certainly, an internal SORT would be more efficient than an internal (manual) bubble-sort.

However, you would still need to feed SORT input with each record defined to a file and obtain each SORT output record via the GIVING or OUTPUT PROCEDURE method.

Bill
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: Thu Jan 27, 2011 10:13 pm    Post subject: Reply to: Sorting a array
Reply with quote

Hello,

Quote:
Is there any other way I can do this?
If you had changed the code to INPUT PROCEDURE / OUTPUT PROCEDURE when it was first recommended, this would have been running successfully hours ago. . .

Suggest you ask yourself why you did not do this . . . icon_confused.gif

d
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


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

PostPosted: Thu Jan 27, 2011 11:20 pm    Post subject:
Reply with quote

Can you split the COBOL program?

Part 1 - format fields and write to file
JCL Sort
Part 2 - read the sorted file back in and resume other processing
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 Efficient sorting chandracdac DFSORT/ICETOOL 5 Sat Oct 22, 2016 3:23 am
No new posts Stripping and Sorting of VB file G SRINIVASA RAO SYNCSORT 5 Wed Sep 14, 2016 1:34 pm
No new posts DFSORT sorting only specific records akodakka DFSORT/ICETOOL 4 Thu Aug 04, 2016 11:24 am
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm
No new posts VB file sorting V S Amarendra Reddy DFSORT/ICETOOL 2 Fri Feb 26, 2016 8:29 pm


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