|Navigation: Language Reference > 2 - Program Source Code Format > Program Format >====== ROUTINE (declare local subroutine) ======|
|ROUTINE||Declares the beginning of a local subroutine.|
|label||The name of the ROUTINE. This may not duplicate the label of any PROCEDURE.|
|DATA||Begin data declaration statements.|
|local data||Declare Local data visible only in this routine.|
|CODE||Begin executable statements.|
|statements||Executable program instructions.|
ROUTINE declares the beginning of a local subroutine. It is local to the PROCEDURE in which it is written and must be at the end of the CODE section of the PROCEDURE to which it belongs. All variables visible to the PROCEDURE are available in the ROUTINE. This includes all Procedure Local, Module Local, and Global data.
In Clarion#, the DATA and CODE keywords are required.
A ROUTINE may contain its own local data which is limited in scope to the ROUTINE in which it is declared. If local data declarations are included in the ROUTINE, they must be preceded by a DATA statement and followed by a CODE statement. Since the ROUTINE has its own name scope, the labels of these variables may duplicate variable names used in other ROUTINEs or even the procedure containing the ROUTINE.
A ROUTINE is called by the DO statement followed by the label of the ROUTINE. Program control following execution of a ROUTINE is returned to the statement following the calling DO statement. A ROUTINE is terminated by the end of the source module, or by another ROUTINE or PROCEDURE. The EXIT statement can also be used to terminate execution of a ROUTINE's code (similar to RETURN in a PROCEDURE).
A ROUTINE has some efficiency issues that are not obvious:
·DO and EXIT statements are very efficient.
·Accessing procedure-level local data is less efficient than accessing module-level or global data.
·Implicit variables used only within the ROUTINE are less efficient than using local variables.
·Each RETURN statement within a ROUTINE incurs a 40-byte overhead.
DO Tally !Call the routine
!More code statements
Tally ROUTINE !Begin routine, end procedure
CountVar BYTE !Declare local variable
CountVar += 1 ! increment counter
DO CountItAgain !Call another routine
EXIT !and exit the routine