I need to split a sequential Mainframe file. Well, to be precise I need to copy the content from this file to another, starting from a specific keyword. Example:
line1
line2
line3
start line4
line5
line6
In this case I need to search for "start" and copy everything starting from line4 to another file using either REXX or SORT. Any suggestions?
EDIT: What I thought about but not happy with in REXX
"EXECIO * DISKR INPUT (STEM INPUT. FINIS)"
LINEINPUT = 1
LINEOUTPUT = 1
FOUND = 0 /*working like a boolean?
DO WHILE LINEINPUT <= INPUT.0
IF INPUT.LINEINPUT = start line4 THEN DO
FOUND = 1
END
IF FOUND = 1 THEN DO
INPUT.LINEINPUT = OUTPUT.LINEOUTPUT
LINEOUTPUT = LINEOUTPUT + 1
END
LINEINPUT = LINEINPUT + 1
END
Something like this maybe, but this means that I need to go through all those files line by line. Maybe there is a better way in JCL? Maybe Syncsort can do something like this?
RECFM is fixed. FBA to be precise. LRECL 170. The trigger can either be a part of this line or the whole line. This is not important, because it is always the same line in every single file and even the first few characters are unique in the whole file. Means that "start" only appears once in the file.
For a fixed-position start of the trigger:
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,
BEGIN=(1,5,CH,EQ,C'start'),
PUSH=(171:ID=1))
OUTFIL OMIT=(171,1,CH,EQ,C' '),
BUILD=(1,170)
For a variable-position, unique, trigger:
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,
BEGIN=(1,170,SS,EQ,C'start'),
PUSH=(171:ID=1))
OUTFIL OMIT=(171,1,CH,EQ,C' '),
BUILD=(1,170)
WHEN=GROUP
gives you PUSH
, which will put data from the current record, or a group-number (ID
) or number within group (SEQ
), to that position on all the records in the group (including the current record). In this case, the "group" is the rest of the file.
The SS
is field-type allowing a Sub-String search.
Then an OMIT=
(similar to OMIT COND=
but after the file has been processed by the control cards) on OUTFIL
does the actual selection from the flag (the automatically extended records not with a value from the PUSH will be set to blank) and BUILD to drop off the extra byte.
The extra byte is needed because SORT has no "program storage" for definitions - extra fields have to be on the records (or, for the duration of the current record only, in PARSEd fields).