RAMP-TSAD03 Step 2. Being smarter with HANDLE_PROMPT()
Note: This step simply demonstrates a technique. Please do not make this modification in your script.
In the preceding example HANDLE_PROMPT() was executed at the start of every button click.
However, if you know that all prompting on this 5250 screen will be done by using F4, you can make the logic faster and smarter like this:
vHandle_BUTTONCLICK: function(sButton)
{
var bReturn = true;
/* <BUTTONCLICK /> - Do not remove or alter this line */
/* Handle function keys and buttons */
switch (sButton)
{
case KeyF4:
if (!HANDLE_PROMPT()) ALERT_MESSAGE("Position the cursor in a promptable field when using F4");
break;
case KeyEnter:
SENDKEY(KeyEnter);
etc, etc, etc
Here the HANDLE_PROMPT() request has been moved from the start of the button click function to the KeyF4 case statement so that it is only called when F4 is used, because we know that is the only time it is required.
Logic has also been added so that if HANDLE_PROMPT() does not handle the request (note the "!" in front of the function call) then a message box will appear saying "Position the cursor in a promptable field when using F4".
We can do this because we know that F4 is going to be handled exclusively on the client and not by the 5250 RPG program on the server.
This contrasts with default behavior in the preceding step that passed unhandled F4 requests on to the 5250 application to see if it wanted to handle them.