7 Subprograms

Subroutine Subprograms

Subroutine subprograms allow you to repeat a series of operations many times using different values or break a large problem down into a series of smaller ones. A subroutine subprogram performs a specific task. It consists of one or more statements following the SUB statement, which is the first statement in a subroutine subprogram. Syntax for the SUB statement is as follows:

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    SUBEND
Here 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    SUBEND
The 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

Eloquence Language Manual - 19 DEC 2002