OPTION COPY
OUTREC IFTHEN=(WHEN=INIT,
PARSE=(%100=(FIXLEN=3,ENDBEFR=C'.',REPEAT=3),
%103=(FIXLEN=3)),
BUILD=(%100,4:C'.',5:%101,8:C'.',9:%102,12:C'.',13:%103)),
IFTHEN=(WHEN=(1,3,CH,EQ,C'167',AND,13,3,CH,EQ,C'99'),
OVERLAY=(5:C'113',9:C'75 ',1:1,15,SQZ=(SHIFT=LEFT))),
IFTHEN=(WHEN=NONE,
BUILD=(1:1,15,SQZ=(SHIFT=LEFT)))
This example illustrates how you can modify variable position/length
fields, such as ftp addresses.
The 15-byte input records might look like this:
167.113.117.99
167.90.18.99
167.80.118.98
165.250.89.562
167.125.890.95
168.250.89.99
167.125.890.99
0.0.0.0
167.90.580.99
We want to convert each FTP address of the form 167.x.y.99 to 167.113.75.99.
x and y can be any 1-3 digit value. Thus, the 15-byte output records
should look like this:
167.113.75.99
167.113.75.99
167.80.118.98
165.250.89.562
167.125.890.95
168.250.89.99
167.113.75.99
0.0.0.0
167.113.75.99
In order to reformat the input records for output, we use IFTHEN
clauses as follows:
- IFTHEN WHEN=INIT clause: We PARSE the four variable numeric values
into four 3-byte fixed parsed fields using %100,
%101, %102 and %103 respectively. Note that we use REPEAT=3 with the
%100 parsed field to repeat it for the %101 and %102 parsed fields.
REPEAT=n is useful when you have several contiguous parsed fields
with the same operands).
We reformat the
record with %100, a period, %101, a period, %102, a period and %103.
At this point, the reformatted records look like this:
167.113.117.99
167.90 .18 .99
167.80 .118.98
165.250.89 .562
167.125.890.95
168.250.89 .99
167.125.890.99
0 .0 .0 .0
167.90 .580.99
- IFTHEN WHEN=(logexp) clause: If the first fixed-length field
is '167' and the fourth fixed-length field is '99 ', we overlay the
second fixed-length field with '113' and the third fixed-length field
with '75'. Then we squeeze the fields to the left to remove the blanks.
- IFTHEN WHEN=NONE clause: If the first fixed-length field is not
'167' or the fourth fixed-length field is not '99 ', we squeeze the
fields to the left to remove the blanks.