Appendix D. FCD Handling API

Table of Contents

D.1. Overview
D.2. File Open Session
D.2.1. tfcd_open()
D.2.2. tfcd_close()
D.3. Record Access
D.3.1. tfcd_start()
D.3.2. tfcd_read()
D.3.3. tfcd_write()
D.3.4. tfcd_writea()
D.3.5. tfcd_delete()
D.4. Special Operations
D.4.1. tfcd_is_file_open()
D.4.2. tfcd_get_status()
D.4.3. tfcd_get_file_name()
D.4.4. tfcd_get_rec_len()
D.4.5. tfcd_set_file_name()
D.4.6. tfcd_set_relative_key()
D.4.7. tfcd_set_key_id()
D.4.8. tfcd_set_rec_len()

This appendix describes the FCD Handling API methods used to read/write data sets, opened by a main COBOL application, from a C subprogram.

You can use the File Control Description (FCD) Handling API provided by OpenFrame to perform I/O operations, such as read and write for the data set that is opened from a main COBOL application, from a subprogram written in C. The main COBOL application must be compiled by the MF-COBOL compiler.

The FCD Handling API library uses FCD as a structure to store data set information. This FCD is a memory structure created when the executable binary, the compilation result by the MF-COBOL compiler, opens a data set during execution. Therefore, the Tmax FCD Handling API library explained in this chapter can be used only along with the executable binary compiled by the MF-COBOL compiler.

Note

When performing I/O operations on the data set from a C program, it is recommended to use the C File Handler library instead of the FCD Handling API library.

To write a program using the FCD Handling API, you must include the header file tfcd.h distributed with the OpenFrame binary in a C sub program and link the libtfcd.so library during compilation.

The Tmax FCD handling API can be classified as follows:

  • File Open Session

    APIDescription

    tfcd_open()

    Opens the data set described in FCD structure.

    tfcd_close()

    Closes the data set described in FCD structure.

  • Record Access

    APIDescription

    tfcd_start()

    Moves to the next record in a relative or indexed data set.

    tfcd_read()

    Reads data set records sequentially or randomly by specifying a key.

    tfcd_write()

    Writes a new record to a data set (WRITE), or rewrites an existing record (REWRITE).

    tfcd_writea()

    Writes a new record to a data set by specifying ASA control character at the head of record.

    tfcd_delete()

    Deletes an existing record from a data set. (RELATIVE/INDEXED)

  • Special Operations

    APIDescription

    tfcd_is_file_open()

    Checks if the data set described in the FCD structure is open.

    tfcd_get_status()

    Retrieves the status code in order to check if an error has occurred, after performing I/O on a data set.

    tfcd_get_file_name()

    Retrieves the DD name of the data set described in FCD structure.

    tfcd_get_rec_len()

    Retrieves the record length of the data set described in FCD structure.

    tfcd_set_file_name()

    Specifies the DD name of the data set described in FCD structure.

    tfcd_set_relative_key()

    Specifies the relative key of the data set described in FCD structure. (RELATIVE)

    tfcd_set_key_id()

    Specifies the KEY ID of the data set described in FCD structure. (INDEXED)

    tfcd_set_rec_len()

    Specifies the record length of the data set described in FCD structure.

Moves to the next record in a RELATIVE data set or INDEXED data set. To set the record position to move to, specify a relative record number by calling the tfcd_set_relative_key() API for a RELATIVE data set, or store the key value in the key location within the record pointer for an INDEXED data set.

When executing the START API, it can be specified to find records with key values that are the same as or larger than the key value specified using the following macros defined in the tfcd.h header.

#define TFCD_START_DEFAULT          0   /* START */
#define TFCD_START_EQUAL            1   /* START (equal to full length) */
#define TFCD_START_GTEQ             2   /* START (not less than) */

For a VSAM data set, ALTERNATE RECORD KEY can be defined in addition to the basic RECORD KEY of the data set. To execute the START API by using the ALTERNATE RECORD KEY, call the tfcd_set_key_id() API and specify the KEY ID that is used in the next START API. KEY IDs are assigned in the order that the ALTERNATE RECORD KEYs are specified in the SELECT statement of the main COBOL application.

  • Prototype

    int tfcd_start(void *fcd, char *record, int flags);
  • Parameters

    ParameterDescription

    fcd (IN/OUT)

    FCD structure address passed from the main COBOL application.

    record (IN/OUT)

    Record buffer pointer that stores the position of the record to move to.

    flags (IN)

    Attributes that can be specified when starting the data set.

    • EQUAL

    • GTEQ

  • Return Value

    If executed successfully, 0 is returned. To verify that the data set has been started successfully, check the status code.

Reads records from a data set sequentially or randomly by specifying a key. When reading records randomly, specify a relative record number by calling the tfcd_set_relative_key() API for a RELATIVE data set or store the key value in advance in the key location within the record pointer for an INDEXED data set.

For a VSAM data set, ALTERNATE RECORD KEY can be defined in addition to the basic RECORD KEY of the data set. To read records randomly by using the ALTERNATE RECORD KEY, call the tfcd_set_key_id() API and specify the KEY ID that is used in the next READ API. For KEY IDs, numbers are given in the order that the SELECT statement specified ALTERNATE RECORD KEYs in the main COBOL application.

Macros, which define whether to read records sequentially or randomly when executing the READ API, are defined as follows in the tfcd.h header file.

#define TFCD_READ_DEFAULT           0   /* READ */
#define TFCD_READ_NEXT              1   /* READ (sequential) */

For a variable length record data set, when reading data set records by using the READ API, the record length that was read can be obtained by calling the tfcd_get_rec_len() API. The record length obtained is the length of the record data excluding RDW.

  • Prototype

    int tfcd_read(void *fcd, char *record, int flags);
  • Parameters

    ParameterDescription

    fcd (IN/OUT)

    FCD structure address passed from the main COBOL application.

    record (IN/OUT)

    Record buffer pointer where the record read from data set is stored.

    flags (IN)

    Attributes that can be specified when reading data set.

    • DEFAULT

    • NEXT

  • Return Value

    If executed successfully, 0 is returned. To check that the data set is read successfully, check the status code.