Printing Mailing Labels

This chapter provides overviews of mailing label printing and the sample program for printing mailing labels and discusses how to:

Click to jump to parent topicUnderstanding Mailing Label Printing

An SQR select paragraph retrieves the addresses and prints them on the page.

Sometimes you need to print labels in multiple columns. The page then becomes a matrix of rows and columns of labels. SQR enables you to print in column format with the COLUMNS and NEXT-COLUMN commands in conjunction with NEXT-LISTING.

Click to jump to parent topicUnderstanding the Sample Program for Printing Mailing Labels

The following sample program prints mailing labels in a format of 3 columns by 10 rows. It also counts the number of labels that are printed and prints that number on the last sheet of the report.

Program ex9a.sqr #define MAX_LABEL_LINES 10 #define LINES_BETWEEN_LABELS 3 begin-setup declare-layout default paper-size=(10,11) left-margin=0.33 end-declare end-setup begin-program do mailing_labels end-program begin-procedure mailing_labels let #label_count = 0 let #label_lines = 0 columns 1 29 57 ! enable columns alter-printer font=5 point-size=10 begin-select name (1,1,30) addr1 (2,1,30) city state zip move &zip to $zip XXXXX-XXXX let $last_line = &city || ', ' || &state || ' ' || $zip print $last_line (3,1,30) next-column at-end=newline add 1 to #label_count if #current-column = 1 add 1 to #label_lines if #label_lines = {MAX_LABEL_LINES} new-page let #label_lines = 0 else next-listing no-advance skiplines={LINES_BETWEEN_LABELS} end-if end-if from customers end-select use-column 0 ! disable columns new-page print 'Labels printed on ' (,1) print $current-date () print 'Total labels printed = ' (+1,1) print #label_count () edit 9,999,999 end-procedure ! mailing_labels

Click to jump to parent topicDefining Columns and Rows

The COLUMNS 1 29 57 command defines the starting position for three columns. The first column starts at character position 1, the second at character position 29, and the third at character position 57.

The ex9a.sqr program writes the first address into the first column, the second address into the second, and the third address into the third. The fourth address is written into the second row of the first column, following the first label. When ten lines of labels are complete, a new page starts. After the last page of labels has been printed, the program prints a summary page showing the number of labels that have been printed.

Note the technique for composing the last line of the label. The city, state, and zip columns are moved to string variables. The command LET $last_line = &city || ', ' || &state || ' ' || $zip combines the city, state, and zip code, plus appropriate punctuation and spacing, into a string, which it stores in the $last_line variable. In this way, city, state, and zip code are printed without unnecessary gaps.

The program defines two counters: #label_count and #label_lines. The first counter, #label_count, counts the total number of labels and prints it on the summary page. The second counter, #label_lines, counts the number of rows of labels that were printed. When the program has printed the number of lines that are defined by {MAX_LABEL_LINES}, it starts a new page and resets the #label_lines counter.

After each row of labels, the NEXT-LISTING command redefines the print position for the next row of labels as line 1. NEXT-LISTING skips the specified number of lines (SKIPLINES) from the last line that was printed (NO-ADVANCE) and sets the new position as line 1.

Note the use of the ALTER-PRINTER command. This command changes the font in which the report is printed.

The sample program prints the labels in 10-point Times Roman, which is a proportionally spaced font. In Microsoft Windows, you can use proportionally spaced fonts with any printer that supports fonts or graphics. On other platforms, SQR directly supports HP LaserJet printers and PostScript printers.

In the sample program, the DECLARE-LAYOUT command defines a page width of 10 inches. This width accommodates the printing of the third column, which contains 30 characters and begins at character position 57. SQR assumes a default character grid of 10 characters per inch, which would cause the third column to print beyond the paper edge if this report used the default font. The 10-point Times Roman that is used here, however, condenses the text so that it fits on the page. The page width is set at 10 inches to prevent SQR from treating the third-column print position as an error.

See Changing Fonts, Printing with SQR.

Click to jump to parent topicRunning the Print Mailing Labels Program

When you print with a proportionally spaced font, you must use a slightly different technique for running the program and viewing the output. If you are using a platform such as UNIX/Linux, specify the printer type with the -PRINTER:xx flag. If you are using an HP LaserJet, enter -PRINTER:HP (or -printer:hp). If you are using a PostScript printer, enter -PRINTER:PS (or -printer:ps) on the command line.

For example:

sqr ex9a ​username/password ​-printer:hp

You can also use the -KEEP command-line flag to produce output in the SQR Portable File format (SPF) and print it by using SQR Print. You still need to use the -PRINTER:xx flag when printing.

See Printing with SQR.

The report produces the output in three columns corresponding to the dimensions of a sheet of mailing label stock. In the preceding example, the report prints the labels from left to right, filling each row of labels before moving down the page.

You can also print the labels from the top down, filling each column before moving to the next column of labels. The code to do this is shown next. The differences between this code and the previous one are shown like this. The output is not printed here, but you can run the file and view it by using the same procedure that you used for the previous example.

Program ex9b.sqr #define MAX_LABEL_LINES 10 #define LINES_BETWEEN_LABELS 3 begin-setup declare-layout default paper-size=(10,11) left-margin=0.33 end-declare end-setup begin-program do mailing_labels end-program begin-procedure mailing_labels let #Label_Count = 0 let #Label_Lines = 0 columns 1 29 57 ! enable columns alter-printer font=5 point-size=10 begin-select name ​(0,1,30) ​addr1 ​(+1,1,30) ​city state zip move &zip to $zip xxxxx-xxxx let $last_line = &city || ', ' || &state || ' ' || $zip ​print $last_line (+1,1,30)add 1 to #label_count add 1 to #label_lines if #label_lines = {MAX_LABEL_LINES} next-column goto-top=1 at-end=newpage let #label_lines = 0 else position (+1) position (+{LINES_BETWEEN_LABELS}) end-if from customers end-select use-column 0 ! disable columns new-page print 'Labels printed on ' (,1) print $current-date () print 'Total labels printed = ' (+1,1) print #label_count () edit 9,999,999 end-procedure ! mailing_labels