I have a requirement.
Read a record, and find a 5 byte string starting with 'Q' (eg: Q$A12), and delete the string from record.
This 5 digit string can be present anywhere in the record. The string starting with 'Q' and rest of the 4 bytes can be vary. My record length is 15 bytes.
I have to do this using SORT.
Example:
Input:
ABCDEFG123**QABC2**
ACDHLAMANWST2HY
HAI**Q&A12**ACMATLK
Output:
ABCDEFG123
ACDHLAMANWST2HY
HAIACMATLK
OPTION COPY
INREC IFOUTLEN=15,
IFTHEN=(WHEN=INIT,
FINDREP=(IN=C' ',
OUT=X'FE')),
IFTHEN=(WHEN=INIT,
FINDREP=(IN=C'Q',
OUT=X'FD',
STARTPOS=12)),
IFTHEN=(WHEN=INIT,
PARSE=(%00=(ENDBEFR=C'Q',
FIXLEN=15),
%01=(SUBPOS=1,
STARTAT=C'Q',
FIXLEN=5),
%02=(FIXLEN=10)),
BUILD=(%00,
X'FEFEFEFEFE',
%02)),
IFTHEN=(WHEN=INIT,
OVERLAY=(1,30,
SQZ=(SHIFT=LEFT))),
IFTHEN=(WHEN=INIT,
FINDREP=(IN=X'FE',
OUT=C' ')),
IFTHEN=(WHEN=INIT,
FINDREP=(IN=X'FD',
OUT=C'Q'))
Set the length of the output records to 15.
Change all original blanks to a non-display character (assuming you data is display-only).
Change any Qs which are not followed by four bytes to another non-display character.
Use PARSE to split input into up to three fields: data before Q (if present, else all data); Five bytes starting with Q; remainder (when Q is present and not in the final position).
Use BUILD to generate a new record, with the space-value, five of them, if necessary to set Q-data to space. User OVERLAY to remove trailing blanks from the fields.
Change space-values back to space. Change Q-value back to Q.