fupdate() — Update a VSAM record

Standards

Standards / Extensions C or C++ Dependencies
Language Environment both  

Format

#include <stdio.h>

size_t fupdate(const void *buffer, size_t size, FILE *stream);

#define _OPEN_SYS_UNLOCKED_EXT 1
#include <stdio.h>

size_t fupdate_unlocked(const void *buffer, size_t size, FILE *stream);

General description

Replaces the last record read from the VSAM cluster pointed to by stream, with the contents of buffer for a length of size. See “Performing VSAM I/O Operations” in z/OS XL C/C++ Programming Guide for details.

The fupdate() function can be used only with a VSAM data set opened in update mode (rb+/r+b, ab+/a+b, or wb+/w+b) with the type=record option.

The fupdate() function can only be used after an fread() call has been performed and before any other operation on that file pointer. For example, if you need to acquire the file position using ftell() or fgetpos(), you can do it either before the fread() or after the fupdate(). An fread() after an fupdate() retrieves the next updated record.

To avoid infringing on the user's name space, this nonstandard function has two names. One name is prefixed with two underscore characters, and one name is not. The name without the prefix underscore characters is exposed only when you use LANGLVL(EXTENDED).

To use this function, you must either invoke the function using its external entry point name (that is, the name that begins with two underscore characters), or compile with LANGLVL(EXTENDED). When you use LANGLVL(EXTENDED) any relevant information in the header is also exposed.

fupdate_unlocked() is functionally equivalent to fupdate() with the exception that it is not thread-safe. This function can safely be used in a multithreaded application if and only if it is called while the invoking thread owns the (FILE*) object, as is the case after a successful call to either the flockfile() or ftrylockfile() function.

KSDS or KSDS PATH: The size of the record can be changed by a call to fupdate(). If the size is greater than the existing record size but less than or equal to the maximum record length of the file, a call to fupdate() will lengthen the record up to the maximum record length of the file. If the size is greater than the maximum record length of the file, the record is truncated and errno is set. If the size is less than or equal to the existing record length, all size bytes of the record are written, and no padding or overlaying occurs. The records will be shortened and not partially updated.

ESDS, ESDS PATH, or RRDS: The size of a record cannot be changed by a call to fupdate(). If you call fupdate() with size smaller than the size of the existing record, size bytes of the record are updated; the remaining bytes are unchanged, and the record length remains unchanged.

The key of reference (the prime key if opened as a cluster, the alternative index key if opened as a path) cannot be changed by an update. If a data set is opened as a path, the prime key cannot be changed by an update. For RRDS files, the buffer must be an RRDS record structure, which includes an rrds_key.

Returned value

If successful, fupdate() returns the size of the updated record.

If the update operation is not successful, fupdate() returns 0.

Example

CELEBF50
⁄* CELEBF50 *⁄                                   
#include <stdio.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
   struct record { char name[20];                                               
                    char address[40];                                           
                    int age;                                                    
                 } buffer;                                                      
   int vsam_rc, numread;                                                        
                                                                                
   stream = fopen("DD:MYCLUS", "rb+,type=record");                              
   numread = fread(&buffer, 1, sizeof(buffer), stream);                         
   ⁄*  ... Update fields in the record ...  *⁄                                  
   vsam_rc = fupdate(&buffer, sizeof(buffer), stream);                          
}                                                                               

Related information