VTOF EXAMPLE – Converting VB to FB
Here is a standard, practical JCL example that demonstrates how to convert a VB file to an FB file.
Assume we have an input VB file with a maximum length (LRECL) of 104 bytes, and we want to convert it to an FB file with an LRECL of 100 bytes.
//STEP001 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=FILE01,DISP=SHR
//FBOUT DD DSN=FILE02,DISP=(NEW,CATLG,DELETE),
// UNIT=3390,SPACE=(CYL,(5,5))
//SYSIN DD *
OPTION COPY
OUTFIL FNAMES=FBOUT,VTOF,OUTREC=(5,100)
/*
Breaking down the SYSIN control cards:
OPTION COPY: Tells the utility we are just copying data, not sorting it. OUTFIL FNAMES=FBOUT: Directs the output to the DD name FBOUT. VTOF: Instructs DFSORT to perform the Variable-to-Fixed conversion. OUTREC=(5,100): Tells the program to extract 100 bytes of data starting from position 5 of the input VB record (skipping the 4-byte RDW).
Handling Short Records (Padding)
One of the main challenges of converting a VB file is that some input records might be shorter than your target FB length.
By default, if a VB input record has fewer data bytes than what is specified in your OUTREC length, DFSORT will automatically pad the right side of the output record with blanks (spaces) to reach the required fixed length.
However, if you want to pad the short records with a specific character instead of blanks, you can use the VLFILL parameter.
For example, VLFILL=C’*’ pads with asterisks and VLFILL=X’00’ pads with binary zeros:
//SYSIN DD *
OPTION COPY
OUTFIL FNAMES=FBOUT,VTOF,OUTREC=(5,100), VLFILL=C’ ’
/*
VLFILL=f – Missing fields will be filled with blanks (x’40’) when CONVERT option in use; missing fields cause application termination when CONVERT is not specified .
Note: If VLFILL is specified, the OUTREC parameter must also be specified. VLFILL is ignored when the FTOV parameter is used.
CONVERT Method
The CONVERT parameter is used in conjunction with the OUTREC parameter to convert variable-length records to fixed-length records. The records do not require an RDW and will be written to the output file(s) with a RECFM of F or FB. When using CONVERT, you no longer need to apply the rules for “Specifying the FIELDS parameter for Variable-Length Records” found in the description of the OUTREC control statement. You cannot specify the variable portion of the input records (position without length) when using CONVERT. The OUTFIL VLFILL parameter can be used to specify a different fill byte for any missing fields (see above description).
Notes: If CONVERT is specified, the OUTREC parameter must also be specified. CONVERT cannot be used with the IFTRAIL, FTOV, or VTOF parameters.
//STEP001 EXEC PGM=SORT
//SORTIN DD DSN=FILE,DISP=SHR <===== Variable input file
//SORTOUT DD DSN=OUTPUT.FIXED.FILE, <===== Fixed output.
// DISP=(NEW,CATLG,DELETE),
// UNIT=(SYSDA),SPACE=(TRK,(50,15),RLSE),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
INREC FIELDS=(1:1,4,
6:6,74)
SORT FIELDS=(62,8,CH,A)
OUTFIL OUTREC=(1:1,4,
6:6,74,
80:C' '),CONVERT
//*
Best Practices for File Conversion
- Always Account for the RDW: The most common mistake programmers make is forgetting that a VB file’s
LRECL includes the 4-byte RDW. If your VB file LRECL is 80, the actual data length is only 76. Your FB output LRECL should generally be 76, and your OUTREC should be (5,76). - Backup Data First: Always ensure you have a backup of your original VB file or write the output to a completely new dataset to avoid accidental data loss.
- Check LRECL and BLKSIZE: Ensure the JCL defining your output dataset (
DCB parameters) matches the length you are generating in the OUTREC statement. Let the system determine the optimal block size by coding BLKSIZE=0. - Verify Data: After the conversion, browse the new FB dataset to ensure data alignment is correct and that padding was applied exactly where expected.
Conclusion
Converting from VB to FB format using the VTOF utility is a valuable capability in environments where fixed-length records are preferred or required. By following the outlined steps and considering best practices, organizations can seamlessly transition their data files to meet specific formatting needs while preserving data integrity and system compatibility. The VTOF utility serves as a reliable tool for efficiently performing this conversion and aligning data structures with the desired file format.