EGL Reference Guide for iSeries

add

The EGL add statement places a record in a file, message queue, or database; or places a set of records in a database.



Syntax diagram for the add statement

record name
Name of the I/O object to add: an indexed, MQ, relative, serial, or SQL record
with #sql{ sqlStatement }
An explicit SQL INSERT statement. Leave no space after #sql.
SQL dynamic-array name
The name of a dynamic array of SQL records. The elements are inserted into the database, each at the position specified by the element-specific key values. The operation stops at the first error or when all elements are inserted.

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.

Indexed 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.

MQ record

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:

Relative record

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:

Serial record

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.

SQL record

Some error conditions are as follows:

The result is as follows when you add an SQL record without specifying an explicit SQL statement:

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


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]