Apologies for a reapeated query.
1. Two FB datasets; DS-A, LRECL=19, has duplicates, is unsorted; DS-B, LRECL=600, has 19 byte data at 'n' column (fixed position), these may be repeated, records are not duplicate but valid repetitions (data is arranged on the basis of SEQ number in column 1 to 6, ascending, though can be unsorted on the aforementioned 19 bytes).
2. Data content-- DS-A can have upwards of 1.5 mill records, DS-B can have upwards of 500k records, as of now < 1 mill.
3. DS-B structure:
--> Has a header record with some-text and date (not necessarily current date)
--> Has detail records with aforementioned sequence in column 1 to 6; yes, the sequence will be repeated from '1' once the limit of '999999' is completed.
--> Has 19 byte data at column 'n' which is to be matched with DS-A
--> Has another 19 byte number in the format: bbbb.cc, on another column
--> Has a tail record which has some text in column 1 to 3, detail-record count ONLY (total count minus head and tail), and lastly the summation of the 19 byte number which is in format bbbb.cc, translated to 15 byte ZD
Requirement: Omit all the records of DS-A from DS-B, rebuild DS-B in the original order with columns 1 to 6 resequenced, and tail rebuilt with updated COUNT and summation.
Since DS-A was large in size (and also because I couldn't think of anything better), hence I went the JOINKEYS-way; below is the current solution:
Step-1:
DS-A is being sorted and SUM FIELDS=NONEd at this point. Original tail record is being dropped here. The set of matched records is being saved for reconciliation.
//SYSIN DD *
JOINKEYS FILES=F1,FIELDS=(1,19,A)
JOINKEYS FILES=F2,FIELDS=(39,19,A)
JOIN UNPAIRED F1,F2
REFORMAT FIELDS=(F1:1,19,F2:1,600,?)
SORT FIELDS=COPY
OUTFIL FNAMES=BOTH,REMOVECC,
INCLUDE=(620,1,CH,EQ,C'B'),
BUILD=(20,600)
OUTFIL FNAMES=ONLYDSB,REMOVECC,
INCLUDE=((620,1,CH,EQ,C'2'),AND,(20,3,CH,NE,C'999')),
BUILD=(20,600)
/*
Step-2:
Handled the header record, and rebuilt the tail.
//TOOLIN DD *
DATASORT FROM(IN) TO(OUT) USING(SRT1) FIRST
/*
//SRT1CNTL DD *
SORT FIELDS=(1,6,CH,A)
OUTFIL FNAMES=OUT,REMOVECC,
IFTHEN=(WHEN=(1,3,CH,NE,C'HEA'),
BUILD=(SEQNUM,6,ZD,7,594)),
TRAILER1=(C'999',
COUNT-1=(M11,LENGTH=9),
TOT=(258,18,UFF,TO=ZD,LENGTH=15))
/*
Query: Can this be done in a more simpler way, can we drop JOINKEYS altogether, an alternate approach maybe?
Thank you.