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.
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
API | Description |
---|---|
Opens the data set described in FCD structure. | |
Closes the data set described in FCD structure. |
Record Access
API | Description |
---|---|
Moves to the next record in a relative or indexed data set. | |
Reads data set records sequentially or randomly by specifying a key. | |
Writes a new record to a data set (WRITE), or rewrites an existing record (REWRITE). | |
Writes a new record to a data set by specifying ASA control character at the head of record. | |
Deletes an existing record from a data set. (RELATIVE/INDEXED) |
Special Operations
API | Description |
---|---|
Checks if the data set described in the FCD structure is open. | |
Retrieves the status code in order to check if an error has occurred, after performing I/O on a data set. | |
Retrieves the DD name of the data set described in FCD structure. | |
Retrieves the record length of the data set described in FCD structure. | |
Specifies the DD name of the data set described in FCD structure. | |
Specifies the relative key of the data set described in FCD structure. (RELATIVE) | |
Specifies the KEY ID of the data set described in FCD structure. (INDEXED) | |
Specifies the record length of the data set described in FCD structure. |
Opens the data set described in FCD structure. The process of opening a data set is a preparation process for I/O operations, such as read and write, on the records of a data set allocated by DD statement in JCL.
For OPEN MODEs used to open a data set, the following macros are defined in the tfcd.h header file.
#define TFCD_OPEN_INPUT 0 /* OPEN INPUT */ #define TFCD_OPEN_OUTPUT 1 /* OPEN OUTPUT */ #define TFCD_OPEN_INOUT 2 /* OPEN I-O */ #define TFCD_OPEN_EXTEND 3 /* OPEN EXTEND */
When a data set is opened successfully, 00 is stored in the status code which can be checked with tfcd_get_status(). If you try to reopen a data set which is already opened, an error occurs.
Prototype
int tfcd_open(void *fcd, int open_mode, int flags);
Parameters
Parameter | Description |
---|---|
fcd (IN/OUT) | FCD structure address passed from the main COBOL application. |
open_mode (IN) | Data set OPEN mode.
|
flags (IN) | Attributes that can be specified when opening a data set.
|
Return Value
If executed successfully, 0 is returned. To verify that the data set has been opened successfully, check the status code.
Closes the data set described in the FCD structure. The process of closing a data set disconnects the application from the physical data set after the application performs I/O operations such as read and write for the data set.
When a data set is closed successfully, 00 is stored in the status code which can be checked with tfcd_get_status(). Once closed, a data set can be opened again by using the tfcd_open() API.
Prototype
int tfcd_close(void *fcd, int flags);
Parameters
Parameter | Description |
---|---|
fcd (IN/OUT) | FCD structure address passed from the main COBOL application. |
flags (IN) | Attributes that can be specified when closing a data set.
|
Return Value
If executed successfully, 0 is returned. To verify that the data set has been closed successfully, check the status code.
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
Parameter | Description |
---|---|
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.
|
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
Parameter | Description |
---|---|
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.
|
Return Value
If executed successfully, 0 is returned. To check that the data set is read successfully, check the status code.
Writes a new record to a data set (WRITE) or rewrites an existing record (REWRITE).
Writes a record at the end of the data set for a sequential data set. For a RELATIVE data set, call the tfcd_set_relative_key() API and specify the relative record number to be stored. For an INDEXED data set, records are stored according to the order of keys within the record pointer.
The macros, which decide whether to write a new record or overwrite the existing record when executing the WRITE API, are defined as follows in the tfcd.h header file.
#define TFCD_WRITE_DEFAULT 0 /* WRITE */ #define TFCD_WRITE_REWRITE 1 /* REWRITE */
For a variable length record data set, the record length can be specified by calling the tfcd_set_rec_len() API before writing data set records with the WRITE API. The record length is the length of the record data excluding RDW.
Prototype
int tfcd_write(void *fcd, char *record, int flags);
Parameters
Parameter | Description |
---|---|
fcd (IN/OUT) | FCD structure address passed from the main COBOL application. |
record (IN) | Buffer pointer where the record to write in a data set is stored. |
flags (IN) | Attributes that can be specified when reading a data set.
|
Return Value
If executed successfully, 0 is returned. To check that the data set was written to successfully, check the status code.
Writes a new record to a data set by specifying an ASA control character at the beginning of the record. The macros that specify an ASA control character when executing the WRITE API are defined in the tfcd.h header file as follows:
#define TFCD_WRITEA_AFTER 0 /* AFTER */ #define TFCD_WRITEA_BEFORE 1 /* BEFORE */ #define TFCD_WRITEA_TAB 2 /* TAB */ #define TFCD_WRITEA_PAGE 4 /* PAGE */ #define TFCD_WRITEA_MNEMONIC 8 /* MNEMONIC */
Prototype
int tfcd_writea(void *fcd, char *record, int lcount, int flags);
Parameters
Parameter | Description |
---|---|
fcd (IN/OUT) | FCD structure address passed from the main COBOL application. |
record (IN) | Record buffer pointer where the record to be written to a data set is stored. |
lcount (IN) | Number of lines to advance before outputting records. |
flags (IN) | Attributes that can be specified when writing to a data set. |
Return Value
If executed successfully, 0 is returned. To check that the data set is written successfully, check the status code.
Deletes a previously read record from a RELATIVE or INDEXED data set.
Prototype
int tfcd_delete(void *fcd, char *record, int flags);
Parameters
Parameter | Description |
---|---|
fcd (IN/OUT) | FCD structure address passed from the main COBOL application. |
record (IN) | Record buffer pointer where the record to be deleted from data set is stored. |
flags (IN) | Attributes that can be specified when deleting a data set. |
Return Value
If the function was executed successfully, 0 is returned. To check that the data set has been deleted successfully, check the status code.
Checks that the data set described in the FCD structure is open. This is used to check that the data set is open before changing the DD name for the data set opened by a main COBOL application.
Prototype
int tfcd_is_file_open(void *fcd);
Parameters
Parameter | Description |
---|---|
fcd (IN) | FCD structure address passed from the main COBOL application. |
Return Value
If the data set is opened, returns 1. Otherwise, returns 0.
After performing an I/O operation on a data set, this API retrieves the data set status code to check if an error has occurred. In general, if the status code value is a space, it means the I/O operation on the data set was successful.
If a critical system error or OpenFrame library error occurs while performing I/O on a data set, the program terminates and shows an error message. However, for general data set I/O errors, such as END OF FILE, the program does not terminate and the I/O function returns normally after setting the proper status code value. After executing an I/O function, it is necessary to check if an error occurred through the tfcd_get_status() function.
For information on status code values that can be set in data set I/O functions, refer to the MicroFocus Server Express online manual. (http://supportline.microfocus.com/Documentation/books/sx40sp2/sx40indx.htm)
Prototype
int tfcd_get_status(void *fcd, char *status);
Parameters
Parameter | Description |
---|---|
fcd (IN) | FCD structure address passed from the main COBOL application. |
status (OUT) | Buffer to store the data set status code. |
Return Value
If executed successfully, 0 is returned.
Retrieves the DD name of the data set described in FCD structure. This API can be used for both opened and closed data sets.
Prototype
int tfcd_get_file_name(void *fcd, char *file_name);
Parameters
Parameter | Description |
---|---|
fcd (IN) | FCD structure address passed from the main COBOL application. |
file_name (OUT) | Buffer to store the data set DD name. |
Return Value
If executed successfully, 0 is returned.
Retrieves the record length of the data set described in the FCD structure. The fixed record length of the entire data set at the point when the fixed-length data set was first opened can be retrieved. And it can be used to obtain the read record length after reading a variable length data set record with the READ API.
For a variable length record data set, the record length is the length of the record data excluding RDW.
Prototype
int tfcd_get_rec_len(void *fcd, int *reclen);
Parameters
Parameter | Description |
---|---|
fcd (IN) | FCD structure address passed from the main COBOL application. |
reclen (OUT) | Buffer to store the data set record length. |
Return Value
If executed successfully, 0 is returned.
Specifies the DD name of the data set described in FCD structure. It is used to change the DD name of the data set, which was opened by a main COBOL application, to open a new data set. Before using this API, opened data sets must be changed to the close state by using the CLOSE API.
Prototype
int tfcd_set_file_name(void *fcd, char *file_name);
Parameters
Parameter | Description |
---|---|
fcd (IN/OUT) | FCD structure address passed from the main COBOL application. |
file_name (IN) | DD name to be specified in data set. |
Return Value
If executed successfully, 0 is returned.
Specifies the relative key of the data set described in FCD structure (RELATIVE). For a RELATIVE data set, a new record is stored or the existing record is read in the relative key location specified by tfcd_set_relative_key().
Prototype
int tfcd_set_relative_key(void *fcd, int relative_key);
Parameters
Parameter | Description |
---|---|
fcd (IN/OUT) | FCD structure address passed from the main COBOL application. |
relative_key (IN) | Status key of RELATIVE data set. |
Return Value
If executed successfully, 0 is returned.
Specifies the KEY ID of the data set described in FCD structure (INDEXED).
To read records randomly by using ALTERNATE RECORD KEY on a data set with ALTERNATE RECORD KEY additionally defined, call the tfcd_set_key_id() API and specify the KEY ID to use in the next READ API.
Prototype
int tfcd_set_key_id(void *fcd, int key_id);
Parameters
Parameter | Description |
---|---|
fcd (IN/OUT) | FCD structure address passed from the main COBOL application (IN/OUT). |
key_id (IN) | KEY ID to be specified in data set (IN). |
Return Value
If executed successfully, 0 is returned.
Specifies the record length of the data set described in FCD structure. It is used to specify the length of the record to be written before writing a variable length data set record with the WRITE API.
For a variable length record data set, the record length is the length of the record data excluding RDW.
Prototype
int tfcd_set_rec_len(void *fcd, int reclen);
Parameters
Parameter | Description |
---|---|
fcd (IN/OUT) | FCD structure address passed from the main COBOL application. |
reclen (IN) | Record length to be specified in data set. |
Return Value
If executed successfully, 0 is returned.