BEFORE INSERT block

The BEFORE INSERT block is executed each time the user inserts a new row, before the new row is created and made the current one.

You typically assign default values to the array variables of the newly created row, before the user gets control to enter more values and validates the row creation.

When called in this block, the ARR_CURR() function returns the index of the newly created row. The row in the program array can be referenced with this index, since the new element is already created in the array. The BEFORE ROW block is also executed (just before BEFORE INSERT) when inserting a new row, but the current row index returned by ARR_CURR() is one higher than the actual number of rows in the list (ARR_COUNT()).

If needed, you can cancel the insert operation with the CANCEL INSERT instruction. This control instruction can only be used in a BEFORE INSERT or AFTER INSERT block. When a CANCEL INSERT is performed in BEFORE INSERT, the dialog will execute some control blocks such as AFTER ROW / BEFORE ROW / BEFORE FIELD for the current row, even if no new row was inserted.

In this example, the BEFORE INSERT block sets some default values and displays a message:
INPUT ARRAY p_items WITHOUT DEFAULTS
      FROM s_items.*
   ...
   BEFORE INSERT
     LET r = DIALOG.getCurrentRow("s_items")
     LET p_items[r].item_num = getNewSerial("items")
     LET p_items[r].item_code = "C" || p_items[r].item_num 
     LET p_items[r].item_price = 100.00
     MESSAGE "You are creating a new record..."
 ...