The following table summarizes the events that are triggered during a FILL operation for a temp-table buffer:

Event When it occurs Examples
BEFORE-FILL For each parent temp-table, BEFORE-FILL executes once before the retrieval of the first record of the temp-table. For each child temp-table, BEFORE-FILL executes once after its parent record is retrieved, but before the child records are retrieved.
  • Prepare a query for a parent table inside the FILL event.
  • Cancel a FILL of a child table.
  • Populate the table with data from a non-database source.
  • Attach a data-source.
AFTER-FILL For each parent temp-table, AFTER-FILL executes once after the retrieval of the last record of the temp-table For each child temp-table, AFTER-FILL executes once after all child records for a parent are retrieved.
  • Reject the FILL operation (Note: To abort a FILL operation you return error from the event handling procedure).
  • Detach a data-source.
  • Perform field calculations in the parent or perform other changes to data values.
BEFORE-ROW-FILL BEFORE-ROW-FILL fires prior to the retrieval of each row during the population of the specified temp-table.
  • Decide whether or not to create a record.
AFTER-ROW-FILL AFTER-ROW-FILL fires after the retrieval of each row during the population of the specified temp-table.
  • Calculate field values.
  • Reject a row by deleting it.

BEFORE-FILL on a temp-table buffer

In this example, a BEFORE-FILL event handler for the ttOrder parent temp-table buffer is used to attach data-sources to the dataset.

PROCEDURE preOrderFill:
  DEFINE INPUT PARAMETER DATASET FOR dsOrderOrderLine.
  BUFFER ttOrder:ATTACH-DATA-SOURCE(DATA-SOURCE srcOrder:HANDLE).
  BUFFER ttOrderLine:ATTACH-DATA-SOURCE(DATA-SOURCE srcOline:HANDLE).
END PROCEDURE. /* preOrderFill */ 
Note: If you want to pre-populate the temp-table from a non-database source (such as JSON, flat file, or spreadsheet) use the BEFORE-FILL event to execute code that populates the temp-table programmatically.

AFTER-FILL on a temp-table buffer

In this example, an AFTER-FILL event handler for the ttOrderLine temp-table buffer updates ttOrder.OrderTotal after all of the ttOrderLine records for the current ttOrder are added to the dataset.

PROCEDURE postOlineFill:
  DEFINE INPUT PARAMETER DATASET FOR dsOrderOrderLine.
  DEFINE VARIABLE dTotal AS DECIMAL NO-UNDO.
  FOR EACH ttOrderLine WHERE ttOrderLine.OrderNum = ttOrder.OrderNum:
    dTotal = dTotal + ttOrderLine.ExtendedPrice.
  END.
 ttOrder.OrderTotal = dTotal.
END PROCEDURE. /* postRecordFill */

BEFORE-ROW-FILL on a temp-table buffer

In this example, a BEFORE-ROW-FILL event handler for the ttOrderLine temp-table buffer is used to filter child records as they are populated during the FILL process.

PROCEDURE preOrderLineRowFill:
  DEFINE INPUT PARAMETER DATASET FOR dsOrderOrderLine.
  IF OrderLine.Discount > 10 THEN 
    RETURN NO-APPLY.
END PROCEDURE. 

AFTER-ROW-FILL on a temp-table buffer

In this example, after each ttItem row is populated, an AFTER-ROW-FILL event handler for the ttItem temp-table buffer is used to capitalize the ItemName field in the record buffer.

PROCEDURE postItemRowFill:
  DEFINE INPUT PARAMETER DATASET FOR dsOrderOrderLine.
  ASSIGN ttItem.ItemName = CAPS(ttItem.ItemName).
END PROCEDURE. 

See also

FILL events

Define FILL events