PURPOSE: The ROUTINE statement is used to name a block of statements that can be called from any of the executable sections. A ROUTINE cannot include inter-record functions (MIN, MAX, AVG, STD_DEV). Trigger is synonymous with ROUTINE.
ROUTINE name
name |
can be any string up to 40 characters, containing alphabetic and numeric characters, underscore, and a period; it must begin with an alphabetic character. This is the name that will be used in later statements to call the ROUTINE. |
The routine shown here is used to print mailing labels, three across, on special paper. The routine is used the first time, in the DETAILS section, to print each set of three labels as they accumulate. It must be used again, in the FINAL section, in case the last group of labels consists of only one or two labels.
PROCESS SECTION
ROUTINE PRINT_THREE_LABELS
0 TO CNT
PRINT LINE1:D(1), TAB 27, LINE1:D(2), TAB 54, LINE1:D(3)
PRINT LINE2:D(1), TAB 27, LINE2:D(2), TAB 54, LINE2:D(3)
PRINT LINE3:D(1), TAB 27, LINE3:D(2), TAB 54, LINE3:D(3)
SKIP TO TOP
! CLEAR THE LABEL AREAS TO BLANK
START:5 FOR I = 1 TO 3
"" TO LINE1:D(I), LINE2:D(I), LINE3:D(I)
REPEAT:5
DETAIL SECTION
START
GET FROM LABELS NEXT RECORD HUSH
LEAVE IF @AUX# ‘YES’
INCR CNT
ADDR1 TO LINE1:D (CNT)
ADDR2 TO LINE2:D (CNT)
ADDR3 TO LINE3:D (CNT)
PERFORM PRINT_THREE_LABELS IF CNT=3
REPEAT
FINAL SECTION
PERFORM PRINT_THREE_LABELS IF CNT#0
NOTES: ROUTINE statements can only appear in the PROCESS section of a PM. Each ROUTINE statement is followed by the statements that make up that ROUTINE. The kinds of statements that can be included in a ROUTINE are governed by the section of the PM from which it will be called. However, a ROUTINE is compiled code that exists in the PROCESS section. It is therefore restricted from containing any of the inter-record functions (which generate implicit code in other sections of the PM). The routine is called by the PERFORM statement.
The word TRIGGER has been made synonymous with ROUTINE due to common usage with other software applications. For example, the phrase "EXIT TRIGGER" may be substituted for "EXIT ROUTINE".