CategoryDF Sort

Replacing low values to spaces in Sort

How can I replace all the low-values in a file to spaces?

We can use ALTSEQ CODE to change the low-values or high-values to spaces in a file using Sort.
Here’s an example of how you could change all low values (X’00’) to spaces (X’40’), in an FB data set with an LRECL of 80:

ALTSEQ CODE=(0040)
OUTREC FIELDS=(1,80,TRAN=ALTSEQ)

Converting a file from VB to FB.

DFSORT can be used to do VB to FB conversion, when sorting, copying or merging. The VTOF or CONVERT and OUTREC operands of OUTFIL can be used to change variable-length (e.g. VB) input records to fixed-length (e.g. FB) output records. VTOF or CONVERT indicates that conversion is to be performed and OUTREC defines the reformatted records. All output data sets for which VTOF or CONVERT is used must have or will be given fixed-length record formats.

An example of OUTFIL conversion:

//VTOF EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSDUMP DD SYSOUT=*
//SORTIN DD DSN=M145.TEMP.SORT.IN,DISP=SHR
//SORTOUT DD DSN=M145.TEMP.SORT.OUT,
// DISP=(NEW,CATLG,DELETE),UNIT=DASD,
// SPACE=(TRK,(500,500),RLSE),
// DCB=(RECFM=FB,LRECL=80)
//SYSIN DD *
            SORT FIELDS=COPY
            OUTFIL FNAMES=SORTOUT,VTOF,OUTREC=(5,80),VLFILL=C’*’
//*

The above step will copy the records from SORTIN to SORTOUT. If the input records are shorter than 80 bytes, the output is padded with ‘*’ (Specified by VLFILL).

If VLFILL option is not specified, by default the records are padded with spaces.

VLFILL=C’x’ => pad with the character x.
VLFILL=X’yy’ => pad with hexadecimal character X’yy’.

Change uppercase to lowercase or lowercase to uppercase in Sort

Translation features of INREC, OUTREC and OUTFIL make it easy to change the case of characters in your fields.

The TRAN=LTOU operand can be used to change lowercase EBCDIC letters (a-z) to uppercase EBCDIC letters (A-Z) anywhere in a field.

The TRAN=UTOL operand can be used to change uppercase EBCDIC letters to lowercase EBCDIC letters anywhere in a field.

You could change the case in the entire record as well or part of the record.

For example, here’s how you could change uppercase to lowercase in the records of an FB data set with an LRECL of 200:

OUTREC BUILD=(1,200,TRAN=UTOL)

And here’s how you could change uppercase to lowercase in the records of a VB data set with any LRECL:

OUTREC BUILD=(1,4,5,TRAN=UTOL)

Here’s how you could change lowercase letters to uppercase letters in a 100-byte character field starting at position 51 in an FB data set with an LRECL of 300:


OUTREC BUILD=(1,50,                      1-50: no change 
              51,100,TRAN=LTOU,        51-150: L to U                                    
            151,150)                   151-300: no change

Add leading and trailing Characters in Sort

Lets assume that we have a sequential dataset with records as below:

ONE
TWO
THREE
FOUR
FIVE

I want to reformat the records for output as follows:

NUMBER ‘ONE’
NUMBER ‘TWO’
NUMBER ‘THREE’
NUMBER ‘FOUR’
NUMBER ‘FIVE’

You can do this quite easily with DFSORT’s JFY function as follows:

OPTION COPY
INREC BUILD=(1,13,JFY=(SHIFT=LEFT,LEAD=C’NUMBER ”’, TRAIL=C””))

SHIFT=LEFT left-justifies the data. LEAD inserts the hard coded text NUMBER ‘ before the value with no intervening blanks.

TRAIL inserts ‘ after the value with no intervening blanks.