HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
Several variations to the basic report format are discussed in the next
sections.
10.10.1 Printing More Than One Logical Line on a Single Physical Line
When your report has only a few columns, you can print several logical lines on one physical line. If you were to print names and addresses on four-up self-sticking multilabel forms, you would print the form left to right and top to bottom, as shown in Figure 10-20 and Example 10-11. To print four-up self-sticking labels, you must format each logical line with four input records.
However, if the columns must be sorted by column, the task becomes more difficult. The last line at the end of the first column is continued at the top of the second column of the same page, indented to the right, and so forth, as shown in Figure 10-21 and Example 10-12. Example 10-12 defines a table containing all data to appear on the page. It reads the input records, stores the data in the table as it is to appear on the page, prints the contents of the table and then fills spaces. When it reaches the end of file, the remaining entries in the table are automatically blank. You can extend this technique to print any number of logical lines on a single physical line.
Figure 10-20 Printing Labels Four-Up
Example 10-11 Printing Labels Four-Up |
---|
IDENTIFICATION DIVISION. PROGRAM-ID. REP02. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUT-FILE ASSIGN TO "LABELS.DAT". SELECT REPORT-FILE ASSIGN TO "LABELS.REP". DATA DIVISION. FILE SECTION. FD INPUT-FILE. 01 INPUT-RECORD. 02 INPUT-NAME PIC X(20). 02 INPUT-ADDRESS PIC X(15). 02 INPUT-CITY PIC X(10). 02 INPUT-STATE PIC XX. 02 INPUT-ZIP PIC 99999. FD REPORT-FILE. 01 REPORT-RECORD PIC X(132). WORKING-STORAGE SECTION. 01 LABELS-TABLE. 03 NAME-LINE. 05 LINE-1 OCCURS 4 TIMES INDEXED BY INDEX-1. 07 LABEL-NAME PIC X(20). 07 FILLER PIC X(10). 03 ADDRESS-LINE. 05 LINE-2 OCCURS 4 TIMES INDEXED BY INDEX-2. 07 LABEL-ADDRESS PIC X(15). 07 FILLER PIC X(15). 03 CSZ-LINE. 05 LINE-3 OCCURS 4 TIMES INDEXED BY INDEX-3. 07 LABEL-CITY PIC X(10). 07 FILLER PIC XXXX. 07 LABEL-STATE PIC XX. 07 FILLER PIC XXXX. 07 LABEL-ZIP PIC 99999. 07 FILLER PIC XXXXX. 01 END-OF-FILE PIC X. PROCEDURE DIVISION. A000-BEGIN. OPEN INPUT INPUT-FILE OUTPUT REPORT-FILE. MOVE SPACES TO LABELS-TABLE. SET INDEX-1, INDEX-2, INDEX-3 TO 1. PERFORM A100-READ-INPUT UNTIL END-OF-FILE = "Y". A050-WRAP-UP. IF LABEL-NAME(1) IS NOT EQUAL TO SPACES PERFORM A300-PRINT-FOUR-LABELS. A050-END-OF-JOB. CLOSE INPUT-FILE REPORT-FILE. DISPLAY "END OF JOB". STOP RUN. * A100-READ-INPUT. READ INPUT-FILE AT END MOVE "Y" TO END-OF-FILE. IF END-OF-FILE = "Y" NEXT SENTENCE ELSE PERFORM A200-GENERATE-TABLE. * A200-GENERATE-TABLE. MOVE INPUT-NAME TO LABEL-NAME(INDEX-1) MOVE INPUT-ADDRESS TO LABEL-ADDRESS(INDEX-2) MOVE INPUT-CITY TO LABEL-CITY(INDEX-3) MOVE INPUT-STATE TO LABEL-STATE(INDEX-3) MOVE INPUT-ZIP TO LABEL-ZIP(INDEX-3) IF INDEX-1 = 4 PERFORM A300-PRINT-FOUR-LABELS ELSE SET INDEX-1, INDEX-2, INDEX-3 UP BY 1. * A300-PRINT-FOUR-LABELS. WRITE REPORT-RECORD FROM NAME-LINE AFTER ADVANCING 3. WRITE REPORT-RECORD FROM ADDRESS-LINE AFTER ADVANCING 1. WRITE REPORT-RECORD FROM CSZ-LINE AFTER ADVANCING 1. MOVE SPACES TO LABELS-TABLE. SET INDEX-1, INDEX-2, INDEX-3 TO 1. |
Figure 10-21 Printing Labels Four-Up in Sort Order
Example 10-12 Printing Labels Four-Up in Sort Order |
---|
IDENTIFICATION DIVISION. PROGRAM-ID. REP03. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INPUT-FILE ASSIGN TO "LABELS.DAT". SELECT REPORT-FILE ASSIGN TO "LABELS.REP". DATA DIVISION. FILE SECTION. FD INPUT-FILE. 01 INPUT-RECORD. 02 INPUT-NAME PIC X(20). 02 INPUT-ADDRESS PIC X(15). 02 INPUT-CITY PIC X(10). 02 INPUT-STATE PIC XX. 02 INPUT-ZIP PIC 99999. FD REPORT-FILE. 01 REPORT-RECORD PIC X(132). WORKING-STORAGE SECTION. 01 LABELS-TABLE. 03 FOUR-UP OCCURS 6 TIMES INDEXED BY ROW-INDEX. 04 NAME-LINE. 05 LINE-1 OCCURS 4 TIMES INDEXED BY NAME-INDEX. 07 LABEL-NAME PIC X(20). 07 FILLER PIC X(10). 04 ADDRESS-LINE. 05 LINE-2 OCCURS 4 TIMES INDEXED BY ADDRESS-INDEX. 07 LABEL-ADDRESS PIC X(15). 07 FILLER PIC X(15). 04 CSZ-LINE. 05 LINE-3 OCCURS 4 TIMES INDEXED BY CSZ-INDEX. 07 LABEL-CITY PIC X(10). 07 FILLER PIC XXXX. 07 LABEL-STATE PIC XX. 07 FILLER PIC XXXX. 07 LABEL-ZIP PIC 99999. 07 FILLER PIC XXXXX. 01 END-OF-FILE PIC X. PROCEDURE DIVISION. A000-BEGIN. OPEN INPUT INPUT-FILE OUTPUT REPORT-FILE. MOVE SPACES TO LABELS-TABLE. SET ROW-INDEX, NAME-INDEX, ADDRESS-INDEX, CSZ-INDEX TO 1. PERFORM A100-READ-INPUT UNTIL END-OF-FILE = "Y". A050-WRAP-UP. IF LABEL-NAME(1, 1) IS NOT EQUAL TO SPACES PERFORM A300-PRINT-PAGE-OF-LABELS VARYING ROW-INDEX FROM 1 BY 1 UNTIL ROW-INDEX IS GREATER THAN 6. A050-END-OF-JOB. CLOSE INPUT-FILE REPORT-FILE. DISPLAY "END OF JOB". STOP RUN. A100-READ-INPUT. READ INPUT-FILE AT END MOVE "Y" TO END-OF-FILE. IF END-OF-FILE = "Y" NEXT SENTENCE ELSE PERFORM A200-GENERATE-LABELS. A200-GENERATE-LABELS. MOVE INPUT-NAME TO LABEL-NAME(ROW-INDEX, NAME-INDEX) MOVE INPUT-ADDRESS TO LABEL-ADDRESS(ROW-INDEX, ADDRESS-INDEX) MOVE INPUT-CITY TO LABEL-CITY(ROW-INDEX, CSZ-INDEX) MOVE INPUT-STATE TO LABEL-STATE(ROW-INDEX, CSZ-INDEX) MOVE INPUT-ZIP TO LABEL-ZIP(ROW-INDEX, CSZ-INDEX) IF ROW-INDEX = 6 AND NAME-INDEX = 4 PERFORM A300-PRINT-PAGE-OF-LABELS VARYING ROW-INDEX FROM 1 BY 1 UNTIL ROW-INDEX IS GREATER THAN 6 MOVE SPACES TO LABELS-TABLE SET ROW-INDEX, NAME-INDEX, ADDRESS-INDEX, CSZ-INDEX TO 1 ELSE PERFORM A210-UPDATE-INDEXES. A210-UPDATE-INDEXES. IF ROW-INDEX = 6 SET ROW-INDEX TO 1 SET NAME-INDEX ADDRESS-INDEX CSZ-INDEX UP BY 1 ELSE SET ROW-INDEX UP BY 1. A300-PRINT-PAGE-OF-LABELS. WRITE REPORT-RECORD FROM NAME-LINE(ROW-INDEX) AFTER ADVANCING 3. WRITE REPORT-RECORD FROM ADDRESS-LINE(ROW-INDEX) AFTER ADVANCING 1. WRITE REPORT-RECORD FROM CSZ-LINE(ROW-INDEX) AFTER ADVANCING 1. |
The group indicating process greatly improves a report's readability where long sequences of entries have some element in common. You print the element once, then leave it blank for subsequent lines, as long as there is no change in that element. For example, if your sample file's sort sequence is State (major key) and City (minor key), you get sequences like those in Table 10-2.
Without Group Indicating | With Group Indicating | ||||
---|---|---|---|---|---|
STATE | CITY | STORE NUMBER |
STATE | CITY | STORE NUMBER |
Arizona | Grand Canyon | 111111 | Arizona | Grand Canyon | 111111 |
Arizona | Grand Canyon | 123456 | 123456 | ||
Arizona | Grand Canyon | 222222 | 222222 | ||
Arizona | Tucson | 333333 | Arizona | Tucson | 333333 |
Arizona | Tucson | 444444 | 444444 | ||
Arizona | Tucson | 555555 | 555555 | ||
Massachusetts | Maynard | 111111 | Massachusetts | Maynard | 111111 |
Massachusetts | Maynard | 222222 | 222222 | ||
Massachusetts | Maynard | 333333 | 333333 | ||
Massachusetts | Maynard | 444444 | 444444 | ||
Massachusetts | Tewksbury | 111111 | Massachusetts | Tewksbury | 111111 |
Massachusetts | Tewksbury | 222222 | 222222 | ||
New Hampshire | Manchester | 111111 | New Hampshire | Manchester | 111111 |
New Hampshire | Manchester | 222222 | 222222 | ||
New Hampshire | Merrimack | 333333 | New Hampshire | Merrimack | 333333 |
New Hampshire | Merrimack | 444444 | 444444 | ||
New Hampshire | Merrimack | 555555 | 555555 | ||
New Hampshire | Nashua | 666666 | New Hampshire | Nashua | 666666 |
Previous | Next | Contents | Index |