View previous topic :: View next topic
|
Author |
Message |
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
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 |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
By chance, is the Input file that needs to be sorted a VSAM KSDS or ESDS?
Bill |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
Thanks Bill. |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
@ rgupta71
Sir, why not using a separate Sort-Step before executing the Cobol-Step in your JCL. |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
@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
Thanks. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 . . .
d |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
|