AFTER INSERT block

The AFTER INSERT block is executed each time the user leaves a new created row. This block is typically used to implement SQL command that inserts a new row in the database. You can cancel the operation with the CANCEL INSERT instruction.

When the user appends a new row at the end of the list, then moves UP to another row or validates the dialog, the AFTER INSERT block is only executed if at least one field was edited. If no data entry is detected, the dialog automatically removes the new appended row and thus does not trigger the AFTER INSERT block.

In this example, the AFTER INSERT block inserts a new row in the database and cancels the operation if the SQL command fails:
INPUT ARRAY ...
   ...
   AFTER INSERT s_items 
     LET r = DIALOG.getCurrentRow("s_items")
     INSERT INTO items VALUES ( p_items[r]. * )
     IF SQLCA.SQLCODE < 0 THEN
       ERROR "Could not insert row into database"
       CANCEL INSERT
     END IF
   ...
 END INPUT

When executing a NEXT FIELD in the AFTER INSERT block, the dialog will stay in the current row. You can use this to implement row input validation and prevent the user from leaving the list or moving to another row. However, this will not cancel the row insertion and will not invoke the BEFORE INSERT / AFTER INSERT triggers again. The only way to keep the focus in the current row after the row was inserted is to execute a NEXT FIELD in the AFTER ROW block.