The EGL add statement places a record in a file, message queue, or database; or places a set of records in a database.
An example is as follows:
if (userRequest = "A") try add record1; onException myErrorHandler(12); end end
The behavior of the add statement depends on the record type. For details on SQL processing, see SQL record.
When you add an indexed record, the key in the record determines the logical position of the record in the file. Adding a record to a file position that is already in use results in the hard I/O error UNIQUE or (if duplicates are allowed) in the soft I/O error DUPLICATE.
When you add a MQ record, the record is placed at the end of the queue. This placement occurs because the add invokes one or more MQSeries calls:
When you add a relative record, the key item specifies the position of the record in the file. Adding a record to a file position that is already in use, however, results in the hard I/O error UNIQUE.
The record key item must be available to any function that uses the record and can be any of these:
When you add a serial record, the record is placed at the end of the file.
If the generated program adds a serial record and then issues a get next statement for the same file, the program closes and reopens the file before executing the get next statement. A get next statement that follows an add statement therefore reads the first record in the file. This behavior also occurs when the get next and add statements are in different programs, and one program calls another.
It is recommended that you avoid having the same file open in more than one program at the same time.
Some error conditions are as follows:
The result is as follows when you add an SQL record without specifying an explicit SQL statement:
INSERT INTO tableName (column01, ... columnNN) values (:recordItem01, ... :recordItemNN)
An example that uses a dynamic array of SQL records is as follows:
try add employees; onException sysLib.rollback(); end
Related concepts
References to parts
Record types and properties
SQL support
Related tasks
Syntax diagram
Related reference
close
delete
get
get next
get previous
Exception handling
execute
I/O error values
open
prepare
EGL statements
replace
SQL item properties
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.