SUBR function
Syntax
SUBR (name, [argument [ ,argument ... ] ] )
Description
Use the SUBR function to return the value of an external subroutine. The SUBR function is commonly used in I-descriptors.
name is an expression that evaluates to the name of the subroutine to be executed. This subroutine must be cataloged in either a local catalog or the system catalog, or it must be a record in the same object file as the calling program. If name evaluates to the null value, the SUBR function fails and the program terminates with a run-time error message.
argument is an expression evaluating to a variable name whose value is passed to the subroutine. You can pass up to 254 variables to the subroutine.
Subroutines called by the SUBR function must have a special syntax. The SUBROUTINE statement defining the subroutine must specify a dummy variable as the first parameter. The value of the subroutine is the value of the dummy variable when the subroutine finishes execution. Because the SUBROUTINE statement has this dummy parameter, the SUBR function must specify one argument less than the number of parameters in the SUBROUTINE statement. In other words, the SUBR function does not pass any argument to the subroutine through the first dummy parameter. The first argument passed by the SUBR function is referenced in the subroutine by the second parameter in the SUBROUTINE statement, and so on.
Example
The following example uses the globally cataloged subroutine *TEST:
OPEN "","SUN.MEMBER" TO FILE ELSE STOP "CAN'T OPEN
DD"
EXECUTE "SELECT SUN.MEMBER"
10*
READNEXT KEY ELSE STOP
READ ITEM FROM FILE,KEY ELSE GOTO 10
X=ITEM<7> ;* attribute 7 of file contains year
Z=SUBR("*TEST",X)
PRINT "YEARS=", Z
GOTO 10
This is the subroutine TEST:
SUBROUTINE TEST(RESULT,X)
DATE=OCONV(DATE(),"D2/")
YR=FIELD(DATE,'/',3)
YR='19':YR
RESULT=YR-X
RETURN
This is the program output:
15 records selected to Select List #0
YEARS= 3
YEARS= 5
YEARS= 2
YEARS= 6
YEARS= 1
YEARS= 0
YEARS= 0
YEARS= 1
YEARS= 4
YEARS= 6
YEARS= 1
YEARS= 2
YEARS= 7
YEARS= 1
YEARS= 0