kinsert -- Insert Record into Keyed File

SYNOPSIS

 #include <lcio.h>

 int kinsert(const void *rec, size_t length, void *key, FILE *f);
 

DESCRIPTION

The kinsert function adds a new record to the keyed stream associated with the FILE object addressed by f. The rec pointer addresses the record to be written. The length argument indicates the length of the record to be written (including the 4-byte key prefix for ESDS or RRDS files). The key pointer addresses the key data for the new record. If key is a NULL pointer, the key is obtained from rec.

For an ESDS file, the key for a new record is assigned by VSAM, not by the program. For these files, the contents of the area addressed by key are ignored, but the key assigned by VSAM is stored in this area when kinsert returns, if key is not NULL.

After successful completion of kinsert, the file is positioned to the record following the one inserted.

RETURN VALUES

The kinsert function returns 0 if it is successful, or a negative value if it is unsuccessful.

DIAGNOSTICS

Most VSAM files do not permit more than one record with the same key. If you attempt to add a record with a duplicate key to such a file, kinsert returns a negative number, and the file's error flag is set. However, no diagnostic message is issued by the library because this error is frequently expected in working programs. The external variable errno is set to EDUPKEY for this condition, enabling the program to distinguish this condition from other errors.

If the run-time option =warning is in effect, a run-time diagnostic is generated for this condition.

EXAMPLE

For an example using the kinsert function, see VSAM I/O Example .

RELATED FUNCTIONS

kdelete, kreplace

SEE ALSO


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.