Joined: 30 Mar 2011 Posts: 48 Location: United States
Does anyone have a copy of Frank Yaeger's article: DFSORT: Parsing Delimited & Variable Length Fields? I think it was originally published in z/Journal in 2007 but its URL appears defunct. I did find a reprint at the following Web site but the figures cited by Frank are missing and it would be more informative with the figures. The article is very well written for a parsing newbie like myself.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
I've rebuilt the examples from the text. Note that there are "scannos" in the text as well (failure of the Optical Character Recognition after text is scanned).
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
There is a way to use ABSPOS=1, discussed by Frank Yaeger in the article, for the final example, so that the PARSE can be done only once:
Code:
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(81:
C' FIRST= ',
C' LAST= ',
C' MIDDLE= ',
C' PROFIT= ',
C' LOSS= ')),
IFTHEN=(WHEN=INIT,
PARSE=(%1=(STARTAFT=C'FIRST=',
ABSPOS=1,
ENDBEFR=C' ',FIXLEN=8),
%2=(STARTAFT=C'MIDDLE=',
ABSPOS=1,
ENDBEFR=C' ',FIXLEN=12),
%3=(STARTAFT=C'LAST=',
ABSPOS=1,
ENDBEFR=C' ',FIXLEN=12),
%4=(STARTAFT=C'PROFIT=',
ABSPOS=1,
STARTAFT=C'LOSS=',
ENDBEFR=C' ',FIXLEN=7))),
IFTHEN=(WHEN=INIT,
BUILD=(%01,
%02,
%03,
%04,
SFF,
EDIT=(IIT.TTS),
SIGNS=(,,+,-)))
SORT FIELDS=COPY
The code ensures that a parameter will always be found, even if not existing in the source data, by adding all the valid parameters to the end of each record.
In itself, not especially useful, but it is a very convenient way to set default values for keyword-field parsing.
Code:
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(81:
C' FIRST=JOE ',
C' LAST=BLOGS ',
C' MIDDLE=X ',
C' PROFIT=+30.00 ',
C' LOSS= ')),
IFTHEN=(WHEN=INIT,
PARSE=(%1=(STARTAFT=C'FIRST=',
ABSPOS=1,
ENDBEFR=C' ',FIXLEN=8),
%2=(STARTAFT=C'MIDDLE=',
ABSPOS=1,
ENDBEFR=C' ',FIXLEN=12),
%3=(STARTAFT=C'LAST=',
ABSPOS=1,
ENDBEFR=C' ',FIXLEN=12),
%4=(STARTAFT=C'PROFIT=',
ABSPOS=1,
STARTAFT=C'LOSS=',
ENDBEFR=C' ',FIXLEN=7))),
IFTHEN=(WHEN=INIT,
BUILD=(%01,
%02,
%03,
%04,
SFF,
EDIT=(IIT.TTS),
SIGNS=(,,+,-)))
SORT FIELDS=COPY
The actual example doesn't lend itself to defaults as such, but serves. Here is the output from a blank line of input:
Code:
JOE X BLOGS 30.00+
It's also a good example for the use of DFSORT symbols/SYMNAMES...