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 DL/I processing, see DLISegment record. For details on SQL processing, see SQL record.
The add statement generates a DL/I ISRT statement. In DL/I, this insert takes place at the current position in the database—wherever that might be. You may control this positioning by, for example, explicitly setting keys in your EGL program (as shown in the example below), by using a set record position statement, by using a get statement, or by creating qualified SSAs through the #dli directive.
//create instances of the records myCustomer CustomerRecord; myLocation LocationRecord; myOrder OrderRecord; //build a segment search argument myCustomer.customerNo = "005001"; myLocation.locationNo = "000022"; //fill the fields in the order record fillOrder(myOrder); //add the new order record try add myOrder; onException myErrorHandler(2); endThis add statement will generate the following pseudo-DL/I code:
ISRT STSCCST (STQCCNO = :myCustomer.customerNo) STSCLOC (STQCLNO = :myLocation.locationNo) STPCORDQualified segment search arguments (SSAs) for customer and location identify the parent segments for the new order segment. DL/I will add the new order segment in a position determined by the keyItem field for that segment, the orderDateNo (STQCODN).
if (myOrder is unique) ... endPossible runtime errors include the following:
add myCustomer, myLocation, myOrder;EGL will generate the following pseudo-DL/I code from this statement:
ISRT STSCCST*D (STQCCNO = :myCust.customerNo) STSCLOC (STQCLNO = :myLocation.locationNo) STPCORD
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 an MQ record, the record is placed at the end of the queue. This placement occurs because the add statement 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.
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.
On CICS® for z/OS®, a single program cannot include a combination of add and get next statements for the same spool file. This restriction also applies when the add and get next statements are in different programs, and one program calls the other. Similarly, an add that follows a get or get next statement will add a record to the beginning of the file.
For IMS™ BMP or z/OS batch, if you add a variable-length serial record to a file associated with GSAM and the record length is longer than the physical file, DL/I returns a blank status code. Data is truncated, but no message is issued because the situation cannot be detected.
For IMS/VS, you must associate a serial record with an alternate PCB (a TP PCB in the PSB). The IMS message header (length, ZZ field, and transaction code) is automatically added to each record written to the message queue. An EGL add statement for a serial record assigned to a message queue results in an ISRT call to the message queue. If an error occurs and the record is assigned to a multiple segment message queue and associated with the express alternate PCB, any records already added are committed, even if an explicit close statement has not occurred. If it is important that these records are not committed, include an additional express alternate PCB in the PSB and associate the file with the additional express alternate PCB.
INSERT INTO tableName (column01, ... columnNN) values (:recordItem01, ... :recordItemNN)
try add employees; onException sysLib.rollback(); end
Related concepts
DL/I database support
References to parts
Record types and properties
SQL support
Related tasks
Syntax diagram for EGL statements and commands
Related reference#dli directive
CICS-related considerations
close
delete
get
get next
get next inParent
get previous
Exception handling
execute
I/O error values
open
prepare
EGL statements
replace
set
SQL item properties