Creating Form Letters

This chapter provides an overview of the document paragraph and the sample program for form letters.

Click to jump to parent topicUnderstanding the DOCUMENT Paragraph

To create form letters, use a document paragraph. It starts with a BEGIN-DOCUMENT command and ends with an END-DOCUMENT command. Between these commands, lay out the letter and insert variables where you want data from the database to be inserted. SQR inserts the value of the variable when the document prints. To leave blank lines in a letter, you must explicitly mark them with .b (see the sample program).

Document markers provide another way to add data to the letter. They are special variables whose names begin with the @ sign. They mark a location in the document where you place data from areas external to the document paragraph. Document markers defined in document paragraphs can be referenced in the POSITION command outside the document paragraph to establish the next printing position.

The sample program demonstrates the use of variables and document markers. SQR prints the contents of the variable in the position where it is placed in the document paragraph. For example, in the sample program, the customer’s name is printed on the first line.

Using a document marker gives you more flexibility in positioning the contents of variables. The sample program uses a document marker to position the city, state, and zip code because the city name varies in length and thus affects the position of the state name and zip code.

Click to jump to parent topicUnderstanding the Sample Program for Form Letters

The following simple form letter program, ex10a.sqr, demonstrates the use of document markers:

Program ex10a.sqr begin-program do main end-program begin-procedure main begin-select name addr1 addr2 city state zip do write_letter from customers order by name end-select end-procedure ! main begin-procedure write_letter begin-document (1,1) &name &addr1 &addr2 @city_state_zip .b .b $current-date Dear Sir or Madam: .b Thank you for your recent purchases from ACME Inc. We would like to tell you about our limited-time offer. During this month, our entire inventory is marked down by 25%. Yes, you can buy your favorite merchandise and save too. To place an order simply dial 800-555-ACME. Delivery is free too, so don't wait. .b .b Sincerely, Clark Axelotle ACME Inc. end-document position () @city_state_zip print &city () print ', ' () print &state () print ' ' () print &zip () edit xxxxx-xxxx new-page end-procedure ! write_letter

First, SQR performs the main procedure and the select paragraph. Next, it performs the write_letter procedure and the document paragraph. The POSITION command sets the position to the appropriate line, which is given by the @city_state_zip marker. The program prints the city, then continues printing the other elements to the current position. The state name and zip code automatically print in the correct positions with appropriate punctuation.

The following is the output for program ex10a.sqr.

John Conway 2837 East Third Street Greenwich Village New York, NY 10002-1001 10-MAY-2004 Dear Sir or Madam: Thank you for your recent purchases from ACME Inc. We would like to tell you about our limited-time offer. During this month, our entire inventory is marked down by 25%. Yes, you can buy your favorite merchandise and save too. To place an order simply dial 800-555-ACME. Delivery is free too, so don't wait. Sincerely, Clark Axelotle ACME Inc.

See Using Graphics.