7 Subprograms
SUB subprogram name [(formal parameter list)]
The subprogram name must be a valid name.
The last line in a subroutine subprogram should be:
SUBEND
This returns control back to the calling program segment.
The subroutine subprogram is accessed and values supplied by the CALL statement. Syntax for this statement is as follows:
CALL subprogram name [(pass parameter list)]
Here is a simple example of a subroutine subprogram used to write a heading for data output:
10 CALL Header . . . 200 END 210 SUB Header 220 PRINT TAB(11),"NAME",TAB(30),"CURRENT SALARY" 230 SUBENDHere is a more complex example which outputs a readable table when values are supplied:
10 CALL Table(Dept,Total,C(*),Super$) . . . 40 END 50 SUB Table(Dept,Total,C(*),Super$) 60 PRINT "DEPARTMENT NUMBER:";Dept,"SUPERVISOR:";Super$,LIN(2) 70 PRINT "PRODUCT NUMBER","% OF TOTAL SALES",LIN(2) 80 FOR I=1 TO 60 90 PRINT SPA(5);C(1,I),SPA(10);C(2,I)/Total 100 NEXT I 110 SUBENDThe SUBEXIT statement is used to transfer control back to the calling program segment before SUBEND is executed.
For example:
120 SUB Pay(X,Y) . . . 160 IF XY THEN SUBEXIT . . . 200 SUBEND