RAMP-TSAD03 Step 6. Dynamic Handler Association
In the preceding steps you learnt how to permanently define a special field handler via RAMP Tools.
You can also dynamically define, modify and delete special handlers in your RAMP scripts. Typically this is done in your logon screen script so that it happens just once. However, this feature may be used in individual screen scripts for specialized purposes.
To dynamically define or redefine a special field handler use the SET_SPECIAL_FIELD_HANDLER() function. To dynamically remove a special field handler use DROP_SPECIAL_FIELD_HANDLER();
Note that dynamically removing a handler will not impact it if is currently displayed. It will just prevent it from being displayed again.
1. Start RAMP Tools and locate the script for the DisplayEmployee screen.
2. In the vHandle_ARRIVE function for the screen dynamically attach a new handler to the utxtDepartment field like this:
SET_SPECIAL_FIELD_HANDLER("utxtDepartment",KeyEnter,"DF_PRM06"); /* Attach an Enter Key handler */
Your code will look like this:
The DF_PRM06 handler will be invoked when the Enter key is pressed.
3. Commit the changes and do a partial save of the RAMP definition
4. Display the details of an employee in the Personnel application to show the screen with the modified script.
5. Press F4 on the Department Code field to cause the DF_PRM04 handler to be invoked from the field.
6. Press Enter on the Department Code field to cause the DF_PRM06 handler to be invoked from the field:
Note that his means you can attach multiple handlers to the same field, differentiated by the function key used.
7. Next drop the F4 handler associated with the field by adding this code to the vHandle_ARRIVE function:
DROP_SPECIAL_FIELD_HANDLER("utxtDepartment",KeyF4); /* Drop the F4 handler */
Your code will look like this:
8. Try this by selecting another employee from the list, and confirm that F4 on the Department Code field no longer brings up the DF_PRM04 special command handler (it shows the 5250 prompter instead).
9. Confirm that you can use Enter to activate the DF_PRM06 handler.
Remember that it is unusual (ie: specialized) to do this in a destination arrival script. Most dynamic attachment is done just once, in the logon script, and it persists for the entire session.