6 8 LceCheckFor

LANSA Open Guide

6.8 LceCheckFor

Checks for the existence of a record in the specified file using the keys specified.

BOOL 

LceCheckFor

(int 

iSession,

 

 

 char far * 

strFileName,

 

 

 char far * 

strKeyList )

  

Parameters

iSession

The session identifier as returned by LceGetSessionId.

strFileName

The name of the file. The file used must have been declared using an LceUseFile function.

strKeyList

A list of field names to be used as keys. The key fields must have been declared using the LceUseField function.

  

Return Values

TRUE is returned if the session can find the record.

FALSE is returned if an error occurs or the record does not exist.

Notes

Portability Considerations

An I/O error (Error 37) will result if you provide an empty string for the strKeyList parameter and your host system is a Windows, Linux or other non-IBM i host. If your host system is LANSA on an IBM i, no error will occur but the call will return FALSE.

  

This function is used to check if a record already exists in a file. You must know the specific key fields to the file. That is, the key list must match the actual file's keys. The values for the keys are set using the LceSetFieldValue/LCeSetFieldValueU function.

You might use the LceCheckFor function when you wish to find out if a record exists but you do not want to fetch the record. For example, if checking if a file has related information on another file before deleting a record.

Tip

The LceInsert, LceUpdate and LceDelete functions have a validate parameter which allows a check to be made without performing the actual insert/update/delete operation. Use this validate parameter with these functions instead of this LceCheckFor function.

Alternatively, you can use the LANSA Repository to perform these referential integrity checks (for insert, update, and delete) provided that you have created the proper validation rules in the Repository. For example, LANSA will check that a customer number exists in the customer file before it creates a new order for that customer in the order file.

Related Functions

6.71 LceUseFile

6.58 LceSetFieldValue

LceSetFieldValueU

6.43 LceInsert

6.67 LceUnicodeToHex

6.10 LceDelete