SUBsubprograms must follow the MAIN program'sENDstatement. The first line must be aSUBstatement and the last line aSUBENDstatement. The lines betweenSUBandSUBENDstatements define a subprogram which can be called by other parts of the program with theCALLstatement.
Unless theOPTIONALkeyword is specified, the number ofCALLarguments must match the number ofSUBparameters; each argument must be of the same type (numeric or string) as the corresponding parameter. Any parameters to the right of theOPTIONALkeyword are optional in theCALLstatement.NPARreturns the number of arguments in the currentCALLstatement. All variables defined in a subprogram that are notCOMvariables are local to the subprogram. Upon each entry to the subprogram they are set to zero.
ACALLto a subprogram, transfers control to the first statement of that subprogram and starts executing from there. Execution proceeds normally until either aSUBENDorSUBEXITstatement is executed, at which point control returns to the statement after theCALL. TheSUBEXITstatement allows a return from the subprogram at points other than theSUBEND. MultipleSUBEXITs are allowed in a subprogram.SUBEXITmay appear in anIFstatement,SUBENDcan not.