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

Sorting a array


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 27, 2011 3:45 am
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 27, 2011 3:51 am
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
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
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

Moderator Emeritus


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

PostPosted: Thu Jan 27, 2011 10:29 am
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
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: 771
Location: Germany

PostPosted: Thu Jan 27, 2011 4:56 pm
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 27, 2011 8:09 pm
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 27, 2011 9:22 pm
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

Moderator Emeritus


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

PostPosted: Thu Jan 27, 2011 10:13 pm
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

Senior Member


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

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

 


Similar Topics
Topic Forum Replies
This topic is locked: you cannot edit posts or make replies. Automation need help in sorting the data DFSORT/ICETOOL 38
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
No new posts Sorting a record spanned over multipl... DFSORT/ICETOOL 13
No new posts To find an array of words (sys-symbol... JCL & VSAM 9
No new posts How to move values from single dimens... COBOL Programming 1
Search our Forums:

Back to Top