Sample Script
The sample script takes a file, and sends it to the same remote system for ten times. Each time the remote file name is concatenated with a counter to make the names different. If the request fails, a message is displayed on the z/OS console, and the script asks the operator whether to continue. After 10 transfer requests, the script terminates.
SET %COUNT = 0 SET %FAIL = 0 SET %GOOD = 0 Sample
:SENDLOOP SET %LF = "TEST.FILE" SET %RF = "TEST.FILE" + %COUNT SET %IPADDR = "127.0.0.1" SET %IPPORT = 46464 CALL SENDTEXT * IF %RC = 0 THEN SET %GOOD = %GOOD + 1 GOTO CONTINUE ELSE NOOP ENDIF CALLPGM TESTPGM %RC %LF %RF SET %FAIL = %FAIL + 1 SET %WTORLENGTH = 1 *
The :SENDLOOP statement defines a routine name, SENDLOOP.
The second statement sets the character variable %LF.
The statement SET %RF = "TEST.FILE" + %COUNT sets the character variable %RF to the contents of the character variable %LF concatenated with a numeric variable. The first time this statement is executed, the variable %RF is assigned the value "TEST.FILE0". The second time this routine is executed (when %COUNT = 1), the variable %RF is assigned the value "TEST.FILE1".
The following two statements set the character variables %IPADDR and %IPPORT.
The CALL SENDTEXT statement passes control to routine SENDTEXT.
The IF statement checks the current return code (%RC). If the current return code is zero, the variable %GOOD is incremented by 1, and the execution is transferred to routine CONTINUE. If the return code is not zero, the execution is transferred to the statement following ENDIF.
The CALLPGM statement defines the script program to call the TESTPGM program which passes three parameters. When the TESTPGM program is completed, the variable %RC is updated with the return code set by TESTPGM.
The next statement increments the variable %FAIL by 1.
The last statement sets the reserved variable %WTORLENGTH to 1. This sets the maximum length of the data that an operator can respond to a WTOR request to 1.
:WTORMSG WTOR "ERROR SENDING FILE %RF REPLY Y=CONTINUE X=CANCEL" SAY WTORLENGTH=%WTORLENGTH WTORDATA=%WTORDATA * IF %WTORDATA = "X" THEN EXIT ENDIF IF %WTORDATA = "Y" THEN GOTO CONTINUE ENDIF GOTO WTORMSG *
The :WTORMSG statement defines a routine name, WTORMSG.
The WTOR function issues a z/OS WTOR request. It displays a message on the z/OS console, and waits for an operator reply. Because the %WTORLENGTH field is set to 1, the reply can be a maximum of 1 byte long. The variable %WTORLENGTH returns the length of the data actually entered by the operator, while the variable %WTORDATA returns the data entered by the operator.
The SAY function displays the contents of the variables %WTORLENGTH and %WTORDATA.
The first IF function checks whether the operator responded to the WTOR function with the character X. If so, the script terminates because of the EXIT call. Because no parameter is specified by the EXIT call, the variable %MAXRC sets the termination return code. No ELSE function is specified because the IF function is terminated by the ENDIF function before an ELSE function is encountered.
The second IF function checks whether the operator responded to the WTOR function with the character Y. If so, the control is passed to the routine labeled CONTINUE. No ELSE function is specified because the IF function is terminated by the ENDIF function before an ELSE function is encountered.
The last function transfers control to the routine labeled WTORMSG. In this case, the routine is looping until the operator enters either Y or X in response to the WTOR function.
:CONTINUE SET %COUNT = %COUNT + 1 IF %COUNT >= 10 THEN GOTO DONE ENDIF * WAITSECS 2 GOTO SENDLOOP *
The :CONTINUE statement defines a routine name, CONTINUE.
The first SET statement increments the variable %COUNT by 1.
The IF statement checks whether the variable %COUNT is greater than or equal to 10. If the condition is true (%COUNT is greater than or equal to 10), control is passed to routine DONE. If the condition is not true, control is passed to the statement following the ENDIF statement.
The WAITSECS function causes the script to go into a wait for 2 seconds.
The GOTO statement causes execution to pass to routine SENDLOOP.
:DONE SAY GOOD COUNT=%GOOD SAY FAIL COUNT=%FAIL EXIT *
The :DONE statement defines a routine name, DONE.
The first SAY statement displays a message containing the variable %GOOD.
The second SAY statement displays a message containing the variable %FAIL.
The EXIT statement causes termination of the script. Because no parameter is supplied with the exit, the variable %MAXRC supplies the script return code.
:SENDTEXT * PROCESS SEND FILE REQUEST PROCESS,SENDB,TRANSFER,SEND DSN=%LF REMOTE_FILE=%RF RUSER=*PROFILE TYPE=TEXT WAIT=YES EFFECT=R TRY=1 IPADDR=%IPADDR IPPORT=%IPPORT WTO "RETURN CALL FROM SENDTEXT=%RC." RETURN
The :SENDTEXT statement defines a routine name, SENDTEXT.
The PROCESS statement and all statements up to and including IPPORT are input into the platform server Batch interface program. These statements cause a TEXT SEND request to be initiated to the system defined by the IPADDR parameter. The EFFECT=R statement indicates replacing the file if the file already exists. If the file does not exist, an error is generated. When the file transfer is completed, the variable %RC is updated with the return code set by the Batch interface program. Control is then passed to the statement following the last PROCESS parameter. The WAIT=YES statement indicates that control should not be passed back to the script until the transfer has been completed either successfully or unsuccessfully.
The WTO function displays a message on the operator console. In this case, it displays a message with the variable %RC. The return code for the PROCESS request is substituted for the variable %RC in the WTO message.
The RETURN statement passes control to the statement following the statement that issued the CALL function to this routine.