Function called after inserting row.


PUBLIC FUNCTION dataEvent_record_AfterInsertRow( 
   errNo INTEGER, 
   errMsg STRING, 
   uniqueKey record-type)

The function has these parameters:

  1. errNo. This is an SQLCA.SQLCODE error.
  2. errMsg. This is the SQLERRMESSAGE message.
  3. uniqueKey. This is a RECORD type defined in the BAM-generated common file (my_entity_common.4gl). It includes the unique key fields from the schema of the database table.
Returns values:
  1. An integer specifying the SQLCA.SQLCODE error number. Codes are defined as constants in the libdbappSql and libdbappCore files in the libdbapp library. If the code is a negative number, an SQL error has occurred. The errors that are relevant in this function are shown in the table.
    Table 1. SQLCA.SQLCODE
    Description Constant Value
    Success ERROR_SUCCESS 0
    Failure ERROR_FAILURE -1
    Concurrent access failure ERROR_CONCURRENT_ACCESS_FAILURE -2
    Concurrent access not found ERROR_CONCURRENT_ACCESS_NOTFOUND -3
  2. A string with the SQLERRMESSAGE error message.


When you select the After Insert Row property for the creation of the event, a function shell is created. Enter your code in the function.

This function is called after inserting a row in the database. Use this function to perform some operation, typically a SQL operation, on another table. For example, you may need to record details about the inserted row of data in a log table.

Example: Before Insert Row

This example uses the After Insert Row code event for the Account table in the OfficeStore demo.

In the example a row of data referenced by the variable uniqueKey is written to a log table. It is assumed that you have created the log table before saving the row to it.

The log table in the example has the following schema:
  • an "id" field that is auto incremented
  • a "date" timestamp field to record the date and time of the operation
  • a "type" field to record the operation (Update/Insert/Delete)
  • a "data" field to record a copy of all field values from the account table
PUBLIC FUNCTION dataEvent_recAccount_AfterInsertRow(errNo INTEGER, errMsg STRING, 
                uniqueKey recAccount_br_uk_type)

    DEFINE log RECORD LIKE log.*
    DEFINE l_data RECORD LIKE account.*  
    DISPLAY "dataEvent_recAccount_AfterInsertRow (Row scope) is raised"
    SELECT * INTO l_data.* FROM account WHERE @userid = uniqueKey.account_userid

    LET = NULL
    LET = util.Datetime.getCurrentAsUTC()
    LET log.type = C_ACTION_INSERT
    LET = SFMT("id=%1 email= %2 firstname=%3 lastname= %4 acstatus=%5  addr1=%6 addr2= %7
                     city=%8 state=%9 zip=%10 country=%11 phone= %12",uniqueKey.account_userid,, 
                     l_data.firstname, l_data.lastname,l_data.acstatus, l_data.addr1, l_data.addr1, 
           ,l_data.state ,,,      
        INSERT INTO log VALUES (log.*)
        LET errNo = ERROR_FAILURE
        LET errMsg = " - AfterInsertRow failed to insert log ", log.*
    DISPLAY "dataEvent_recAccount_AfterInsertRow (Row scope) is exited"

    RETURN errNo, errMsg