Subroutines
A subroutine is a set of instructions that perform a specific task. It is a small program that can be embedded in a program and accessed with a GOSUB statement, or it can be external to the program and accessed with a CALL statement. Common processes are often kept as external subroutines. This lets the programmer access them from many different programs without having to rewrite them.
When a GOSUB statement or CALL statement is encountered, program control branches to the referenced subroutine. An internal subroutine must begin with a statement label. An external subroutine must begin with a SUBROUTINE statement.
A RETURN statement can be used at the end of a subroutine to return program flow to the statement following the last referenced GOSUB or CALL statement. If there is no corresponding CALL or GOSUB statement, the program halts and returns to the InfoSphere® DataStage® command level. If an external subroutine ends before a RETURN statement is encountered, a RETURN is provided automatically.
One or more arguments separated by commas can be passed to the subroutine as an argument list. An argument can be a constant, variable, array variable, or expression, each representing an actual value. The SUBROUTINE statement argument list must contain the same number of arguments so that the subroutine can reference the values being passed to it. Arguments are passed to subroutines by passing a pointer to the argument. Therefore, arguments can also be used to return values to the calling program.