Try OpenEdge Now
skip to main content
Programming Interfaces
Input/Output Processes : Handling User Input : Telling the AVM how to continue processing
 

Telling the AVM how to continue processing

When you modify a field or variable, pressing GO tells the AVM to accept the data in all the modified fields and variables in the current statement and to go on to the next statement in the procedure.
As the following figure shows, if you press GO while the cursor is in the name, creditlimit, or salesrep fields, the AVM continues on to the next statement in the procedure, which is END. The procedure then returns to the beginning of the FOR EACH loop.
i-intro.p
You might want to define function keys that tell the AVM to continue processing data a certain way. You can use the GO–ON phrase with the SET or UPDATE statement to do this, as shown in the i-gon1.p procedure.
i-gon1.p
DISPLAY "You may update each customer." SKIP
  "After making your changes, press one of:" SKIP(1)
  KBLABEL("GO") + " - Make the change permanent" FORMAT "x(40)" SKIP
  KBLABEL("END-ERROR") + " - Undo changes and exit" FORMAT "x(40)" SKIP
  "F8 - Undo changes and try again" SKIP
  "F10 - Find next customer" SKIP
  "F12 - Find previous customer"
  WITH CENTERED FRAME ins.

FIND FIRST Customer EXCLUSIVE-LOCK.

upd-loop:
REPEAT:
  UPDATE Customer.CustNum Customer.Name Customer.Address Customer.Address2
    Customer.City Customer.State
    GO-ON(F8 F10 F12) WITH 1 DOWN CENTERED.

  CASE LASTKEY:
    WHEN KEYCODE("F8") THEN
      UNDO upd-loop, RETRY upd-loop.
    WHEN KEYCODE("F10") THEN
      FIND NEXT customer.
    WHEN KEYCODE("F12") THEN
      FIND PREV customer.
  END CASE.
END.
In this example, if the user presses F8, F10, or F12 while updating the customer data, the procedure immediately goes on to the next statement in the procedure. Let's take a closer look at this procedure.
Any key you can press while running an ABL procedure has a code, a function, and a label associated with it. The code of a key is an integer value that the AVM uses to identify that key. For example, the code of F1 is 301. The function of a key is the work that the AVM does when you press the key. For example, the function of the F1 key may be HELP. The label of a key is the actual label that appears on the keyboard key. The label of the F1 key is F1.
As shown earlier, you can use the KEYLABEL, KEYCODE, KEYFUNCTION, and KBLABEL functions to convert key labels, key codes, and key functions. In addition to these functions, the LASTKEY function returns the key code of the last key pressed.
You can use the functions described in this table to monitor the keys being pressed, as in the i-keys.p procedure.
i-keys.p
REPEAT:
  DISPLAY "Press any key".
  READKEY.
  DISPLAY
    LASTKEY LABEL "Key Code"
    KEYLABEL(LASTKEY) LABEL "Key Label"
    KEYFUNCTION(LASTKEY) LABEL "Key Function" FORMAT "x(12)".
  IF KEYFUNCTION(LASTKEY) = "end-error" THEN LEAVE.
END.
Run procedure i-keys.p to see how the different keys you press translate into key codes, key labels, and key functions.
Now, run the i-gon1.p procedure. A screen similar to the one shown in the following figure appears.
Figure 22. The i-gon1.p procedure
While updating the customer information, press F9, F10, F11, or use either of the standard techniques to signal the end of data entry, the AVM goes on to the next statement in the procedure. If you press any other key, the AVM does not continue on to the next statement in the procedure, but instead performs the data entry operation associated with that key. If you press END-ERROR, the AVM performs the default ENDKEY processing of UNDO, LEAVE.
If the AVM does continue on to the next statement in the procedure, the CASE statement determines the action to take by checking the value of the last key pressed.
The procedure i-gon2.p shows how you can achieve the same functionality in an event-driven application.
i-gon2.p
FORM
  Customer.CustNum Customer.Name Customer.Address Customer.Address2
  Customer.City Customer.State
  WITH CENTERED FRAME upd-frame.

DISPLAY "You may update each customer." SKIP
  "After making your changes, press one of:" SKIP(1)
  KBLABEL("GO") + " - Make the change permanent" FORMAT "x(40)" SKIP
  KBLABEL("END-ERROR") + " - Undo changes and exit" FORMAT "x(40)" SKIP
  "F8 - Undo changes and try again" SKIP
  "F10 - Find next customer" SKIP
  "F12 - Find previous customer"
  WITH CENTERED FRAME ins.

ON F8 ANYWHERE DO:
  DISPLAY Customer.CustNum Customer.Name Customer.Address Customer.City
    Customer.State
    WITH CENTERED FRAME upd-frame.
END.

ON F10 ANYWHERE DO:
  APPLY "GO" TO FRAME upd-frame.
  FIND NEXT Customer.
  DISPLAY Customer.CustNum Customer.Name Customer.Address Customer.Address2
    Customer.City Customer.State
    WITH CENTERED FRAME upd-frame.
END.

ON F12 ANYWHERE DO:
  APPLY "GO" TO FRAME upd-frame.
  FIND PREV Customer.
  DISPLAY Customer.CustNum Customer.Name Customer.Address Customer.Address2
    Customer.City Customer.State
    WITH CENTERED FRAME upd-frame.
END.

ON GO OF FRAME upd-frame
  ASSIGN FRAME upd-frame Customer.CustNum Customer.Name Customer.Address
    Customer.Address2 Customer.City Customer.State.

ENABLE ALL WITH FRAME upd-frame.
FIND FIRST customer.
APPLY "F8" TO FRAME upd-frame.

WAIT-FOR END-ERROR OF FRAME upd-frame.
Use the ANYWHERE option of the ON statement to set up triggers that execute no matter which widget has input focus. In i-gon2.p, the ANYWHERE option is used to assign triggers to function keys.
Note: In a larger program, you must be careful of the scope of the ANYWHERE trigger.