DataEvent_record_BeforeUpdateRow

Function called before updating row.

Syntax

PUBLIC FUNCTION dataEvent_record_BeforeUpdateRow(
   p_dataT0 record-type,
   p_dataT1 record-type )
   RETURNS (INTEGER, STRING, record-type, record-type)

The function has two parameters:

  1. p_dataT0. This is a RECORD containing a row of data. It is defined according to the structure of the database table.
  2. p_dataT1. This is a RECORD defined according to the structure of the database table. It contains the data from the form field including those modified by user.
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 is returned with the SQLERRMESSAGE error message.
  3. record-type. This is a RECORD type defined according to the structure of the database table.
  4. record-type. This is a RECORD type defined according to the structure of the database table.

Usage

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

This function is called before updating a row in the database. This event is triggered when the 'update' action is invoked. This happens when a user modifies a field in a row and then presses the 'accept' action or moves to another row. Use this function to check if something has changed, such as a quantity that must not exceed a certain value, or must satisfy a constraint. You can test several fields.

Example: Before Update Row

This example uses the Before Update Row code event for the OrderItem form in the OfficeStore demo.

In this example, the modified value for the line item quantity is checked against the quantity in the inventory table. The function returns an error number and message depending on this result.

PUBLIC FUNCTION dataEvent_OrderItem_BeforeUpdateRow(p_dataT0 RECORD LIKE lineitem.*, 
             p_dataT1 RECORD LIKE lineitem.*)
    RETURNS (INTEGER, STRING, RECORD LIKE lineitem.*, RECORD LIKE lineitem.*)

    DEFINE errNo INTEGER
    DEFINE errMsg STRING
    DEFINE res INTEGER
    
    DISPLAY "dataEvent_OrderItem_BeforeUpdateRow (Row scope) is raised"
    IF (p_dataT0.* != p_dataT1.*) THEN
       SELECT qty INTO res FROM inventory WHERE @itemid=p_dataT1.itemid
       IF SQLCA.SQLCODE=0 THEN 
         IF p_dataT1.quantity > res THEN
            LET errNo = ERROR_FAILURE
            LET errMsg = " - Invalid value - not enough in stock"
         END IF
       END IF  
    END IF
    DISPLAY "dataEvent_OrderItem_BeforeUpdateRow (Row scope) is exited"
   
    RETURN errNo, errMsg, p_dataT0.*, p_dataT1.*
END FUNCTION