You have already seen cases where a procedure causes an event to fire “artificially” by using the APPLY statement. In the CustOrders procedure, each button trigger has to APPLY the VALUE-CHANGED event to the Order browse to get it to run the internal procedure to display related data for the Order, such as this code for the Next button trigger:

DO:
  GET NEXT CustQuery.
  IF AVAILABLE Customer THEN
  DO:
    DISPLAY {&FIELDS-IN-QUERY-CustQuery}
      WITH FRAME CustQuery IN WINDOW CustWin.
    {&OPEN-BROWSERS-IN-QUERY-CustQuery}
    APPLY "VALUE-CHANGED" TO OrderBrowse.
  END.
END.

The APPLY statement causes whatever trigger is currently active for the event and object to fire. Unlike the ON statement, you must place the name of the event in quotation marks in an APPLY statement, if it is a literal value. This makes it possible to APPLY the value of a character variable instead. In this way, you can define a CHARACTER variable, assign it a value of an event name during program execution, and then use that value in an APPLY statement, adding flexibility to your programming. For example:

DEFINE VARIABLE cEvent AS CHARACTER NO-UNDO.
.
.
.
cEvent = “VALUE-CHANGED”.
.
.
.
APPLY cEvent TO <some object>.

By contrast, ABL must know the event for an ON statement at compile time to prepare the trigger properly. For this reason the event name cannot be a variable, so you can specify it with or without quotation marks in the ON statement.

DEFINE VARIABLE cFillFrom AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFillTo AS CHARACTER NO-UNDO.

ENABLE cFillFrom cFillto WITH FRAME fFrame.

ON ANY-PRINTABLE OF cFillFrom
  APPLY LAST-KEY TO cFillto.

WAIT-FOR CLOSE OF THIS-PROCEDURE.

The LAST-KEY keyword is a built-in function that returns the value of the last keystroke the user pressed. Every time you enter a letter into the first fill-in field, cFillFrom, the ANY-PRINTABLE trigger fires which, as its name suggests, responds to any printable character typed on the keyboard, and this trigger retrieves that keystroke and applies it to the other fill-in field, cFillTo. So you can apply not just the standard events but even keyboard characters to an object like a fill-in field, if is enabled for input.

This figure shows the effect of typing Text into cFillFrom.

Figure 1. Result of typing into cFillFrom