How to get last field?



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

How to get last field?

Postby ottoelflaco » Mon Jan 18, 2016 4:43 pm

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!!
ottoelflaco
 
Posts: 36
Joined: Fri Sep 21, 2012 2:33 pm
Has thanked: 1 time
Been thanked: 0 time

Re: How to get last field?

Postby BillyBoyo » Mon Jan 18, 2016 5:04 pm

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.

These users thanked the author BillyBoyo for the post:
ottoelflaco (Mon Jan 18, 2016 6:56 pm)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: How to get last field?

Postby ottoelflaco » Mon Jan 18, 2016 6:52 pm

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!!
ottoelflaco
 
Posts: 36
Joined: Fri Sep 21, 2012 2:33 pm
Has thanked: 1 time
Been thanked: 0 time

Re: How to get last field?

Postby BillyBoyo » Mon Jan 18, 2016 7:01 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post