Page 1 of 1

### Last Fields from a VB File

Posted: Mon Jan 09, 2012 5:01 pm
Hi All,

I am sure that this question might have been asked before somewhere. I tried to search the forum but couldnt get any direct answer.
So Here I am, Posting this in a new thread.

Lets say I have a VB file as below:
Rajesh14XXXXX000001
Rajesh13XXXX000001
Rajesh11XX000002
Rajesh11XX000003
Rajesh10X000004
Rajesh11XX000005
Rajesh12XXX000006
Rajesh12XXX000007
Rajesh12XX0000008
Rajesh12XX0000009

Basically there is a fixed 6 digit key at the end of each VB record.

1) How do I write a SORTCARD which gets me only the fixed 6 digit key?
2) I know that the first 4 bytes are RDW on a VB file which have the length each record. Is it possible to use this in a Sortcard?
3) Lets say Hypothetically that in columns between 7 and 8 I have the starting column of the key; e.g 14 in the first record. Is it possible to use this in a Sortcard to get the 6 digit key?

I am sorry if this sounds stupid, But in my current organisation I dont get to work on DFSORT often and hence my prior knowledge is a little hazy.
Would appreciate pointers, even if there is no direct answer.

Thanks,
Rajesh

### Re: Last Fields from a VB File

Posted: Tue Jan 10, 2012 2:00 am
DFSORT does not have any built-in functions for calculating a position from a field, but you can use a series of IFTHEN clauses to do what you want like this (note that your starting column does NOT include the 4-byte RDW, so we have to add 4, e.g. 14 = 14 + 4 = 18).

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=...  input file (VB)
//SORTOUT DD DSN=...  output file (FB/6)
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=(11,2,CH,EQ,C'10'),BUILD=(1,4,14,6)),
IFTHEN=(WHEN=(11,2,CH,EQ,C'11'),BUILD=(1,4,15,6)),
IFTHEN=(WHEN=(11,2,CH,EQ,C'12'),BUILD=(1,4,16,6)),
IFTHEN=(WHEN=(11,2,CH,EQ,C'13'),BUILD=(1,4,17,6)),
IFTHEN=(WHEN=(11,2,CH,EQ,C'14'),BUILD=(1,4,18,6))
OUTFIL VTOF,BUILD=(5,6)
/*

Alternatively, if you use the pattern of the data (nonnumeric, numeric starting in position 13) instead of the column value, you can use DFSORT's PARSE function like this:

OPTION COPY
INREC PARSE=(%01=(ABSPOS=13,FIXLEN=6,
STARTAT=C'0',STARTAT=C'1',STARTAT=C'2',STARTAT=C'3',
STARTAT=C'4',STARTAT=C'5',STARTAT=C'6',STARTAT=C'7',
STARTAT=C'8',STARTAT=C'9')),
BUILD=(1,4,%01)
OUTFIL VTOF,BUILD=(5,6)