Examples (PRINT SPACE command)
Inserting a Blank Line after the Output for Each Case
PRINT / NAME DEPT82 *
MOHIRED(T30,F2) '/' YRHIRED *
SALARY82 (T35,DOLLAR8).
PRINT SPACE.
EXECUTE.
- Each time that it is executed,
PRINT SPACE
displays one blank line. BecausePRINT SPACE
is not used in aDO IF-END IF
structure,PRINT SPACE
is executed once for each case. In effect, the output is double-spaced.
Using PRINT SPACE Inside a DO IF-END IF Structure
NUMERIC #LINE.
DO IF MOD(#LINE,5) = 0.
PRINT SPACE 2.
END IF.
COMPUTE #LINE=#LINE + 1.
PRINT / NAME DEPT *
MOHIRED 30-31 '/' YRHIRED *
SALARY 35-42(DOLLAR).
EXECUTE.
-
DO IF
specifies thatPRINT SPACE
will be executed ifMOD
(the remainder) of #LINE divided by 5 equals 1. Because #LINE is incremented by 1 for each case,PRINT SPACE
is executed once for every five cases. (See Arithmetic Functions for information on theMOD
function.) -
PRINT SPACE
specifies two blank lines. Cases are displayed in groups of five with two blank lines between each group.
Using an Expression to Specify the Number of Blank Lines
* Printing addresses on labels.
COMPUTE #LINES=0. /*Initiate #LINES to 0
DATA LIST FILE=ADDRESS/RECORD 1-40 (A). /*Read a record
COMPUTE #LINES=#LINES+1. /*Bump counter and print
WRITE OUTFILE=LABELS /RECORD.
DO IF RECORD EQ ' '. /*Blank between addresses
+ PRINT SPACE OUTFILE=LABELS 8 - #LINES. /*Add extra blank #LINES
+ COMPUTE #LINES=0.
END IF.
EXECUTE.
-
PRINT SPACE
uses a complex expression for specifying the number of blank lines to display. The data contain a variable number of input records for each name and address, which must be printed in a fixed number of lines for mailing labels. The goal is to know when the last line for each address has been printed, how many lines have printed, and therefore how many blank records must be printed in order for the next address to fit on the next label. The example assumes that there is already one blank line between each address on input and that you want to print eight lines per label. - The
DATA LIST
command defines the data. Each line of the address is contained in columns 1–40 of the data file and is assigned the variable name RECORD. For the blank line between each address, RECORD is blank. - Variable #LINES is initialized to 0 as a scratch variable and is incremented for
each record that is written. When the program encounters a blank line
(
RECORD EQ ' '
),PRINT SPACE
prints a number of blank lines that is equal to 8 minus the number already printed, and #LINES is then reset to 0. -
OUTFILE
onPRINT SPACE
specifies the same file that is specified byOUTFILE
onWRITE
.