I have a file with multiple sets of data.
Each set of data has its own header and trailer with data records between them.
The number of sets of data is not fixed; it can vary as per Business day.
1 – Header indicator for each set of data
3 - Trailer indicator for each set of data
Data records between each Header and Trailer are prefixed by number 2.
I want the data contained between each header, trailer to be stored on Filed and Subfield value in ascending order, for the entire file.
Note: But when it comes to Field38, it’s a special type of data. Field38 have has to be placed in ascending order sequence (i.e. after Field37 or any nearest smaller value Field), but its SUBFIELD values should be presented exactly as it been received in the input file.
(Sergeyken had already suggested the solution for sorting on fields and subfields for the whole file, only thing we now want is to grant this special privilege to Filed38)
Note: But when it comes to Field38, it’s a special type of data. Field38 have has to be placed in ascending order sequence (i.e. after Field37 or any nearest smaller value Field), but its SUBFIELD values should be presented exactly as it been received in the input file.
==> Rows (lines) with Field38 should not be reordered by SUBFIELD
INREC IFTHEN=(WHEN=GROUP,
* DETECT EITHER OF 'H(EADER)', '1', 'T(RAILER)'
BEGIN=(1,1,SS,EQ,C'H1T'),
PUSH=(81:ID=6, APPEND GROUP SEQ NUMBER
SEQ=9)), APPEND LINE NO WITHIN GROUP
IFTHEN=(WHEN=(2,7,CH,EQ,C'FIELD38'),
OVERLAY=(96:87,9)), USE FIELD38'S SEQ NO
IFTHEN=(WHEN=NONE,
OVERLAY=(96:9,9)) USE REGULAR SUBFIELD
*
SORT FIELDS=(81,6,ZD,A, GROUP SEQ NUM
1,1,CH,A, LINE TYPE WITHIN GROUP
2,7,CH,A, FIELD
96,9,CH,A) MODIFIED SUBFIELD
*
OUTREC BUILD=(1,80) TRUNCATE GROUP NUMBER, AND LINE NUMBER
*
END
As per your explanation, 'FIELD38' value is sorted among other FIELD values.
So, FIELD38 goes before FIELD4, FIELD40, FIELD7, FIELD9 etc. etc. etc.
It's not clear from your initial example: why FIELD38 might be considered not less than FIELD4, or FIELD40???
If you need this, you MUST consider digits at the end of your "fields" as numeric values, not as character strings.
Code:
INREC IFTHEN=(WHEN=GROUP,
* DETECT EITHER OF 'H(EADER)', '1', 'T(TRAILER)'
BEGIN=(1,1,SS,EQ,C'H1T'),
PUSH=(81:ID=6, APPEND GROUP SEQ NUMBER
SEQ=9)), APPEND LINE NO WITHIN GROUP
IFTHEN=(WHEN=(2,7,CH,EQ,C'FIELD38'),
OVERLAY=(96:87,9)), USE FIELD38'S SEQ NO
IFTHEN=(WHEN=NONE,
OVERLAY=(96:9,9)) USE REGULAR SUBFIELD
*
SORT FIELDS=(81,6,ZD,A, GROUP SEQ NUM
1,1,CH,A, LINE TYPE WITHIN GROUP
2,7,UFF,A, FIELD
96,9,UFF,A) MODIFIED SUBFIELD
*
OUTREC BUILD=(1,80) TRUNCATE GROUP NUMBER
*
END