![]() |
QUERY/iX Reference Manual
> Chapter 5 QUERY/iX COMMANDS (cont)REPORT |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
SyntaxR[EPORT] report statement;... ENDFor example: >REPORT >>H1,"NAME LIST",20,SPACE A2 >>D,LAST-NAME,20 >>D,FIRST-NAME,30 >>ENDor >R H1,"NAME LIST",20,SPACE A2;D,LAST-NAME,20;D,FIRST-NAME,30;ENDWhere header statement = H1,"NAME LIST",20,SPACE A2 and detail statements = D,LAST-NAME,20 and D,FIRST-NAME,30 Parameter
DiscussionIf you enter REPORT without following it with report statements, QUERY will prompt you for the statements until you enter an END at the prompt. If the first report statement is in error, the REPORT command terminates. The REPORT command is an extension of a retrieval command in that it prints a report of the data entries located by the last FIND, MULTIFIND, or SUBSET command. REPORT output can be directed to any desired output device through the MPE :FILE command and the QUERY OUTPUT= command. Refer to the OUTPUT= command for further discussion. You can specify your own user defined procedure(s) to enable your report to perform specialized tasks not provided by QUERY. This is an advanced capability used by programmers. Refer to Appendix F for further discussion. Table 5-1 REPORT Statements
REPORT StatementsStatements can also contain additional parameters which perform such tasks as skipping to the top of the next report page, spacing between report lines, and indicating edit masks to be used to insert punctuation such as decimal points, dollar signs, etc., into values printed in the report. These options are described in Table 5-2 "REPORT Statement Parameters". Table 5-2 REPORT Statement Parameters
Print PositionThe column position specified is the rightmost character to be output on the report for the specific report item. When OUT=TERM, QUERY truncates items that are longer than 80 characters, then QUERY positions the data in the report line. When OUT=LP, QUERY truncates items that are longer than 256 characters, then QUERY positions the data in the report line. If the print position for the data does not allow the remainder of the data to be printed, then the data is truncated again, only from the LEFT this time. Because the maximum length for TERM is different than the maximum length for LP, a data item value (that fits the case above) will print differently in a report to TERM and to LP. For example, given the report line: D1,X250,10 (where X250 is a data item of type X with a length of 250).
Skipping and SpacingWhen paging is in effect, the following rules govern skipping and spacing:
Designing a ReportReport formats vary according to their use. However, many reports assume the general format depicted in Figure 5-1 "General Report Format". The TITLE and HEADERS describe the report and are printed at the top of each page along with the page number. HEADERS are usually used to describe the report columns. The report body consists of DETAIL lines, GROUP TITLES, and TOTALS along with other descriptive labels. Normally, each detail line displays information from a single data entry, although information can appear on more than one line per entry. A DETAIL field can be edited to include commas, decimal points, dollar signs, and other punctuation characters. DETAIL lines can be sorted and grouped according to the values of data items in the entry. For example, a sales report may list sales results by country, region, sales office, and finally by individual salesperson within each office. A GROUP TITLE can be printed whenever a "sort field" changes value. For example, when the country changes, the name of the country could be displayed as a GROUP TITLE. The title can be a series of characters or a data item value. SUBTOTALS can be printed for logical groups (for example, for each sales office) and GRANDTOTALS for the entire report. These totals add, average, or count the DETAIL fields in each column of the report. Like DETAIL and GROUP fields, TOTAL fields can be edited with punctuation characters. Figure 5-1 General Report Format TITLE OF REPORT PAGE NO. HEADER HEADER HEADER GROUP TITLE DETAIL DETAIL DETAIL DETAIL DETAIL DETAIL DETAIL DETAIL DETAIL SUBTOTAL SUBTOTAL SUBTOTAL GROUP TITLE DETAIL DETAIL DETAIL DETAIL DETAIL DETAIL DETAIL DETAIL DETAIL SUBTOTAL SUBTOTAL SUBTOTAL GRANDTOTAL GRANDTOTAL GRANDTOTALThrough the following sections on REPORT Statements, a report is created by adding one statement type at a time and showing how the added statements change the report. Figure 5-2 "Sample Report" contains the final version of the report. Figure 5-2 Sample Report AS OF: 01/07/86 PAGE 1 BOBO'S MERCANTILE ON HAND INVENTORY BIN# SUPPLIER STOCK SHIP DATE INVENTORY AMOUNT 0 H & S SURPLUS 7391Z22F 8/13/85 $5,012.50 5405T14F 9/11/85 $12,129.60 6650D22S 12/05/85 $14,985.00 BIN TOTAL $32,127.10 * 1 ACME WIDGET 2457A11C 12/01/85 $553,477,666.95 BAY PAPER CO. 7391Z22F 12/01/85 $4,704.00 CARDINAL MILLS 5405T14F 11/28/85 $1,396.00 JAKE'S JUNK 3739A14F 12/15/85 $1,189.32 BIN TOTAL $553,485,956.27 * 2 ACME WIDGET 4397D13P 3/02/85 $55,080.00 CARDINAL MILLS 3586T14Y 11/20/85 $358.56 BIN TOTAL $55,438.56 * 3 ACME WIDGET 6650D22S 12/03/85 $75,716.62 H & S SURPLUS 6650D22S 12/14/85 $187.85 6650D22S 12/15/85 $153.45 BIN TOTAL $75,057.92 * TOTAL INVENTORY $553,248,578.85 ** REPORT - HEADER STATEMENTSHeader statements are used to print report titles and column headings at the top of each report page. SyntaxHheader number, print element, print position [,SPACE A[number]] [,SPACE B[number]] [,E{number | Z}]For example: H2,F-NAME,20,SPACE A5Where header number = 2, print element = F-NAME, print position = 20, and number of spaces = 5 Parameters
DiscussionA header can contain up to 9 lines of information and any number of blank lines as long as it does not exceed the page size as defined by the output control statement LINES=. (Refer to the description at the beginning of this section.) A report consisting of only header statements will not generate any output. Negative data item values of type P, Z, I, J, and K are output with a special character in the rightmost position, unless you use the NOPUNCH output control statement. This type of output is called overpunch. Refer to the REPORT ALL command for more information on overpunch. >F ALL INVENTORY.STOCK# USING SERIAL READ 13 ENTRIES QUALIFIED >REPORT >>H1,"AS OF:",6 >>H1,DATE,15 >>H1,PAGENO,71 >>H1,"PAGE",69 >>H2,"BOBO'S MERCANTILE",45 >>H3,"ON HAND INVENTORY",45,SPACE A2 >>H7,"BIN#",4 >>H7,"SUPPLIER",14 >>H7,"STOCK",33 >>H7,"SHIP DATE",49 >>H7,"INVENTORY",68 >>H8,"AMOUNT",68 . . .In the example above, entries are located first. Then report statements are entered describing the report headings. Characters in quotation marks are printed as they appear in the statement. DATE and PAGENO are generated and printed by QUERY. The following is an example of the specified report. The column and heading markers, in the example below, do not appear in an actual report. Col. Col. Col. Col. Col. Cols. 6 15 33 45 49 68 71 | | | | | | | v v | | | | v H1--> AS OF: 01/07/86 | v | PAGE 1 H2--> BOBO'S MERCANTILE | | H3--> ON HAND INVENTORY | | | | | v v v H7--> BIN# SUPPLIER STOCK SHIP DATE INVENTORY H8--> AMOUNT REPORT - DETAIL STATEMENTSDetail statements usually specify a data item name whose value changes with each data entry reported, although a fixed series of characters can be specified as well. The statement specifies the print position, top-of-form, line spacing, and applicable edit masks. SyntaxD[detail number] ,print element,print position [,SPACE A[number]] [,SPACE B[number]] [,SKIP {A | B}] [,E {number | Z}]For example: D2,BADGE#,35,SKIP B,E8Where detail number = 2, print element = BADGE#, print position = 35, and edit number = 8 D,R3,15,SPACE A2Where print element = R3, print position = 15, number of spaces = 2 Parameters
DiscussionNegative data item values of type P, Z, I, J, and K are output with a special character in the rightmost position, unless you use the NOPUNCH output control statement. This type of output is called overpunch. Refer to the REPORT ALL command for more information on overpunch. >REPORT >>H1,"AS OF:",6 >>H1,DATE,15 >>H1,PAGENO,71 >>H1,"PAGE",69 >>H2,"BOBO'S MERCANTILE",45 >>H3,"ON HAND INVENTORY",45,SPACE A2 >>H7,"BIN#",4 >>H7,"SUPPLIER",14 >>H7,"STOCK",33 >>H7,"SHIP DATE",49 >>H7,"INVENTORY",68 >>H8,"AMOUNT",68 >>D1,STOCK#,36 >>D1,LASTSHIPDATE,48 >>ENDIf the same report shown in the header statement example has detail statements added, the result follows. The first detail statement prints the value of STOCK# ending in column 36. The next statement prints LASTSHIPDATE value on the same detail line ending in column 48. Note that detail lines are printed once per entry. Col. Col. 36 48 | | | | AS OF: 01/07/86 | | PAGE 1 BOBO'S MERCANTILE | ON HAND INVENTORY | | | | v BIN# SUPPLIER STOCK | SHIP DATE INVENTORY v AMOUNT D1--> 6650D22S 120385 D1--> 2457A11C 120185 D1--> 3586T14Y 112085 . 7391Z22F 120185 . 5405T14F 112885 . 7391Z22F 81385 . 5405T14F 91185 . 4397D13P 30285 . 3739A14F 121585 . 6650D22S 120585 . 6650D22S 121485 D1--> 6650D22S 121585 REPORT - EDIT STATEMENTSThe edit statement is used for formatting data item values printed in a report. The statement performs such functions as suppressing leading zeros in numeric values, inserting characters such as dollar signs, dashes, commas, and decimal points. It also masks characters to eliminate them from the printed output. Edit statements can appear anywhere in the report. SyntaxEnumber,"edit mask"For example: E3,"$$$999CR"Where number = 3, and edit mask = "$$$999CR" Parameters
Alphanumeric Edit MasksAlphanumeric edit masks consist of X's (used as place holders) and any other ASCII alphanumeric printing characters (used as insertion characters). QUERY examines the data item value specified in the detail, group, or total statement and the edit mask specified in the referenced edit statement, starting with the leftmost character of each. If the character in the edit mask is X, a character from the data item value is printed in the corresponding position of the output field. If the character in the edit mask is any character other than an X, the edit mask character is printed in the corresponding position of the output field. For example, if the value ABCD is edited with the mask "X-X-X-X", the result is printed as A-B-C-D. If there are fewer X's in the edit mask than there are in the data item value, the rightmost characters of the data item value that do not correspond to an X in the mask are omitted. For example, if the value ABCD is edited with the mask "XX", the result is printed as AB. If there are more X's in the edit mask than there are characters in the data item value, QUERY prints asterisks in place of the unused X's in the edit mask. All insertion characters in the mask are printed in the output field. For example, if the value ABCD is edited with the mask "XXXX-X", the result is printed as ABCD-*. Here are two more examples of alphanumeric edit masks:
Numeric Edit MasksA numeric edit mask consists of the placement holders (9,Z,*,$), the sign characters (CR,-), and any other numeric ASCII printing characters used as insertion characters. Each of the place holders and sign characters serves a special purpose in editing data item values. Characters and their usage are specified in Table 5-3 "Numeric Edit Mask Characters". The numeric edit mask edits decimal integer values consisting of up to 20 characters (not counting the sign characters) in the combinations outlined in Table 5-4 "Numeric Edit Mask Combinations". If the number of significant digits of the data item value is greater than the number of place holders (9,Z,*,$) in the edit mask, the output field is filled with asterisks. For example, if the value 12345 is edited with the mask "999CR" the result is *****. Only one decimal point can appear in any edit mask. If a minus sign appears in the edit mask in any position other than the rightmost character of the mask, the minus is treated as an insertion character. For example, if the value 12345 is edited with the mask 999-99, the result is 123-45. Figure 5-3 "Sample Output Using Numeric Edit Masks" shows the results of printing numeric data item values using numeric edit masks. Table 5-3 Numeric Edit Mask Characters
DATA ITEM VALUE EDIT MASK PRINTED RESULT 0059 "$$$,999" $059 001024 "ZZZ,ZZZ" 1,024 -0010555 "$$,$$$.99CR" $105.55CR 00010555 "$$,$$$.99CR" $105.55 -0010555 "$$,$$$.99-" $105.55- 15039250 "$,$$$,$$$.99CR" $150,392.50 00049 "*****" ***49 044240474 "999-99-9999" 044-24-0474 -2145 "$,$$$.99" $21.45 Real NumbersReal values can be printed in either fixed-point (xx.xxx) or floating-point (xx.xxxExx) form. The default is that R2 values less than .1 or greater than 10 to the sixth (106) and R4 values less than .1 or greater than 10 to the sixteenth (1016) are printed in floating point (scientific notation). All other R2 and R4 values are printed in fixed-point notation. To override the default and specify that fixed point form always be used for real number values, you can use edit masks. These edit masks work the same way as for other data types except that the placement of the decimal point determines where the number will be placed in the field. Note that fixed R2 values occupy up to eight characters and floating-point R2 values occupy up to 12 characters. R4 values occupy up to 18 and 22 characters for fixed and floating-point respectively.
Example>REPORT >>H1,"AS OF:",6 >>H1,DATE,15 >>H1,PAGENO,71 >>H1,"PAGE",69 >>H2,"BOBO'S MERCANTILE",45 >>H3,"ON HAND INVENTORY",45,SPACE A2 >>H7,"BIN#",4 >>H7,"SUPPLIER",14 >>H7,"STOCK",33 >>H7,"SHIP DATE",49 >>H7,"INVENTORY",68 >>H8,"AMOUNT",68 >>D1,STOCK#,36 >>D1,LASTSHIPDATE,48,E2 >><user|E2,"XX/XX/XX" >>ENDIn the example above, LASTSHIPDATE is altered with edit mask E2. Edit mask E2 is defined as "XX/XX/XX". Now the report looks like this: AS OF: 01/07/86 PAGE 1 BOBO'S MERCANTILE ON HAND INVENTORY BIN# SUPPLIER STOCK SHIP DATE INVENTORY AMOUNT 6650D22S 12/03/85 2457A11C 12/01/85 3586T14Y 11/20/85 7391Z22F 12/01/85 5405T14F 11/28/85 7391Z22F 8/13/85 5405T14F 9/11/85 4397D13P 3/02/85 3739A14F 12/15/85 6650D22S 12/05/85 6650D22S 12/14/85 6650D22S 12/15/85 REPORT - SORT STATEMENTSThe sort statement specifies data items whose values are used to sort data entries when they are printed in the report. It also defines control break levels for use by group and total statements in the report. SyntaxS[level],data item name [,{ASC | DES}]For example: S3,BADGE#,ASC Where level = 3 and data item name = BADGE# S,L-NAME Where data item name = L-NAME Parameters
S1,L-NAME DATA ENTRIES AFTER FIND L-NAME F-NAME AGE WHITE ROB 26 BROWN JACK 32 GREEN ROB 49 WHITE LARRY 81 BROWN CHRIS 17 GREEN SAM 28 GREEN BILL 45 BROWN DAN 39 WHITE WILL 22 DATA ENTRIES AFTER SORT EXECUTED L-NAME F-NAME AGE BROWN JACK 32 BROWN CHRIS 17 BROWN DAN 39 GREEN ROB 49 GREEN SAM 28 GREEN BILL 45 WHITE ROB 26 WHITE LARRY 81 WHITE WILL 22The higher-numbered sort statement identifies the major (or first) sort field, while the lower-numbered sort statement identifies the minor sort field. The minor sort arranges entries in the order specified, keeping all major sort items with identical values together, in other words, it sorts within subsets of the entire set of entries. S1,F-NAME S2,L-NAMEIf the statements above appear in a report, the result would be as follows. L-NAME F-NAME AGE level 2 (major)--> BROWN level 1 (minor)--> CHRIS 17 Control break BROWN control breaks DAN 39 BROWN JACK 32 level 2 (major)--> GREEN BILL 45 control break GREEN ROB 49 GREEN SAM 28 level 2 (major)--> WHITE LARRY 81 control break WHITE ROB 26 WHITE WILL 22 Control BreaksA control break occurs during the printing of a report whenever the value of a current entry for a data item defined in a numbered sort statement is different from the value of the last entry. When the first entry is printed, a control break occurs since the data item value changes from null (no value) to the first value. Totals are not printed when the first control break occurs. In the previous examples, a control break occurs when the value of L-NAME becomes BROWN, when it changes to GREEN, and again when it changes to WHITE. This is known as a level 2 control break because the data item named L-NAME appears in a sort statement labeled S2. The level 1 control break is associated with the data item named F-NAME and sort statement labeled S1. A control break occurs for all lower levels whenever a higher level control break occurs. For example, when a control break occurs for level 2 (L-NAME), a control break also occurs for level 1 (F-NAME). A group or total statement prints only when a control break occurs that is at the same level as the group or total statement. This means that a total statement labeled T1 prints only when a level 1 control break occurs, or a group statement labeled G2 prints only when a level 2 control break occurs. Consult the descriptions of group and total statements later in this section for an explanation of their functions. Sort statements with no level (i.e., no number) are used to sort entries but do not define control breaks for use by group or total statements. Major to Minor Sort FieldsNumbered and unnumbered sort statements can appear in the same REPORT command. The order in which unnumbered sort statements appear in the report body is significant. The first unnumbered statement defines the most minor sort field, while the last unnumbered statement defines the most major sort field. QUERY defines sort fields in the following order from most major to most minor: MOST MAJOR ---------------------------------------------> MOST MINOR S10 ---> S1 ---> S(last in report body) ---> S(first in report body) STATEMENTS ORDER S2,OFFICE MONTH (S3) MAJOR S,PARTNO OFFICE (S2) | S1,SLSMAN SLSMAN (S1) | S,QUANTITY QUANTITY (S last) v S3,MONTH PARTNO (S first) MINOR Maximum Number of Sort ItemsThe number of data items you can use to sort is limited in two ways. The maximum number of sort statements allowed in a single report is 66. You can have up to 66 sort statements provided that the combined length of the data items in all of the 66 statements is not greater than 2378 words. Example>REPORT >>H1,"AS OF:",6 >>H1,DATE,15 >>H1,PAGENO,71 >>H1,"PAGE",69 >>H2,"BOBO'S MERCANTILE",45 >>H3,"ON HAND INVENTORY",45,SPACE A2 >>H7,"BIN#",4 >>H7,"SUPPLIER",14 >>H7,"STOCK",33 >>H7,"SHIP DATE",49 >>H8,"AMOUNT",68 >>D1,STOCK#,36 >>D1,LASTSHIPDATE,48,E2 >>E2,"XX/XX/XX" >>S2,BINNUM >>S1,SUPPLIER >>S,LASTSHIPDATE >>ENDIn the example above, BINNUM is defined as a sort level 2, SUPPLIER as sort level 1, and LASTSHIPDATE as a sort without a control break. As shown in the new report, the detail entries are now sorted by BINNUM, SUPPLIER, and LASTSHIPDATE. The values for BINNUM and SUPPLIER will be printed in group statements which are described next. AS OF: 01/07/86 PAGE 1 BOBO'S MERCANTILE ON HAND INVENTORY BIN# SUPPLIER STOCK SHIP DATE INVENTORY AMOUNT 7391Z22F 8/13/85 5405T14F 9/11/85 6650D22S 12/05/85 2457A11C 12/01/85 7391Z22F 12/01/85 5405T14F 11/28/85 3739A14F 12/15/85 4397D13P 3/02/85 3586T14Y 11/20/85 6650D22S 12/03/85 6650D22S 12/14/85 6650D22S 12/15/85 REPORT - GROUP STATEMENTSA group statement prints the value of a data item, the value in a register (Rn), or a series of characters whenever a control break occurs. SyntaxGlevel,print element, print position [,SPACE A[number] ] [,SPACE B[number] ] [,SKIP {A}] [,E{number | Z}]For example: G3,WEEK,35,SKIP B,E2Where level = 3, print element = WEEK, print position = 35, and edit number = 2 G1,R3,55,SPACE B2Where level = 1, print element = R3, print position = 55, and number of spaces = 2 Parameters
DiscussionEach control break occurs as a result of a sort statement labeled from 1 to 10. When the control break occurs, the group statement with the same number as the sort statement prints the information you specify. (Refer to "Control Breaks" under REPORT Sort Statements for more information.) Whenever a control break occurs, all group statements with a number equal to or less than the level of the sort statement causing the break will print a value and/or series of characters. All group statements print on the same line. Since a control break always occurs at the very beginning of the report, all group statements print their contents before any detail statements are executed. If the REPORT command contains group statements but no sort statements, an error message is printed. Negative data item values of type P, Z, I, J, and K are output with a special character in the rightmost position, unless you use the NOPUNCH output control statement. This type of output is called overpunch. Refer to the REPORT ALL command for more information on overpunch. Example 5-1 Title not available (Discussion) >REPORT >>H1,"AS OF:",6 >>H1,DATE,15 >>H1,PAGENO,71 >>H1,"PAGE",69 >>H2,"BOBO'S MERCANTILE",45 >>H3,"ON HAND INVENTORY",45,SPACE A2 >>H7,"BIN#",4 >>H7,"SUPPLIER",14 >>H7,"STOCK",33 >>H7,"SHIP DATE",49 >>H7,"INVENTORY",68 >>H8,"AMOUNT",68 >>D1,STOCK#,36 >>D1,LASTSHIPDATE,48 >>E2,"XX/XX/XX" >>S2,BINNUM >>S1,SUPPLIER >>S,LASTSHIPDATE >>G2,BINNUM,3,SPACE B >>G1,SUPPLIER,20 >>ENDIn this example, BINNUM will be printed when a control break occurs for sort level 2, and SUPPLIER when a sort level 1 control break occurs. In the report below, notice that the two items mentioned in the detail statements do not print on the same line as the group statements. This is because the detail statements are numbered. Unnumbered detail statements print on the same line as a group statement whenever a control break occurs. AS OF: 01/07/86 PAGE 1 BOBO'S MERCANTILE ON HAND INVENTORY BIN# SUPPLIER STOCK SHIP DATE INVENTORY AMOUNT 0 H & S SURPLUS 7391Z22F 8/13/85 5405T14F 9/11/85 6650D22S 12/05/85 1 ACME WIDGET <-------- level 1 and level 2 control break 2457A11C 12/01/85 BAY PAPER CO. <--------- level 1 control break 7391Z22F 12/01/85 CARDINAL MILLS <--------- level 1 control break 5405T14F 11/28/85 JAKE'S JUNK <--------- level 1 control break 3739A14F 12/15/85 2 ACME WIDGET <------- level 1 and level 2 control break 4397D13P 3/02/85 CARDINAL MILLS 3586T14Y 11/20/85 3 ACME WIDGET 6650D22S 12/03/85 H & S SURPLUS 6650D22S 12/14/85 6650D22S 12/15/85 REPORT - TOTAL STATEMENTSThe total statement prints a data item value, the value in a register (Rn), a series of characters, or the total, average, or count of a group of data items whenever a control break occurs. SyntaxTlevel,print element,print position [,SPACE A[number]] [,SPACE B[number]] [,SKIP {A | B}] [,E{number | Z}] [,{ADD | AVERAGE | COUNT} [,NOREPEAT]]Or the special form: Tlevel, RnFor example: T4,WAGES,60,SKIP A,E2,ADDWhere level = 4, print element = WAGES, print position = 60, and edit number = 2 T1,"TOTAL WAGES=",40,SPACE B5Where level = 1, print element = "TOTAL WAGES=", print position = 40, and number of spaces = 5 T3,R2Where level = 3 and n = 2 Parameters
DiscussionIf the total statement is labeled TF, the ADD, AVERAGE, and COUNT options apply to all occurrences of the data item in the report. Negative data item values of type P, Z, I, J, and K are output with a special character in the rightmost position, unless you use the NOPUNCH output control statement. This type of output is called overpunch. Refer to the REPORT ALL command for more information on overpunch. If you use the special form of the command, specifying only a register without a print element, the register is cleared (reset to zero) when a control break occurs. A control break results from a sort statement labeled from 1 to 10. When a control break occurs, the total statement corresponding to the sort level causing the break prints the information you specify. Total statements not labeled TF require corresponding sort statements. (Refer to the description of the sort statement for more information on control breaks.) To perform more than one operation (total, average, count) on the same data item, you must specify a total statement for each operation. The information is printed on the same line if you use the same level for each statement. No more than five (5) data items can be used as print elements in total statements. Example 5-2 Title not available (Discussion) >REPORT >>H1,"AS OF:",6 >>H1,DATE,15 >>H1,PAGENO,71 >>H1,"PAGE",69 >>H2,"BOBO'S MERCANTILE",45 >>H3,"ON HAND INVENTORY",45,SPACE A2 >>H7,"BIN#",4 >>H7,"SUPPLIER",14 >>H7,"STOCK",33 >>H7,"SHIP DATE",49 >>H7,"INVENTORY",68 >>H8,"AMOUNT",68 >>D1,STOCK#,36 >>D1,LASTSHIPDATE,48,E2 >>E2,"XX/XX/XX" >>S2,BINNUM >>S1,SUPPLIER >>S,LASTSHIPDATE >>G2,BINNUM,3,SPACE B >>G1,SUPPLIER,20 >>T2," *",70 >>T2,"BIN TOTAL",14,SPACE B,SPACE A >>TF,"TOTAL INVENTORY",20,SPACE B3 >>TF," **",71 >>ENDThe total statements which have been added merely print character literals. The totals are computed with register statements which are described next. More total statements are added to the example in REPORT Register Statements. In this example, the first total statement prints an asterisk in column 70 and the next one prints a character literal when a level 2 control break occurs. When the final totals are printed, the last two total statements print the specified characters. The resulting report appears as follows. AS OF: 01/07/86 PAGE 1 BOBO'S MERCANTILE ON HAND INVENTORY BIN# SUPPLIER STOCK SHIP DATE INVENTORY AMOUNT 0 H & S SURPLUS 7391Z22F 8/13/85 5405T14F 9/11/85 6650D22S 12/05/85 BIN TOTAL <------ level 2 control break * 1 ACME WIDGET 2457A11C 12/01/85 BAY PAPER CO. 7391Z22F 12/01/85 CARDINAL MILLS 5405T14F 11/28/85 JAKE'S JUNK 3739A14F 12/15/85 BIN TOTAL * 2 ACME WIDGET 4397D13P 3/02/85 CARDINAL MILLS 3586T14Y 11/20/85 BIN TOTAL * 3 ACME WIDGET 6650D22S 12/03/85 H & S SURPLUS 6650D22S 12/14/85 6650D22S 12/15/85 BIN TOTAL * TOTAL INVENTORY ** The NOREPEAT OptionThe NOREPEAT option is only applicable on compound data sets created by a MULTIFIND command. In a compound data set, a particular value can occur more than once. This is because each value of the data item on the left side of the TO (of the JOIN command) is being paired with each occurrence of that value of the data item on the right side of the TO. If the JOIN and MULTIFIND commands are as follows, each STOCK# value in STOCK-DETAIL will be paired with each occurrence of that same STOCK# value in SALES-DETAIL. >JOIN STOCK-DETAIL.STOCK# TO SALES-DETAIL.STOCK# >MU ALLFor example, given the following values in the data sets STOCK-DETAIL and SALES-DETAIL: STOCK-DETAIL SALES-DETAIL ------------------------------ ------------------------------ STOCK# DESCR ON-HAND ACCT# STOCK# QUAN ------------------------------ ------------------------------ 110 NUT 970 666 90 350 60 BOLT 1200 222 60 25 50 NAIL 1000 999 60 500 50 NAIL 900 555 60 75 ------------------------------ 333 50 45 111 50 100 ------------------------------the following compound data set entries are created: <------ (STOCK-DETAIL) --------><------- (SALES-DETAIL) --------> ------------------------------------------------------------------ STOCK# DESCR ON-HAND ACCT# STOCK# QUAN ------------------------------------------------------------------ 60 BOLT 1200 222 60 25 60 BOLT 1200 999 60 500 60 BOLT 1200 555 60 75 50 NAIL 1000 333 50 45 50 NAIL 1000 111 50 100 50 NAIL 900 333 50 45 50 NAIL 900 111 50 100 ------------------------------------------------------------------The one occurrence of STOCK# 60 in STOCK-DETAIL is paired with each occurrence of STOCK# 60 in SALES-DETAIL resulting in 3 entries in the compound data set. You can see by the ACCT# that each of these entries is separate and unique. Now suppose you wanted to produce a report from this retrieval in which you wanted to count the number of STOCK# in the entries retrieved. The report might look like: >REPORT >>H1,"DIFFERENT STOCK# COUNT:",30 >>TF,STOCK-DETAIL.STOCK#,50,COUNT >>ENDThis report would produce the following: DIFFERENT STOCK# COUNT: 7This count is incorrect if you wanted a count of the unique STOCK# entries. If you wanted to know the number of selected entries from STOCK-DET you need to use the NOREPEAT option on the TF statement. This tells QUERY to count only the first occurrence of each retrieved entry from STOCK-DETAIL. The report and its output are shown below: >REPORT >>H1,"DIFFERENT STOCK# COUNT:",30 >>TF,STOCK-DETAIL.STOCK#,50,COUNT,NOREPEAT >>END DIFFERENT STOCK# COUNT: 3If you wanted a count of the unique stock# entries, you must structure the access such that the item being counted is unique in its source dataset. REPORT - REGISTER STATEMENTSA register statement specifies an operation to be executed in one of 30 QUERY registers. The register statements are executed sequentially as they appear in the REPORT command, once for each data entry in the report (that is, once for each entry selected by the last retrieval command). SyntaxRnumber, {L[OAD] } ,data element [,NOREPEAT] A[DD] S[UBTRACT] M[ULTIPLY] D[IVIDE]For example: R3,ADD,PRICEWhere number = 3 and data element = PRICE R0,M,"25"Where number = 0 and data element = "25" R5,DIV,R6Where number = 5 and data element = R6 Parameters
DiscussionAfter each operation is executed, the result is placed in the register specified at the beginning of the statement. For example, assume R2 contains 3 and R4 contains 2. After the statement below is executed: R2,MULTIPLY,R4R2 will contain 6. Using QUERY RegistersThe register statements in a REPORT command describe a fixed sequence of operations to be performed each time a new data entry is processed for the report. If you are familiar with programming techniques, you can consider the Rn statements as a program "loop" which is executed once for each entry in the report. Rn statement execution affects only the 30 QUERY registers. No output results from the statements, although you can print the content of any register by using other REPORT command statements (with the exception of sort and header statements). All register operations except LOAD are cumulative. When each Rn statement is executed, the current contents of the register are operated on by the data element and the result is stored in the register again. Initializing RegistersEach register is initialized to zero when the REPORT command begins execution. You can reset the register to zero in three ways:
Register and Data TypesOnly numeric type data can be used in register operations. The following IMAGE data item types are allowed:
HIGHEST R4 ,E4 (Extended precision type data) R2 ,E2 (Real type data) LOWEST I1,I2,I4,J1,J2,J4,K1,K2,Zn,Pn (Integers and packed decimal numbers)The new register content always has a data type which is the higher of the two operand types: the old register content or the data element. For example, if Register 2 is loaded with an integer and then multiplied by a real type data item, the content of R2 will be type real. R2,L,"3" R2,M,PERCENT (where the value of PERCENT is 25.6)All registers start with a default type of packed decimal. When you issue the REPORT command, QUERY cycles through all register statements (before executing the command) and assigns each register the highest type that the register will hold during the report. This ensures the correct typing of a register, in case its type changes during the report. For example: R1,LOAD,DECITEM Register 1 is type packed decimal R2,LOAD,REALITEM Register 2 is type real (R2) R1,ADD,R2 Register 1 becomes type real (R2)Because Register 1 is added with Register 2 later in the report, it is typed as real, instead of the initial default of packed decimal. When the first LOAD into Register 1 is performed, DECITEM will be converted into a real and loaded into Register 1. If Register 1 is printed with a detail statement, it will be displayed as a R2 data type. You can convert a register to type R4 either by loading it (or by performing an arithmetic operation on it) with a data item of type R4. You can also convert a register to R4 by loading it with a real numeric literal that has more than 6 digits. Zeros preceding the decimal point or the most significant digit will be ignored, except in the case of all zeros. For example, all of the following convert Register 1 into an R4 data type: R1,ADD,"000000.0" (produces 0.0) R1,LOAD,"0.000000" (produces 0.0) R1,MUL,"1.000000" (produces 1.0) R1,ADD,"500.0000" (produces 500.0) R1,LOAD,".0000100" (produces .00001)The following will not perform the conversion since leading zeros will not affect the output. R1,LOAD,"000005.0" (produces an R2 data type) R1,LOAD,"000000.5" (produces an R2 data type)However, the following will perform the conversion. R1,LOAD,"5.000000" (produces an R4 data type) R1,LOAD,".5000000" (produces an R4 data type)The largest integer (including all IMAGE integer data types) which a register can contain is 19 digits. Real and extended precision numbers have the same limits in registers as IMAGE R2 and R4 data items. R2 can have 6 to 7 significant digits and R4 can have 16 to 17 significant digits. If a register calculation results in overflow, a message is printed on the $STDLIST device. When mixing data types in arithmetic register computations, you should think about the order of precedence and its effect on the calculations. For example, if you operate on a real register number with an integer having 12 significant digits, the result will have 6 to 7 significant digits. Numeric LiteralsTo use a constant number in a register operation, you enter the number surrounded by quotation marks (for example, "325", ".0013", "-3E-6"). This type of number is called a numeric literal. Integer numeric literals can have at most 19 digits. The length of real numeric literals is limited only by the line length (or input record length). Limits for real numeric literal values and significant digits are the R2 limits. Numeric literals can contain the following characters within the quotation marks.
>REPORT >>H1,"AS OF:",6 >>H1,DATE,15 >>H1,PAGENO,71 >>H1,"PAGE",69 >>H2,"BOBO'S MERCANTILE",45 >>H3,"ON HAND INVENTORY",45,SPACE A2 >>H7,"BIN#",4 >>H7,"SUPPLIER",14 >>H7,"STOCK",33 >>H7,"SHIP DATE",49 >>H7,"INVENTORY",68 >>H8,"AMOUNT",68 >>D1,STOCK#,36 >>D1,LASTSHIPDATE,48 >>D1,R12,68,E1 >>E2,"XX/XX/XX" >>E1,"$$$,$$$,$$$,$$$.99" >>S2,BINNUM >>S1,SUPPLIER >>S,LASTSHIPDATE >>R12,LOAD,ONHANDQTY >>R12,MULT,UNIT-COST >>R8,ADD,R12 >>T2,R8,68,SPACE B,E1 >>G2,BINNUM,3,SPACE B >>G1,SUPPLIER,20 >>T2," *",70 >>T2,R8 >>T2,"BIN TOTAL",14,SPACE B,SPACE A >>TF,"TOTAL INVENTORY",20,SPACE B3 >>TF," **",71 >>TF,R9,68,SKIP A,E1 >>R9,ADD,R12 >>ENDIn the example above, a detail statement is added to print the content of Register 12 and edit with E1. Three register statements are added to load the value of ONHANDQTY into R12, multiply by UNIT-COST, and add the result to the contents of R8. Three more total statements are added to print the content of Register 8 at each level 2 control break, to clear Register 8, and to print the content of Register 9 on the final total line. The last register statement adds R12 to R9 each time the data of another entry is printed in the report. In this example, all register statements are executed every time a new entry is processed by the REPORT command. AS OF: 01/07/86 PAGE 1 BOBO'S MERCANTILE ON HAND INVENTORY BIN# SUPPLIER STOCK SHIP DATE INVENTORY AMOUNT ONHANDQTY multiplied by UNIT-COST ------ | 0 H & S SURPLUS v 7391Z22F 8/13/85 $5,012.50 5405T14F 9/11/85 $12,129.60 6650D22S 12/17/85 $14,985.00 BIN TOTAL $32,127.10 * ^ accumulated R12 values in R8 | R8 set to 0 --- 1 ACME WIDGET 2457A11C 12/01/85 $553,477,666.95 BAY PAPER CO. 7391Z22F 12/01/85 $4,704.00 CARDINAL MILLS 5405T14F 11/28/85 $1,396.00 JAKE'S JUNK 3739A14F 12/15/85 $1,189.32 BIN TOTAL $553,485,956.27 * 2 ACME WIDGET 4397D13P 3/02/85 $55,080.00 CARDINAL MILLS 3586T14Y 11/20/85 $358.56 BIN TOTAL $55,438.56 * 3 ACME WIDGET 6650D22S 12/03/85 $75,716.62 H & S SURPLUS 6650D22S 12/17/85 $187.85 6650D22S 12/15/85 $153.45 BIN TOTAL $76,057.92 * TOTAL INVENTORY accumulated R12 values--->$553,248,579.85 ** REPORT - OUTPUT CONTROL STATEMENTSOutput control statements can be included in a REPORT command to alter the standard parameters for report output. There are five output control statements.
ExampleIn the following example, entries are located with the FIND command. The REPORT ALL command prints entries without output control statements. The report is terminated with CONTROL-Y. When the NOPAGE output control statement is used, QUERY does not skip lines for a top of page margin. >F ALL LAST-NAME USING SERIAL READ 13 ENTRIES QUALIFIED >REPORT ALL ACCOUNT =54283540 LAST-NAME =CORCORAN FIRST-NAME =CLIFFORD INIT CONTROL-Y < CONTROL Y > >REPORT NOPAGE;ALL ACCOUNT =5428340 LAST-NAME =CORCORAN FIRST-NAME =CLIFFORD INITIAL =C . . . . . .In the example below, QUERY pauses after 10 lines and RETURN must be pressed to continue the listing: >REPORT >>D1,LAST-NAME,20,SPACE A2 >>PAUSE >>LINES=10 >>ENDIn the next example, the UNIFYDETAIL statement causes an entire block of detail lines to be printed together on one page. >REPORT >>UNIFYDETAIL >>D1,ITEM1,5 >>D2,ITEM2,5 >>D3,ITEM3,15 >>S1,ITEM1 >>G1,"GROUP TITLE",11 >>END
|