Yes, I wouldn't prefer to have very few records here which makes INCLUDE simpler and it was a correction to TS to refer the right keys with the sample data provided.
If the TS is not able to adjust the general approach to his own needs and specification, that means he's at the level of copy-and-paste-ready-to-use-solution.
Discussion at this level must continue at the Beginners Forum.
The specific of the original topic (which is critical compared to other sort tasks): it requires some implementation of many-to-many record comparison, one by one, with varying number of records in each part, and (desirable): easy to change key type, and key size, and key position within each dataset.
The solution involving SYMNAMES doesn't make any difference from simple sequential comparison of ONE dataset to the LIMITED and FIXED number of keys, either those keys are coded as part of SORT control statements, or "hidden" inside the SYMNAMES list.
Using SYMNAMES doesn't make any difference or improvement except shortening a bit the SORT control statements themselves; it doesn't help to achieve the original specific task of many-to-many comparison.
You are making your own assumption and I can not code for the whole world.
What I have suggested will work with that TS wants at this point of time and not what you assume. If TS wants something else then let it come from TS not from you. I don't prefer to have cartesian product created without any reason here and it will have more EXCP when you hit millions of records.
No need to make own assumption and have a no meaning conversation further. If you continue to replay back and forth (off topic talks since already solutions are posted) someone will lock this post soon and TS have no chance to communicate further and that unfair.
I don't prefer to have cartesian product created without any reason here and it will have more EXCP when you hit millions of records.
In order to get the desired result one mandatory needs to perform pairs of comparisons as many as
(size of input) * (number of ranges)
either they are coded inside the original datasets, or "converted" via SYMNAMES into sequential fixed logical comparisons listed as SORT control statements.
Whatever solution is used, exactly the same "millions of records" must be handled!
The straightforward one-step solution given in previous example works fine for reasonable size of input dataset (let's say, up to several hundreds of thousand records, 100,000-300,000). The total number of ranges is also not expected to be very huge, but up to 1,000 ranges can be considered as acceptable amount.
That method does really produce the cartesian product in between, but it does not mean that we must avoid this thing as if it was a devil's creation. This way works fine assuming we are within a reasonable amount of data to handle; so, why not to use the simple method when it really works?
Definitely, there are other cases in this world when huge amount of records must be handled. Let's say, starting from 100M and more input records, and/or starting from 100K of valid ranges. In that case straightforward method with cartesian product highly likely would fail. Another method is needed, to process huge input dataset only once. This can be done; the only requirement: the input must be presorted by the key field.
The range file also needs to be sorted, but it can be done as part of processing, since one extra manipulation with range file is needed by this method. Two JCL steps needed, and most likely it cannot be avoided AFAIK.
//* SELECT BETWEEN - FROM A HUGE FILE
//* SORT AND SPLIT RANGE LIST INTO TWO SEPARATE LISTS: FROM/TO VALUES
//RANGES EXEC PGM=SYNCSORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
//FROMLIST DD DISP=(NEW,PASS),
//TOLIST DD DISP=(NEW,PASS),
//SYSIN DD *
INCLUDE COND=(1,6,CH,LE,7,12,CH) eliminate bad ranges
SORT FIELDS=(1,6,CH,A) sort left range ascending
OUTFIL FNAMES=(FROMLIST), create left range list
BUILD=(1,6,74X'00') provide merging before any real data
OUTFIL FNAMES=(TOLIST), create right range list
BUILD=(7,6,74X'FF') provide merging after any real data
//* MERGE HUGE INPUT, AND TWO RANGE FILES; ALL MUST BE SORTED
//BETWEEN EXEC PGM=SYNCSORT
//SYSOUT DD SYSOUT=*
//SORTIN01 DD DISP=(OLD,DELETE),DSN=&&FROMLIST left ranges
//SORTIN02 DD DISP=(OLD,DELETE),DSN=&&TOLIST right ranges
//SORTIN03 DD * input data (huge)
//SELECTED DD SYSOUT=*
//SYSIN DD *
MERGE FIELDS=(1,6,CH,A, merge using record keys
7,1,CH,A) place range records before/after data groups
OUTREC IFTHEN=(WHEN=GROUP, detect groups of allowed ranges
BEGIN=(7,1,CH,EQ,X'00'), marker of left range record
END=(7,1,CH,EQ,X'FF'), marker of right range record
PUSH=(81:7,1)) mark group records as valid
INCLUDE=(7,1,CH,NE,X'00', exclude left markers
AND,7,1,CH,NE,X'FF', exclude right markers
AND,81,1,CH,EQ,X'00') include only valid records