Page 1 of 1

How to get last field?

PostPosted: Mon Jan 18, 2016 4:43 pm
by ottoelflaco
Hello! (sorry my english),

I m trying to get the last field of the input file. For example:

Input file:
CL LOCKHART RD WANCHAI 1
4 NEW YORK PLAZAFLOOR 15
CL PINAR DE SAN JOSE S/N
ST 26-28F 30F NO 66
CL ORENSE 69
20th Abbey road S/N
APOQUINDO 789
GRAN VIA DE HORTALEZA 1
CL PIO XII 23
CL GANDHI 2


Out file:
1
15
S/N
66
69
S/N
789
1
23
2


I thought that PARSE had any paremeter to start extracting data since last space, but no...:
https://www-01.ibm.com/support/knowledg ... meters.htm


Can anybody give me light about this? :(


Thank youu!!

Re: How to get last field?

PostPosted: Mon Jan 18, 2016 5:04 pm
by BillyBoyo
Presumably you have a fixed-length line? How long?

If you PARSE for the maximum possible number of words, you can OVERLAY (or BUILD) the PARSEd fields, prefixed by a blank, in reverse order. Then a second PARSE with STARTAFT=BLANKS.

Re: How to get last field?

PostPosted: Mon Jan 18, 2016 6:52 pm
by ottoelflaco
fixed 64.

Billyroyo, this is?:
//STEP1:
SORT FIELDS=COPY                         
INREC PARSE=(%01=(ENDBEFR=C' ',FIXLEN=10),
             %02=(ENDBEFR=C' ',FIXLEN=10),
             %03=(ENDBEFR=C' ',FIXLEN=10),
             %04=(ENDBEFR=C' ',FIXLEN=10),
             %05=(ENDBEFR=C' ',FIXLEN=10),
             %06=(ENDBEFR=C' ',FIXLEN=10),
             %07=(FIXLEN=10)),           
BUILD=(%07,%06,%05,%04,%03,%02,%01)


//STEP2
SORT FIELDS=COPY                             
INREC PARSE=(%01=(STARTAFT=BLANKS,FIXLEN=10)),
      BUILD=(%01)                           





thank you!!

Re: How to get last field?

PostPosted: Mon Jan 18, 2016 7:01 pm
by BillyBoyo
It doesn't have to have a second step.

You can use multiple IFHTHEN=(WHEN=INIT on your INREC. Or you can just use OUTREC or OUTFIL to do the second PARSE and BUILD.

Make sure you have enough PARSEs to cover all possibilities. If you have 30 characters, you'll need 16 PARSEs (theoretically).

An alternative if with lots of IFTHEN=(WHEN=(logicalexpression) starting with the last PARSEd field first, but it's more code.