Writing to a Diskette File - IBM-ILE

You can write records to a diskette file.

A diskette file is a device file that is used for a diskette unit. The object type is *FILE. The Tape and Diskette Device Programming manual contains information on diskette files.

I/O Considerations for Diskette Files

A diskette unit can only be accessed with a program described file. An ILE C/C++ program can only process a diskette file sequentially. The concept of clearing a file or opening a file using append mode does not apply to diskette files.

The diskette file label name is required when the file is opened. You specify this label name using the Override Diskette File (OVRDKTF) command. If the diskette file is opened for input and:

  • if the lrecl parameter is not specified or is specified as zero, the record length in the data file label on the name on the diskette is used to determine the length of the records to read.
  • if the lrecl parameter is greater than the length of the records on the diskette file, the records that are read are padded with blanks.
  • if the lrecl parameter is less than the length of the records on the diskette file, the records that are read are truncated.
  • if the file type in the diskette file is a source file, a date and sequence number (12 bytes) is appended at the beginning of each record. You must remove these when writing the record and add 12 bytes to the lrecl parameter on the open statement.

Note: Output may not always result in an I/O operation to a diskette file. The I/O buffer must contain enough data to fill an entire track on a diskette. When opening a diskette file for output, any files existing on the diskette are deleted if the data file expiration date is less than or equal to the system date.

Opening Diskette Files as Binary Stream Files

To open an iSeries diskette file as a binary stream file for record-at-a-time processing, use the fopen() function with one of the following modes:

•rb •wb

Note: The only way to create a diskette file is to use the CRTDKTF command. If you use fopen() and the diskette file does not exist, a physical database file is created.

The valid keyword parameters are:

•type •lrecl •blksize

I/O Considerations for Binary Stream Diskette Files

Blocking Binary Stream Diskette Files: If your program processes diskette files, performance can be improved if I/O operations are blocked. If you do not specify a value for the blksize parameter or if you specify blksize=0 on fopen(), the system calculates a number of records to be transferred as a block to your program.

Binary Stream Functions for Diskette Files

Use the following binary stream functions to process diskette files:

  • fclose()
  • fopen()
  • fread()
  • freopen()
  • fwrite()

Opening Diskette Files as Record Files

To open an iSeries diskette file as a record file, use the _Ropen() function with one of the following modes:

•rr •wr

The valid keyword parameters are:

•blkrcd •lrecl •secure •riofb

I/O Considerations for Record Diskette Files

The _Rfeod() function is valid for diskette record files opened for input and output operations. It signals the end-of-file. For output operations, it does not write any data.

Read and Write Record Diskette Files: If you read from a diskette file, the next sequential record in the diskette file is processed. Use the _Rreadn() function for reading diskette files and the _Rwrite() function for writing to diskette files.

Blocking Record Diskette Files: If your program processes diskette files, performance can be improved if records are blocked. If you specify blkrcd=Y on _Ropen(), the system calculates a number of records to be transferred as a block to your program.

Record Functions for Diskette Files

Use the following record functions to process diskette files:

Record Functions for Diskette Files

Example

The following example shows how to write to a diskette file.

  1. To create the diskette file T1520DKF, type:
  2. Type:
  3. To create the physical file T1520DDI using the following DDS source:

    A R CUST
    A NAME 20A
    A AGE 3B
    A DENTAL 6B

  4. Type the following records into the database file T1520DDI:
  5. Dave Bolt 35 350
    Mary Smith 54 444
    Mike Tomas 25 545
    Alex Michaels 32 512

  6. To select only records that have a value greater than 400 in the DENTAL field, type:
  7. OPNQRYF FILE((MYLIB/T1520DDI)) QRYSLT(’DENTAL *GT 400’) OPNSCOPE(*JOB)
  8. To create the program T1520DSK using the source shown below, type:
  9. CRTBNDC PGM(MYLIB/T1520DSK) SRCFILE(QCLE/QACSRC)

    T1520DSK — ILE C Source to Write Records to a Diskette File

    ILE C Source to Write Records to a Diskette File

    ILE C Source to Write Records to a Diskette File

    The _Ropen() function opens the diskette file T1520DKF and the database file T1520DDI. The _Rreadn() function reads all database records. The _Rwrite() function copies all database records that have a value > 400 in the dental field to the diskette file T1520DKF.

  10. To run the program T1520DSK, type:
  11. CALL PGM(MYLIB/T1520DSK)

    The output to the diskette file is as follows:

    Mary Smith 444
    Mike Tomas 545
    Alex Michaels 512

    After you run the program, the diskette file contains only the records that satisfied the selection criteria

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM-ILE Topics