View previous topic :: View next topic
|
Author |
Message |
jerryte
Active User
Joined: 29 Oct 2010 Posts: 202 Location: Toronto, ON, Canada
|
|
|
|
I had a situation where I wanted to run a sort copy operation on a file that should already be sorted. I wanted a way to check that the file was indeed sorted and give a non-zero return code if not.
Option 1
Sort the file anyway. This would use a lot of resources if the file was large. Not sure if DFSORT can detect that a file is already sorted and minimize the resource usage.
Option 2
Do a SORTKEYS join to an empty file using the "SORTED" keyword. File F1 would be the input and file F2 would just be empty.
Code: |
JOINKEYS FILE=F1,FIELDS=(something),SORTED
JOINKEYS FILE=F2,FIELDS=(something)
SORT FIELDS=COPY |
This will fail if the input file is not sorted.
Option 3
I wrote a COBOL exit program that will check each record to the previous one and force a terminate (RC=16) if not sorted. It works but this is limited. It has to read a dd on the first call to get the field position and length.
Option 4
This doesn't exist but it would be nice if IBM added a feature to DFSORT to check that a file is already sorted. Suggested syntax:
Code: |
SORT CHECK=(something) |
DFSORT would then flag any record that is not in sorted order and terminate with a non-zero return code.
Thoughts? Suggestions? Ideas? |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
Back to top |
|
|
jerryte
Active User
Joined: 29 Oct 2010 Posts: 202 Location: Toronto, ON, Canada
|
|
|
|
Thanks for the info. I had not thought to try a MERGE.
This works but is a "trick" as technically I am not doing a merge. By definition a merge requires 2 or more things.
The functionality already exists within DFSORT to check sort order. It would make sense to have an actual syntax command for this. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You can MERGE with one input. It will check the keys. It will fail if out-of-sequence.
Why don't you know if the file is sorted? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If the sequence of the file is in question, the file needs to be sorted.
If the file is already in sequence the sort will run exponentially faster than if the data is out of sequence. |
|
Back to top |
|
|
|