Figure 1 shows an example of a simple AS/400 sign-on program written in REXX. Note the basic steps. We parse the input argument (parameters) into the variables well be referring to later in the procedure. The REXX program is then attached to the emulator session with the CONNECT function. The program searches the presentation space to ensure its typing into the sign-on screen. The program types the user ID, tab key, password, and enter key into the presentation space, then searches the new presentation space to verify its displaying the Main Menu panel. Finally, it performs clean up and exits.
A more sophisticated logon program might modify the window title or minimize the window while the program is running, then reset everything prior to exiting. Further validation may also be performed. For example, rather than assuming the cursor is resting in the USER field of the sign-on panel, a program might first type the Home key. The extent to which you can automate basic tasks is really limited only by your imagination and ingenuity.
/* REXX */
/*
LOGO5250.CMD: Sign On to a typical AS/400.
This REXX cmd requires three parms to be passed into it:
1) The session name. If omitted, Session "A" is used.
2) The USERID. If omitted, 'User' is used.
3) The PASSWORD. If Omitted, " Pswd" is used.
To execute this program ensure the target emulator session is
active and open an OS/2 window. Type the command name,
LOGO5250, followed by the parameters representing the session
name, userid, and password. For example, to sign on to the AS/400
represented in emulator session C using the userid CHRIS and
the password CHRISPSWD type the following at the OS/2 prompt:
logo5250 c chris chrispwd
*/
/* Intercept errors and direct them to the QUIT routine to */
/* properly clean-up resources. */
signal on halt name quit
signal on error name quit
signal on syntax name quit
/* Retrieve passed parameters and assign to variables */
parse arg session userid password
/* Substitute defaults for unspecified parameters */
if session = '' then session = 'A' /* Use emulator session 'A' */
if userid = '' then userid = 'User' /* Use userid 'User' */
if password = '' then password = 'Pswd' /* Use password 'Pswd' */
/* Query REXX EHLLAPI support and load if not already present */
/* NOTE: RxFuncQuery will return a 1 if the function is not */
/* already loaded */
if Rxfuncquery('ehllapi') then /* Query Support */
call Rxfuncadd 'EHLLAPI','SAAHLAPI','HLLAPISRV'/* Load support */
/* Connect this REXX program to the specified emulator session */
rc=ehllapi('Connect',session)
if rc0 then do /* Error, exit */
say 'Did not connect to host. RC='rc
signal quit
end
/* Wait for keyboard to be unlocked and ready for input */
/* NOTE: It is necessary to issue the WAIT after EHLLAPI function */
/* calls to ensure previous host operations have completed. */
rc=ehllapi('Wait') /* Wait for for host */
if rc0 then do /* Error, exit */
say 'Host keyboard locked.'
signal quit
end
/* We are now connected to the emulator session. We can search */
/* the presentation space and type data. */
/* We first scan the emulator session for the 'Sign On' prompt. */
/* If we don't find it, we assume the user is already signed on. */
pos=ehllapi('Search_ps','Sign On',1)/* Search screen for 'Sign-On' */
if pos=0 then do /* If not found, exit */
say 'Not at Sign-on screen. Must already be logged on.'
signal quit
end
/* We assume this is a typical Sign On screen: the cursor is */
/* currently resting in the USER input field and a right tab will */
/* move the cursor to the PASSWORD input field. */
/* NOTE: The double bars, ||, is the REXX string concatenation */
/* operator. */
rc=ehllapi('Sendkey', userid||' @T') /* Type USERID and TAB */
rc=ehllapi('Wait') /* Wait for completion */
rc=ehllapi('Sendkey', password||' @E') /* Type PASSWORD and ENTER */
rc=ehllapi('Wait') /* Wait for completion */
/* The emulator session should now be logged on and we can quit, */
/* but we'll first do a search of the new screen to ensure we're */
/* at the main menu. */
pos=ehllapi('Search_ps','Main Menu',1) /* Look for 'Main Menu' */
if pos=0 then say 'Logon failed.' /* Can't find it. */
else say 'Sign-on successful' /* Found it! */
quit:
call ehllapi ('disconnect') /* End the EHLLAPI connection */
call ehllapi ('reset_system') /* EHLLAPI clean-up */
exit
Figure 1: REXX Example Logon Program
LATEST COMMENTS
MC Press Online