CANCEL INSERT instruction

Insertion can be canceled, by using the CANCEL INSERT instruction, in the BEFORE INSERT or AFTER INSERT blocks. Using this instruction in a different place will generate a compilation error.

The instructions that appear after CANCEL INSERT will be skipped.

A CANCEL INSERT executed inside a BEFORE INSERT block prevents the new row creation. These tasks are performed:

  1. No new row will be created (the new row is not yet shown to the user).
  2. The BEFORE INSERT block is terminated (further instructions are skipped).
  3. The BEFORE ROW and BEFORE FIELD triggers are executed.
  4. Control goes back to the user.
For example, you can cancel a row insertion if the user is not allowed to create rows:
BEFORE INSERT
   IF user_can_insert() == FALSE THEN
      ERROR "You are not allowed to insert rows."
      CANCEL INSERT
   END IF

A CANCEL INSERT executed inside an AFTER INSERT block removes the newly created row. These tasks are performed:

  1. The newly created row is removed from the list (the row exists now and user has entered data).
  2. The AFTER INSERT block is terminated (further instructions are skipped).
  3. The BEFORE ROW and BEFORE FIELD triggers are executed.
  4. The control goes back to the user.
For example, you can cancel a row insertion if a database error occurs when you try to insert the row into a database table:
AFTER INSERT
   WHENEVER ERROR CONTINUE
   INSERT INTO customer VALUES ( arr[arr_curr()].* )
   WHENEVER ERROR STOP
   IF SQLCA.SQLCODE<>0 THEN
      ERROR SQLERRMESSAGE
      CANCEL INSERT
   END IF

If the CANCEL INSERT is done while on a new row that was appended to the end of the list, the new row will be removed and the previous row will get the focus. If there are no more existing rows, the list loses the focus because no row can be edited. The next time the user clicks in a cell, DIALOG will automatically create a new row.

You can also disable the insert and append actions to prevent the user from performing these actions with:
CALL DIALOG.setActionActive("insert", FALSE)
CALL DIALOG.setActionActive("append", FALSE)