Page 1 of 1

DFSORT number records

PostPosted: Fri Mar 16, 2012 2:57 pm
by JorenWillems
Hi

Is it possible to number records in an output file?
My input file looks like this:

Ryan Phillips
John Terry
Frank Lampard
Steven Gerrard


With DFSORT I want someting like this:

1Ryan Phillips
2John Terry
3Frank Lampard
4Steven Gerrard


Is this possible?

Thx

Re: DFSORT number records

PostPosted: Fri Mar 16, 2012 3:20 pm
by BillyBoyo
Yes, if you want sequence number, no if you want shirt numbers :-)

You want just 0-9, or just an example you can apply elsewhere?

Re: DFSORT number records

PostPosted: Fri Mar 16, 2012 3:32 pm
by JorenWillems
I don't want shirt numbers :)
just a sequence of numbers for example
01
02
03
04
05
06
07
08
09
10
11
12
13
14
etc...

Re: DFSORT number records

PostPosted: Fri Mar 16, 2012 3:50 pm
by BillyBoyo
OK, two answers. First, is with a BUILD, putting the sequence number at the start of the record, as you have shown in your example. 2 is the length, ZD is the type, so can be any sensible length and type for a numeric as described in the manual. The 1,17 takes the rest of the data from the input record and places it after the sequence number.

//SEQNUMB EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
  OPTION COPY
  INREC BUILD=(SEQNUM,2,ZD,1,17)
//*
//SORTIN   DD *
SOME RECORDS 01 -
SOME RECORDS 02 -
SOME RECORDS 03 -
SOME RECORDS 04 -
SOME RECORDS 05 -
SOME RECORDS 06 -
SOME RECORDS 07 -
SOME RECORDS 07 -
SOME RECORDS 09 -
SOME RECORDS 10 -


Second is with OVERLAY. Same format, but sequence number appears at the end of the record. No movement of the original data.

With a BUILD and at the front, you can do sequence numbers on a variable-length file and still know where they are afterwards without making the records all the same length (negating the "variable" bit of the file description).

With the OVERLAY you can add a sequence number to the back of the record on a fixed-length file, without shifting the data around (so performing better).

//SEQNUMO EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
  OPTION COPY
  INREC OVERLAY=(18:SEQNUM,2,ZD)
//SORTIN   DD *
SOME RECORDS 01 -
SOME RECORDS 02 -
SOME RECORDS 03 -
SOME RECORDS 04 -
SOME RECORDS 05 -
SOME RECORDS 06 -
SOME RECORDS 07 -
SOME RECORDS 07 -
SOME RECORDS 09 -
SOME RECORDS 10 -



Output 1:

01SOME RECORDS 01 -
02SOME RECORDS 02 -
03SOME RECORDS 03 -
04SOME RECORDS 04 -
05SOME RECORDS 05 -
06SOME RECORDS 06 -
07SOME RECORDS 07 -
08SOME RECORDS 07 -
09SOME RECORDS 09 -
10SOME RECORDS 10 -
Output 2:

SOME RECORDS 01 -01
SOME RECORDS 02 -02
SOME RECORDS 03 -03
SOME RECORDS 04 -04
SOME RECORDS 05 -05
SOME RECORDS 06 -06
SOME RECORDS 07 -07
SOME RECORDS 07 -08
SOME RECORDS 09 -09
SOME RECORDS 10 -10