This subsection shows how to structure Process Modules (PM) for several typical data management tasks. In particular, PM’s are shown for reporting, updating a single Data Set (DS), updating with a transaction set, converting a DS to a new format, customizing commands, and as a stand-alone program for calculations. Examples also show how to combine reporting with other functions.
When a report is to be created without any other data manipulation, then the REPORT command can be used to invoke the Process Module (PM). The PM can include the following sections:
CONTROL | to relate the master DS and report files. |
DECLARE | to establish picture formats for the print statements, to define local variables. |
INITIAL | to assign values to system fields that are used in report formatting. Example: @BOTTOM_MARGIN, @FOOTING_SIZE, @LINES, @TOP_MARGIN, @TOF, @TOF_NUMBER, @PAGE_DIVIDER. |
TITLES | to create a title page for the reports. |
HEADINGS | to specify the headings for the top of each page. |
SUBHEADINGS | to print subheadings whenever the value changes in key fields. |
FOOTINGS | to print footnotes on each page. |
DETAIL | to print data from qualified records to the reports. |
TOTALS | to calculate and print subtotals. |
FINAL | to print grand totals or other information at the end of the program. |
The only sections required to create a report are CONTROL and one of the Record Processing sections. Other sections that might be used are PROCESS, BEFORE, AFTER, and UNQUALIFIED. Inter-record functions (SUM, MIN, MAX, AVG, STD_DEV) can be used in both the TOTALS and FINAL sections. Subtotals are specified in the TOTALS section and grand totals in the FINAL section.
ACCENT R provides five inter-record functions that are used for cumulative calculations on field values. The functions, MIN, MAX, AVG, SUM, and STD_DEV, are available for use in either the TOTALS or the FINAL section of a Process Module (PM). They all operate on integer, real, or numeric fields or expressions. MIN and MAX can also be used with date values.
The inter-record functions are actually calculated during execution of the DETAIL or AFTER:M section. Specifying these functions causes automatic allocation of space to store calculations. As each qualifying record is passed from the section, its values are used in the function calculations (unless the record fails a USE VALUES conditional in the ON statement under which the function appears). Note that the inter-record functions reflect all processing on records. (All updating is done before field values are passed to the inter-record functions.)
FUNCTIONS |
MEANING |
SUM (field;(ae)) |
total of all values for the field or expression among records in the group. |
MIN (field;(ae)) |
minimum value detected for the field or expression among records in the group. |
MAX (field;(ae)) |
maximum value detected for the field or expression among records in the group. |
AVG (field;(ae)) |
average value calculated for the field or expression among records in the group. |
STD_DEV(field;(ae)) |
standard deviation calculated for the field or expression among records in the group. |
A Data Set field, a declared field, or an arithmetic expression involving a field can be used in all inter-record functions. An expression must be enclosed in parentheses.
The use of subscript variables in SUM, MIN, MAX, AVG, and STD_DEV functions is confined to fields subscripted with a constant value. If a variable is used, it should be initialized in the INITIAL section and remain unchanged through all iterations. The following statement will print the same value 3 times rather than the sums of FLD(1), FLD(2), and FLD(3), as one might be inclined to think.
00500 PRINT SUM FLD(X) FOR X = 1 TO 3To print the sums of FLD(1), FLD(2), and FLD(3), use:
00500 PRINT SUM FLD(1), SUM FLD(2), SUM FLD(3)To print the sum of all the occurrences in FLD, use the following statements:
00300 DETAIL SECTION00305 FLD(1) + FLD(2) + FLD(3) TO FLDTOT ::00625 FINAL SECTION00630 PRINT SUM FLDTOT
The standard deviation is calculated by the Machine Method, which performs the calculation with only one pass through the data. The formula is taken from Handbook of Mathematical Calculations, by Karen and Said Assaf (Iowa State University Press, 1974, p. 195):
The following Process Module (PM), which is called by the REPORT command, contains only five sections. Since the user wants to report on all records, there is no conditional clause in the command. The UNQUALIFIED section is not needed in the PM.
The user in this example is a book distributor who has just updated the records in a Data Set (DS) MYSTRY. The DS after updating, is shown below. (The PM that updated this Data Set is shown in the next example.) Since the PM has control breaks on book title for subtotaling and averaging, the user accesses records through a Data Index (DI) domain on book title. The DI creates a view of the records as though they were sorted on book title. Subtotals are accumulated in the TOTALS section and grand totals in the FINAL section.
*USE DS MYSTRY DI MYSTRY*STRUCTURECUSTNO INT 5SHIPDATE DATEORDATE DATEBKTITLE CHAR 16QTY_PUR INT 4UNITPRICE FLOAT 4 2DISCPRICE FLOAT 6 4AMTDUE FLOAT 7 2*EXTRACT1123 10/15/91 08/01/91 ALEPH SOLUTION 30 2.11 1.5825 47.486430 10/15/91 09/28/91 ALEPH SOLUTION 40 2.11 2.0045 80.186674 10/15/91 09/12/91 ALEPH SOLUTION 45 2.11 1.7935 80.717432 10/15/91 09/02/91 ALEPH SOLUTION 25 2.11 1.7935 44.845234 10/15/91 08/10/91 DELPHI BETRAYAL 20 2.55 2.5500 51.006430 10/15/91 09/28/91 DELPHI BETRAYAL 30 2.55 2.4225 72.682242 10/15/91 09/01/91 JERICHO MAN 35 1.99 1.6915 59.203529 10/15/91 10/10/91 JERICHO MAN 35 1.99 1.9900 69.652242 10/15/91 09/01/91 MAYDAY MAYDAY 40 2.78 2.3630 94.526540 10/15/91 10/05/91 MAYDAY MAYDAY 25 2.78 2.7800 69.50*LIST PM DUE00095 !==============00100 CONTROL SECTION00105 !==============00110 RELATE DI MYSTRY AS MASTER FOR INPUT00120 RELATE SF DUE AS REPORT 100160 !00165 !===============00170 HEADINGS SECTION00175 !===============00175 PRINT00180 CENTER "SUMMARY REPORT FOR MYSTERY TITLES" AT 4000190 PRINT00200 CENTER "PREPARED ON " + @FDATE AT 4000210 PRINT00220 PRINT "CUSTNO ORDATE BOOK TITLE QTY "," UNITPRICE&DISCPRICE AMTDUE",@CR00230 !00235 !=============00240 DETAIL SECTION00245 !=============00250 PRINT CUSTNO,3B,ORDATE,2B,BKTITLE,QTY_PUR,&4B,UNITPRICE,6B, DISCPRICE @"D.DDDD",3B,AMTDUE00260 !00265 !=============00270 TOTALS SECTION00275 !=============00280 ON BKTITLE00290 PRINT 5B,"AVERAGE ORDER:",AVG QTY_PUR,15B,&"TOTAL DUE FOR", BKTITLE, SUM AMTDUE,@CR00300 !00305 !============00310 FINAL SECTION00315 !============00320 PRINT 44B, "THE TOTAL AMOUNT DUE IS: ", SUM AMTDUE00330 TYPE "THE REPORT IS AVAILABLE IN THE FILE DUE.REP"*REPORT VIA DUETHE REPORT IS AVAILABLE IN THE FILE DUE.REP*LIST SF DUE.REP
SUMMARY REPORT FOR MYSTERY TITLES
PREPARED ON Nov. 4, 1991
CUST NO | OR DATE | BOOK TITLE | QTY | UNIT PRICE | DISC PRICE | AMT DUE |
1123 | 08/01/91 | ALEPH SOLUTION | 30 | 2.11 | 1.5825 | 47.48 |
6430 | 09/28/91 | ALEPH SOLUTION | 40 | 2.11 | 2.0045 | 80.18 |
6674 | 09/12/91 | ALEPH SOLUTION | 45 | 2.11 | 1.7935 | 80.71 |
7432 | 09/02/91 | ALEPH SOLUTION | 25 | 2.11 | 1.7935 | 44.84 |
AVERAGE ORDER: 35 TOTAL DUE FOR ALEPH SOLUTION | 253.20 |
CUST NO | OR DATE | BOOK TITLE | QTY | UNIT PRICE | DISC PRICE | AMT DUE |
5234 | 08/10/91 | DELPHI BETRAYAL | 20 | 2.55 | 2.5500 | 51.00 |
6430 | 09/28/91 | DELPHI BETRAYAL | 30 | 2.55 | 2.4225 | 72.68 |
AVERAGE ORDER: 25 TOTAL DUE FOR DELPHI BETRAYAL | 123.68 |
CUST NO | OR DATE | BOOK TITLE | QTY | UNIT PRICE | DISC PRICE | AMT DUE |
2242 | 09/01/91 | JERICHO MAN | 35 | 1.99 | 1.6915 | 59.20 |
3529 | 10/10/91 | JERICHO MAN | 35 | 1.99 | 1.9900 | 69.65 |
AVERAGE ORDER: 35 TOTAL DUE FOR JERICHO MAN | 128.85 |
CUST NO | OR DATE | BOOK TITLE | QTY | UNIT PRICE | DISC PRICE | AMT DUE |
2242 | 09/01/91 | MAYDAY MAYDAY | 40 | 2.78 | 2.3630 | 94.52 |
6540 | 10/05/91 | MAYDAY MAYDAY | 25 | 2.78 | 2.7800 | 69.50 |
AVERAGE ORDER: 32 TOTAL DUE FOR MAYDAY MAYDAY | 164.02 | |||||
THE TOTAL AMOUNT DUE IS: | 669.75 |
When a single Data Set (DS) is to be updated without a transaction set, the ALTER command with a Process Module (PM) is generally used. An “ALTER PM” can include the following sections:
- CONTROL - to relate the DS for UPDATE
- DECLARE - to establish local fields
- INITIAL - to execute any task required before record processing begins.
- DETAIL - to update the records
- FINAL - to display information of job completion
The only sections required are a CONTROL section and one Record Processing section. Other sections that might be used are BEFORE, AFTER and UNQUALIFIED. If a SET clause or SHOWING clause is used in the command, the order in which sections and clauses execute might affect the decision of where to put modifying statements for qualified records (see the flow diagram for ALTER Process Modules later in this section).
In the following example, a book distributor is updating the records in a DS named MYSTRY. The distributor wants to calculate the amount owed by each customer. Note that the fields for discounted price and amount due in the data set MYSTRY are empty before the ALTER command is executed. The PM calculates the discounted price and the amount due, reflecting all available discounts.
The customer receives a discount if he has purchased over 25 copies of a title ordered some time before the November 15 ship date. Specifically, if he has ordered the books 60 days before shipment, he pays 75% of the normal price; if he orders 30 or 14 days before shipment, he pays 85% or 95%, respectively. Both the INITIAL and FINAL sections are used to display messages on the terminal screen.
The preceding example, for reporting, shows this DS after updating, and also shows a reporting PM that is used on the updated DS. The next example combines the updating and reporting into one PM.
*USE DS MYSTRY DI MYSTRY*STRUCTURECUSTNO INT 5SHIPDATE DATEORDATE DATEBKTITLE CHAR 16QTY_PUR INT 4UNITPRICE FLOAT 4 2DISCPRICE FLOAT 6 4AMTDUE FLOAT 7 2*LIST DI MYSTRY00100 INDEX TYPE IS RAM00110 INDEX TO MYSTRY00120 DOMAIN BKTITLE ON BKTITLE*EXTRACT1123 10/15/91 08/01/91 ALEPH SOLUTION 30 2.11 .0000 .006430 10/15/91 09/28/91 ALEPH SOLUTION 40 2.11 .0000 .006674 10/15/91 09/12/91 ALEPH SOLUTION 45 2.11 .0000 .007432 10/15/91 09/02/91 ALEPH SOLUTION 25 2.11 .0000 .005234 10/15/91 08/10/91 DELPHI BETRAYAL 20 2.55 .0000 .006430 10/15/91 09/28/91 DELPHI BETRAYAL 30 2.55 .0000 .002242 10/15/91 09/01/91 JERICHO MAN 35 1.99 .0000 .003529 10/15/91 10/10/91 JERICHO MAN 35 1.99 .0000 .002242 10/15/91 09/01/91 MAYDAY MAYDAY 40 2.78 .0000 .006540 10/15/91 10/05/91 MAYDAY MAYDAY 25 2.78 .0000 .00*LIST PM UP_INVOICE00005 !==============00010 CONTROL SECTION00015 !==============00020 RELATE DI MYSTRY AS MASTER FOR UPDATE00030 !00035 !==============00040 DECLARE SECTION00045 !==============00050 DISCOUNT,FLOAT,4,200060 !00065 !==============00070 INITIAL SECTION00075 !==============00080 TYPE "UPDATING INVOICES FOR NEW MYSTERIES"00090 TYPE "QUANTITY AND EARLY ORDER DISCOUNTS GIVEN.",@CR00100 !00105 !=============00110 DETAIL SECTION00115 !=============00120 IF QTY_PUR >= 2500130 IF:2 SHIPDATE - ORDATE >= 6000140 .75 TO DISCOUNT:D00150 ORIF:2 SHIPDATE - ORDATE >= 3000160 .85 TO DISCOUNT:D00170 ORIF:2 SHIPDATE - ORDATE >= 1500180 .95 TO DISCOUNT:D00190 ELSE:200200 1 TO DISCOUNT:D00210 ELSE00220 1 TO DISCOUNT:D00230 CONTINUE00240 UNITPRICE * DISCOUNT:D * QTY_PUR TO AMTDUE00250 DISCOUNT:D * UNITPRICE TO DISCPRICE00260 !00265 !============00270 FINAL SECTION00275 !============00280 TYPE "THE TOTAL AMOUNT DUE IS: ", SUM AMTDUE*ALTER VIA UP_INVOICE UPDATING INVOICES FOR NEW MYSTERIES QUANTITYAND EARLY ORDER DISCOUNTS GIVENTHE TOTAL AMOUNT DUE IS: 669.75*EXTRACT1123 10/15/91 08/01/91 ALEPH SOLUTION 30 2.11 1.5825 47.486430 10/15/91 09/28/91 ALEPH SOLUTION 40 2.11 2.0045 80.186674 10/15/91 09/12/91 ALEPH SOLUTION 45 2.11 1.7935 80.717432 10/15/91 09/02/91 ALEPH SOLUTION 25 2.11 1.7935 44.845234 10/15/91 08/10/91 DELPHI BETRAYAL 20 2.55 2.5500 51.006430 10/15/91 09/28/91 DELPHI BETRAYAL 30 2.55 2.4225 72.682242 10/15/91 09/01/91 JERICHO MAN 35 1.99 1.6915 59.203529 10/15/91 10/10/91 JERICHO MAN 35 1.99 1.9900 69.652242 10/15/91 09/01/91 MAYDAY MAYDAY 40 2.78 2.3630 94.526540 10/15/91 10/05/91 MAYDAY MAYDAY 25 2.78 2.7800 69.50
Whenever a report is desired after a DS has been altered, the reporting statements should be included in the PM that does the altering. Combining functions in one PM makes the operation more efficient, as only one pass is required through the DS or DI.
Since a PM called by REPORT does not allow changes to records, a PM that combines functions should be called by the command that controls the other function. The reports can be looked at as an automatic by-product of the primary function.
A PM called by ALTER can contain any section except those record processing sections that apply to processing with a transaction set. The sections allowed are:
AFTER BEFORE CONTROL DECLARE DETAIL EXCEPTIONS FINAL FOOTINGS |
HEADINGS INITIAL PROCESS SUBHEADINGS TITLES TOTALS UNQUALIFIED |
The only sections required are the CONTROL section and one record processing section. If a report is being created, the HEADINGS section is generally used to provide column headings. Beyond that, the inclusion of other sections depends on the requirements of the application.
Example of Altering & Reporting
The following example is a PM that alters the DS and reports on the alterations. It combines the functions accomplished in the preceding two examples. Comparison of this PM with the previous two will show that all statements and sections from each PM are included. Note that the PRINT statement follows the manipulating statements in the DETAIL section, so that the record is printed in the report after all changes have taken place.
*LIST PM UP_DUE00005 !==============00010 CONTROL SECTION00015 !==============00020 RELATE DI MYSTRY AS MASTER FOR UPDATE00030 RELATE SF DUE AS REPORT 100040 !00045 !==============00050 DECLARE SECTION00055 !==============00060 DISCOUNT, FLOAT, 4, 200070 !00075 !==============00080 INITIAL SECTION00085 !==============00090 TYPE "UPDATING INVOICES FOR NEW MYSTERIES"00100 TYPE "QUANTITY AND EARLY ORDER DISCOUNTS GIVEN.", @CR00110 !00115 !==============00120 HEADINGS SECTION00125 !==============00130 PRINT00140 CENTER "SUMMARY REPORT FOR MYSTERY TITLES" AT 4000150 PRINT00160 CENTER "PREPARED ON " + @FDATE AT 4000170 PRINT00180 PRINT "CUSTNO ORDATE BOOK TITLE QTY UNITPRICE DISCPRICE"&"AMTDUE",@CR00190 !00195 !=============00200 DETAIL SECTION00205 !=============00210 IF QTY_PUR >= 2500220 IF:2 SHIPDATE - ORDATE >= 6000230 .75 TO DISCOUNT:D00240 ORIF:2 SHIPDATE - ORDATE >= 3000250 .85 TO DISCOUNT:D00260 ORIF:2 SHIPDATE - ORDATE >= 1500270 .95 TO DISCOUNT:D00280 ELSE:200290 1 TO DISCOUNT:D00300 ELSE00310 1 TO DISCOUNT:D00320 CONTINUE00330 UNITPRICE * DISCOUNT:D * QTY_PUR TO AMTDUE00340 DISCOUNT:D * UNITPRICE TO DISCPRICE00350 PRINT CUSTNO,3B,ORDATE,2B,BKTITLE,QTY_PUR, 4B,UNITPRICE,&6B, DISCPRICE @"D.DDDD",3B,AMTDUE00360 !00365 !=============00370 TOTALS SECTION00375 !=============00380 ON BKTITLE00390 PRINT 5B,"AVERAGE ORDER:",AVG QTY_PUR,15B, &"TOTAL DUE FOR", BKTITLE, SUM AMTDUE,@CR00400 !00405 !=============00410 FINAL SECTION00415 !=============00420 TYPE "THE TOTAL AMOUNT DUE IS: ", SUM AMTDUE00430 PRINT 44B,"THE TOTAL AMOUNT DUE IS: ", SUM AMTDUE00440 TYPE "THE REPORT IS AVAILABLE IN THE FILE DUE.REP"After the DS and DI are declared, this PM is invoked with the ALTER command.
*USE DS MYSTRY DI MYSTRY*ALTER VIA UP_DUE
When a DS is to be updated with values from a transaction DS, the UPDATE command is used. The transaction can be used as a read only DS, or it can also be updated. The matching master and transaction records are processed against one another in the MATCHED section. Therefore, statements that update master records with transaction values, or transaction records with master values, must go in the MATCHED section. The other record processing sections can also be used for updating matched records. A PM used only for updating would include some or all of the following sections.
CONTROL |
to relate master for UPDATE and transaction for either INPUT or UPDATE. |
DECLARE |
to establish local fields and picture formats for output statements. |
INITIAL |
to establish initial values or display messages on the terminal screen. |
BEFORE:M |
to update qualified master records, both matched and unmatched. |
UNMATCHED:M |
to update qualified master records, unmatched master records. |
AFTER:M |
to update qualified master records, both matched and unmatched. |
UNQUALIFIED:M |
to update unqualified master records only. |
MATCHED |
to update matched master or transaction records. |
BEFORE:T |
to update qualified transaction records, both matched and unmatched. |
UNMATCHED:T |
to update qualified transaction records, unmatched transaction records. |
AFTER:T |
to update qualified transaction records, both matched and unmatched. |
UNQUALIFIED:T |
to update unqualified transaction records. |
TOTALS |
to calculate subtotals for displaying on the terminal screen, save in global storage or write to an auxiliary data set. |
FINAL |
to calculate totals for displaying on the terminal screen, save in global storage or write to an auxiliary data set. |
This example updates both the master and transaction DS. The user is a publisher who is updating the records in a master DS NEW_BOOKS with information from a transaction DS named ORDERS. NEW_BOOKS contains information about the publisher’s current inventory. ORDERS contains information about the orders from book stores.
The SD and contents of both DS’s are shown below.
*USE DS NEW_BOOKS*STRUCTURETITLE_CODE CHAR 6TYPE_CODE CHAR 12QTY_ONHAND INT 6QTY_SHIPPED INT 6RESTOCK INT 6*SORT ON TITLE_CODE, TYPE_CODE*EXTRACTCP2264 computer 150 0 0CP3681 computer 100 0 0FL0839 for_lang 60 0 0FL2772 for_lang 70 0 0HI0034 history 630 0 0MY4312 mystery 0 0 0TR7022 travel 350 0 0TR7657 travel 20 0 0*USE DS ORDERS*STRUCTURESTORE_CODE CHAR 4TITLE_CODE CHAR 6TYPE_CODE CHAR 12QTY_ORDERED INT 6QTY_SHIPPED INT 6*SORT ON TITLE_CODE, STORE_CODE*EXTRACT6359 CP2264 computer 100 06360 CP2264 computer 45 05742 FL0839 for_lang 75 06360 FL2772 for_lang 25 07106 FL2772 for_lang 30 06418 HI0034 history 65 05742 TR7022 travel 200 07238 TR7657 travel 30 01234 ZZ1109 govt 10 0PM DAILY (shown below) matches each order from the transaction set ORDERS with the current inventory NEW_BOOKS on TITLE_CODE and TYPE_CODE. The MATCHED section processes each master record that has at least one matching transaction. If enough books are in stock to fill an order, they are shipped to the store. NEW_BOOKS is updated to reflect the transaction. If more books are ordered than are in stock, the order is partially filled.
Note that the transaction set is also updated to show the number shipped. The SETUP statement in line 100 sets a flag so that, at the end of the Record Processing sections, the updated transaction record is rewritten to the transaction set.
In the UNMATCHED:M section, the user examines the master DS for out-of-stock books. If no store has requested the book, the record for that book is omitted from the master set.
After each master record has been processed by either the MATCHED or UNMATCHED:M section, it goes through the AFTER:M section. Therefore, this is the place to determine whether the stock of any book has been depleted by the day’s orders. If any stock has fallen below 10, line 250 automatically sets the reorder quantity to 200.
If an ordered book does not appear in the publisher’s inventory (an unmatched transaction), a new record is created for that book in the master DS, so that the publisher can obtain the book and fill the order (lines 270-330). New records are appended to the end of the DS.
*LIST PM DAILY00010 !00015 !==============00020 CONTROL SECTION00025 !==============00030 RELATE DS NEW_BOOKS AS MASTER FOR UPDATE00040 RELATE DS ORDERS AS TRANSACTION FOR UPDATE00050 !00055 !==============00060 INITIAL00065 !==============00070 TYPE "UPDATING OF BOOK INVOICES FOR ", @DATE, @CR00080 !00085 !==============00090 MATCHED00095 !==============00100 SETUP TO REWRITE TRANSACTION00110 IF QTY_ONHAND:M < QTY_ORDERED:T00120 QTY_ONHAND:M TO QTY_SHIPPED:T00125 QTY_SHIPPED:M + QTY_SHIPPED:T TO QTY_SHIPPED:M00130 0 TO QTY_ONHAND:M00140 ELSE00150 QTY_ONHAND:M - QTY_ORDERED:T TO QTY_ONHAND:M00160 QTY_ORDERED:T + QTY_SHIPPED:M TO QTY_SHIPPED:M00170 QTY_ORDERED:T TO QTY_SHIPPED:T00180 !00185 !==============00190 UNMATCHED:M00195 !==============00200 IF QTY_ONHAND:M = 0 AND RESTOCK:M = 000210 SETUP TO OMIT MASTER00220 TYPE"RECORD FOR BOOK",TITLE_CODE:M,1B, TYPE_CODE:M, &"OMITTED",@CR00230 !00235 !=============00240 AFTER:M00245 !=============00250 200 TO RESTOCK:M IF QTY_ONHAND:M < 1000260 !00265 !=============00270 UNMATCHED:T SECTION00285 !==============00280 READY MASTER00290 TITLE_CODE:T TO TITLE_CODE:M:R00300 TITLE_CODE:T TO TITLE_CODE:M:R00310 0 TO QTY_ONHAND:M:R00320 200 TO RESTOCK:M:R00330 CREATE MASTER HUSHThis PM is invoked by the UPDATE command. The interaction is as follows:
*USE DS NEW_BOOKS*UPDATE WITH ORDERS MATCH ON TITLE_CODE,TYPE_CODE VIA DAILY UPDATING OF BOOK INVOICES FOR 07/19/91RECORD FOR BOOK MY4312 mystery OMITTED.The master and transaction sets, after updating, are shown below.
*USE DS NEW_BOOKS*EXTRACTCP2264 computer 5 145 200CP3681 computer 100 0 0FL0839 for_lang 0 60 200FL2772 for_lang 15 55 0HI0034 history 565 65 0TR7022 travel 150 200 0TR7657 travel 0 20 200ZZ1109 govt 0 0 200*USE DS ORDERS*EXTRACT6359 CP2264 computer 100 1006360 CP2264 computer 45 455742 FL0839 for_lang 75 606360 FL2772 for_lang 25 257106 FL2772 for_lang 30 306418 HI0034 history 65 655742 TR7022 travel 200 2007238 TR7657 travel 30 201234 ZZ1109 govt 10 0
When updating and reporting are combined in one PM, the PM is invoked with the UPDATE command. It is possible to report on either master records or transaction records, as well as to update both DS's. You can create up to 10 separate reports during a single pass of the records.
A PM invoked by UPDATE can include any sections except those reserved for simple processing (without a transaction DS). The sections allowed are as follows:
CONTROL DECLARE PROCESS INITIAL TITLES HEADINGS SUBHEADINGS FOOTINGS BEFORE:M MATCHED |
UNMATCHED:M AFTER:M UNQUALIFIED:M BEFORE:T UNMATCHED:T AFTER:T UNQUALIFIED:T TOTALS FINAL EXCEPTIONS |
The only sections required are the CONTROL section and one of the record processing sections. When a report is being created, the HEADINGS section is generally used. Beyond that, the inclusion of other sections depends on the requirements of the application.
Example of Updating & Reporting
This example builds on the preceding example of updating. PM COMPLETE, shown below, does exactly the same updating as was done before; in addition, it creates three reports. Two reports are derived from the master DS - one listing all current stock and the other listing the books that must be reordered. The third report, derived from the transaction set, shows which orders were filled, and which were back ordered.
All updating statements are identical to those shown in PM DAILY and are in the same sections (see preceding example for explanations). The additional sections and statements are all used to create the reports.
The DECLARE section creates three declared fields that are used to count the number of filled orders, partial shipments, and unfilled orders. These fields are incremented in the AFTER:T section and the final values are written to the report on shipments.
The PRINT statements that create the reports always follow the statements that update the desired records, so that records are reported after all processing that affects them is completed. Thus the PRINT statements for master records are in the AFTER:M section and those for the transaction records are in the AFTER:T section.
In the UNMATCHED:T section, new master records are created for any books that have been ordered by stores but are not currently stocked by the publisher. Each new record is built up field by field in a special buffer called the ready area. When the record is completed, it is compiled and written to the master DS. READY and CREATE are special statements that allow you to create new Master or Transaction Records. Master records are not available to any statements in the UNMATCHED:T section except READY and CREATE. You can use fields from the transaction record to create new master records with the READY Master and CREATE statements, PRINT statements in this section cannot print the new records from the master DS. However, PRINT statements can access the records in the ready area. Thus each field included in the two print statements must carry the double suffix :M:R.
*LIST PM COMPLETE00010 !00015 !==============00020 CONTROL SECTION00025 !==============00030 RELATE DS NEW_BOOKS AS MASTER FOR UPDATE00040 RELATE DS ORDERS AS TRANSACTION FOR UPDATE00050 RELATE SF CURSTK AS REPORT 100060 RELATE SF RESTK AS REPORT 200070 RELATE SF DONE AS REPORT 300080 !00085 !==============00090 DECLARE SECTION00095 !==============00100 FILLED,INT,300110 PART_FILL,INT,300120 UNFILL,INT,300130 !00135 !==============00140 INITIAL00145 !==============00150 TYPE "UPDATING OF BOOK INVOICES FOR", @DATE, @CR00160 2 TO @FOOTING_SIZE(3)00170 !00175 !==============00180 HEADINGS SECTION00185 !==============00190 REPORT 100200 SKIP 100210 CENTER "CURRENT BOOK STOCK" AT 1500220 SKIP 100230 CENTER @FDATE AT 1500240 SKIP 100250 PRINT"TITLE_CODE",3B,"TYPE_CODE",2B,&"ON HAND",2B,"RESTOCK"00260 !00270 REPORT 200280 PRINT @CR, "RESTOCK LIST AS OF ", @FDATE, @CR00290 PRINT "TITLE_CODE",3B,"TYPE_CODE",2B,"RESTOCK QTY"00300 !00310 REPORT 300320 SKIP 100330 CENTER "ORDERS SHIPPED ON " + @FDATE AT 2800340 SKIP 100350 PRINT"STORE_CODE",2B,"TITLE_CODE",3B,"TYPE_CODE",&3B,"ORDERED",2B,"SHIPPED",2B,"BACKORDERED",2B00360 !00365 !==============00370 FOOTINGS SECTION00375 !==============00380 REPORT 300390 PRINT @CR, 5B, "P = PARTIAL SHIPMENT"00400 !00405 !==============00410 MATCHED00415 !==============00420 SETUP TO REWRITE TRANSACTION00430 IF QTY_ONHAND:M < QTY_ORDERED:T00440 QTY_ONHAND:M TO QTY_SHIPPED:T00450 QTY_SHIPPED:M + QTY_SHIPPED:T TO QTY_SHIPPED:M00460 0 TO QTY_ONHAND:M00470 ELSE00480 QTY_ONHAND:M - QTY_ORDERED:T TO QTY_ONHAND:M00490 QTY_ORDERED:T + QTY_SHIPPED:M TO QTY_SHIPPED:M00500 QTY_ORDERED:T TO QTY_SHIPPED:T00510 !00515 !==============00520 UNMATCHED:M00525 !==============00530 IF QTY_ONHAND:M = 0 AND RESTOCK:M = 000540 SETUP TO OMIT MASTER00550 TYPE"RECORD FOR BOOK ",TITLE_CODE:M,1B, TYPE_CODE:M, &"OMITTED",@CR00570 !00575 !==============00580 UNMATCHED:T SECTION00585 !==============00590 READY MASTER00600 TITLE_CODE:T TO TITLE_CODE:M:R00600 TITLE_CODE:T TO TITLE_CODE:M:R00620 0 TO QTY_ONHAND:M:R00630 200 TO RESTOCK:M:R00640 CREATE MASTER HUSH00650 PRINT ON 1 TITLE_CODE:M:R,2B,TYPE_CODE:M:R,2B, &QTY_ONHAND:M:R 5B,RESTOCK:M:R,&3B,"(NEW)"00660 PRINT ON 2 TITLE_CODE:M:R, 2B, TYPE_CODE:M:R,5B, &RESTOCK:M:R, 3B,"(NEW)"00670 !00675 !==============00680 AFTER:M00685 !==============00700 200 TO RESTOCK:M IF QTY_ONHAND:M < 1000710 PRINT ON 1 TITLE_CODE,2B,TYPE_CODE,2B,QTY_ONHAND,5B,RESTOCK00720 PRINT ON 2 TITLE_CODE,2B,TYPE_CODE,5B,RESTOCK IF RESTOCK>000730 !00735 !==============00740 AFTER:T SECTION00745 !==============00750 PRINT ON 3 STORE_CODE:T,4B,TITLE_CODE:T,1B,TYPE_CODE:T, &3B, QTY_ORDERED:T,NOCR00760 IF QTY_SHIPPED:T = QTY_ORDERED:T00770 PRINT ON 3 5B, QTY_SHIPPED:T00780 INCR FILLED:D00790 ELSE00800 IF:5 QTY_SHIPPED:T = 000810 PRINT ON 3 14B, QTY_ORDERED:T00820 INCR UNFILL:D00830 ELSE:500840 PRINT ON 3 5B,QTY_SHIPPED:T,1B,"P",4B, &QTY_ORDERED:T QTY_SHIPPED:T@"ZZZ"00850 INCR PART_FILL:D00860 !00865 !==============00870 FINAL SECTION00875 !==============00880 PRINT ON 3 @CR,"THE NUMBER OF FILLED ORDERS IS:",6B,FILLED:D00890 PRINT ON 3 "THE NUMBER OF UNFILLED ORDERS IS:",4B,UNFILL:D00900 PRINT ON 3 "THE NUMBER OF PART FILLED ORDERS IS:",PART_FILL:D00910 TYPE"REPORT ON CURRENT STOCK IS IN THE FILE CURSTK.REP."00920 TYPE"RESTOCK REPORT IS IN THE FILE RESTK.REP."00930 TYPE"REPORT ON SHIPMENTS IS IN THE FILE DONE.REP."The PM COMPLETE is invoked with the UPDATE command, and displays several messages to the terminal while it is executing.
*USE DS NEW_BOOKS*UPDATE WITH ORDERS MATCH ON TITLE_CODE, TYPE_CODE VIA COMPLETE UPDATING OF BOOK INVOICES FOR 7/19/91RECORD FOR BOOK MY4312 mystery OMITTED.REPORT ON CURRENT STOCK IS IN THE FILE CURSTK.REP.RESTOCK REPORT IS IN THE FILE RESTK.REP.REPORT ON SHIPMENTS IS IN THE FILE DONE.REP.The three reports produced by PM COMPLETE are shown in the following text. Notice that the new records are reported in correct sequence in the first and second reports, even though they are appended to the end of the master DS.
*LIST SF CURSTK.REP
CURRENT BOOK STOCK
JUL 19, 1991
TITLE_CODE | TYPE_CODE | ON HAND | RESTOCK | |
CP2264 | computer | 5 | 200 | |
CP3681 | computer | 100 | 0 | |
FL0839 | for_lang | 0 | 200 | |
FL2772 | for_lang | 15 | 0 | |
HI0034 | history | 565 | 0 | |
TR7022 | travel | 150 | 0 | |
TR7657 | travel | 0 | 200 | |
ZZ1109 | govt | 0 | 200 | (NEW) |
*LIST SF RESTK.REP
RESTOCK LIST AS OF JUL 19, 1991
TITLE_CODE | TYPE_CODE | RESTOCK QTY | |
CP2264 | computer | 200 | |
FL0839 | for_lang | 200 | |
TR7657 | travel | 200 | |
ZZ1109 | govt | 200 | (NEW) |
*LIST SF DONE.REP
ORDERS SHIPPED ON JUL 19, 1991
STORE_CODE
|
TITLE_CODE
|
TYPE_CODE
|
ORDERED
|
SHIPPED
|
BACKORDERED
|
6359
|
CP2264
|
computer
|
100
|
100
|
|
6360
|
CP2264
|
computer
|
45
|
45
|
|
5742
|
FL0839
|
for_lang
|
75 P
|
60
|
15
|
6360
|
FL2772
|
for_lang
|
25
|
25
|
|
7106
|
FL2772
|
for_lang
|
30
|
30
|
|
6418
|
HI0034
|
history
|
65
|
65
|
|
5742
|
TR7022
|
travel
|
200
|
200
|
|
7238
|
TR7657
|
travel
|
30 P
|
20
|
10
|
1234
|
ZZ1109
|
govt
|
10
|
10
|
THE NUMBER OF FILLED ORDERS IS: 6THE NUMBER OF UNFILLED ORDERS IS: 1THE NUMBER OF PART FILLED ORDERS IS: 2P = PARTIAL SHIPMENT
It is frequently necessary, in an active application, to modify the structure or format of the Data Sets (DS). ACCENT R provides a number of convenient ways to do this.
The utility SDMOD, which is stored in the public DBL NIS:ACCSDM, is the simplest method.
Another way is to use the CONVERT command. It can change field types, names, or sizes, change storage form, modify data, and add or delete fields without a PM.
For DS’s with multiple record types or when fields require complex manipulations, a PM invoked by EXTRACT can be used. The new DS is related as an auxiliary DS for CREATE. Records are built up field by field in the ready area, then written to the auxiliary DS with the CREATE statement. It is possible to accept field values interactively or to leave fields empty for later updating. For DS’s with multiple record types, IF nests are used to create the records of each type.
A PM used for converting need include only two sections:
CONTROL - to relate the old set as master for INPUT and the new set as an auxiliary for CREATE.- DETAIL - to create the new records.
The PM could include any sections except those record processing sections reserved for join commands. The UNQUALIFIED section might be used if the old DS is being split up, qualified records to one new DS and unqualified records to another new DS. Reporting sections could be used if reports are being created for documenting the changes.
The following example converts a multiple record type DS. The structure of the current DS, and the data therein, are shown below.
*USE DS MULDAT*STRUCTURERECORD OLD_BOOKRT CHAR 1TITLE_CODE CHAR 6NOTES CHAR 20ONHAND INT 6ONORDER INT 6PRICE FLOAT 7 2RECORD LIBRT CHAR 1TITLE_CODE CHAR 6LIBNO INT4RECORD RETAILRT CHAR 1TITLE_CODE CHAR 6TYPE_CODE CHAR 12STORE_CODE CHAR 4QTY_ORDERED INT 4ORDER_DATE DATE*EXTRACTO CP2264 slow 25 0 7.99O FL4049 sale 5 20 15.25L TR7022 MM25R TR7022 5789 20 04/13/91L MY4312 ML09R ZZ1019 7089 15 08/08/91O SF8812 hot 70 100 10.00The user wants to remove the field ONORDER from OLD_BOOK records, and add fields to the RETAIL records to show the quantity shipped and the shipped date. The current SD is copied to a new name, then modified to reflect the desired changes. Then the user creates a new DS to reflect the new SD. The new SD is shown below.
*USE DS MDAT*STRUCTURERECORD OLD_BOOKRT CHAR 1TITLE_CODE CHAR 6TYPE_CODE CHAR 12NOTES CHAR 20ONHAND INT 6PRICE FLOAT 7 2RECORD LIBRT CHAR 1TITLE_CODE CHAR 6LIBNO INT 4ZONE INT 2RECORD RETAILRT CHAR 1TITLE_CODE CHAR 6STORE_CODE CHAR 4QTY_ORDERED INT 4ORDER_DATE DATESHIPPED_QTY INT 4SHIPPED_DATE DATEThe PM MODSET, shown below, relates the current DS as master and the new, empty DS, as an auxiliary for creating new records. READY new, prepares an area where each new record will be built, field by field. CREATE AUX, writes the new record to the auxiliary DS.
For each record type, the fields from the old DS are moved into the ready area. For LIB records, values for the new field ZONE are accepted interactively while the PM is executing.
*LIST PM MODSET00010 !00015 !==============00020 CONTROL SECTION00025 !==============00030 RELATE DS MULDAT AS MASTER FOR INPUT00040 RELATE DS MDAT AS New FOR CREATE00050 !00055 !==============00060 DETAIL SECTION00065 !==============00070 READY New00080 !00090 IF RT = "O"00100 RT:M TO RT:New00110 TITLE_CODE:M TO TITLE_CODE:New HUSH00120 TYPE_CODE:M TO TYPE_CODE:New HUSH00130 ONHAND:M TO ONHAND:New HUSH00140 PRICE:M TO PRICE:New HUSH00150 NOTES:M TO NOTES:New HUSH00160 !00170 ORIF RT = "L"00180 RT:M TO RT:New HUSH00190 TITLE_CODE:M TO TITLE_CODE:New HUSH00200 LIBNO:M TO LIBNO:New HUSH00210 TYPE "PLEASE ENTER ZONE FOR LIB", LIBNO, ":", NOCR00220 ACCEPT ZONE:New00230 !00240 ELSE00250 RT:M TO RT:New HUSH00260 TITLE_CODE:M TO TITLE_CODE:New HUSH00270 STORE_CODE:M TO STORE_CODE:New HUSH00280 QTY_ORDERED:M TO QTY_ORDERED:New HUSH00290 ORDER_DATE:M TO ORDER_DATE:New HUSH00300 CONTINUE00310 !00320 CREATE NewAfter the PM is executed, the new DS is displayed. The new integer field QTY_SHIPPED in RETAIL records is filled with zeros, since no data was supplied. The other empty field, SHIP_DATE, is a date field and contains no date which displays as asterisks.
*USE DS MULDAT*EXTRACT VIA MODSETPLEASE ENTER ZONE FOR LIB MM25: 15 PLEASE ENTER ZONE FOR LIB ML09: 17*USE DS MDAT*EXTRACTO CP2264 slow 25 7.99O FL4049 sale 5 15.25L TR7022 MM25 15R TR7022 5789 20 04/13/91 0 ********L MY4312 ML09 17R ZZ1019 7089 15 08/08/91 0 ********O SF8812 hot 70 10.00
The Data Manipulation commands provide many pre-programmed features to speed information retrieval and manipulation. These features have been designed to handle the tasks of data base management that are common to most applications. PM's take advantage of the automatic features of commands while tailoring them to fit any unique situation.
Example of Customizing a Command
In the following example, the user finds that most requirements of an updating operation can be handled by automatic features of the CHANGE command: record retrieval, display of old values, accepting new values, duplicating identical field values in succeeding records, and creating the environment to enter new records. By using a simple PM, the user extends the capabilities of the CHANGE command to fit special requirements. The CHANGE command is as follows:
*CHANGE BY ID FIELDS THRU NAME SHOWING &"Author Code:",ACODE@"",3S, "Author Name:",AUTHOR@""&DUPLICATE NO CHECK&ENTER FIELDS PHONE,ADDRESS,CITY,STATE,ZIP,COUNTRY,CONTRACT&WITH PROMPTS&VIA MAIL_UPDATE EQUATE $@STRING(3) TO CODESThe PM called by CHANGE automates the assignment of dates and numbers to records. An auxiliary DS, MAILCD, contains the highest company number assigned to any record in the Master DS, MAIL. When a new record is added to MAIL, the number in MAILCD is incremented, and the new number is assigned to the new record in MAIL. The PM also assigns today’s date as the creation date for a new record. If a record is being changed, today’s date is recorded as the last change date. The PM is shown below.
*LIST PM MAIL_UPDATE00010 CONTROL00020 RELATE SD MAIL AS MASTER FOR UPDATE00030 RELATE SD MAILCD AS CODES FOR UPDATE00040 !00050 DETAIL00060 IF @OPER="ENTER"00070 GET FIRST FROM CODES00080 ADD 1 TO LAST_NUM:CODES00090 PUT CODES00100 TYPE "***Author Code:",LAST_NUM:CODES@"",1S,"Assigned."00110 DATE TO CREATE_DATE:M00120 CONTINUE00130 @DATE TO CHANGE_DATE:M
Stand-alone PM's are used for data manipulation when some unique situation makes the program model of standard PM’s inapplicable.
Stand-alone PM’s can be used:
with auxiliary DS for completely random retrieval- with a DS that has its own pointer system (one record pointing to another)
- to do non-sequential retrieval under program control
If record retrieval is sequential, either directly or through a DI, then the PM should be designed for use with one of the Data Manipulation commands. The built-in features of such PM’s can substantially reduce programming time.
Example Of A Stand - Alone Process Module
The following example shows a simple stand-alone PM. It is used for making calculations based on values entered interactively. All calculations and user interactions are included in the FINAL section. Response to prompts are in bold print.
*LIST PM ROYALTY00010 !This PM figures the royalty expense per order.00015 !00020 !==============00020 DECLARE SECTION00025 !==============00030 QTY_ORDER, INT, 600040 PRICE, FLOAT, 10, 200050 ROY_PCT, FLOAT, 300060 ROY_EXP, FLOAT, 10, 200070 !00075 !==============00080 FINAL SECTION00085 !==============00090 !00100 ! get information00110 TYPE @CR, "ORDER QUANTITY FOR BOOK: ", NOCR00120 ACCEPT QTY_ORDER00130 TYPE "BOOK PRICE: ", NOCR00140 ACCEPT PRICE00150 TYPE "BOOK ROYALTY % (Ex: .05): ", NOCR00160 ACCEPT ROY_PCT00170 !00180 ! calculate entries00190 QTY_ORDER * PRICE * ROY_PCT TO ROY_EXP0020000210 ! display information00220 TYPE @CR,"ROYALTY EXPENSE FOR ORDER:$",ROY_EXP*USE PM ROYALTYBOOK PRICE: $5.35BOOK ROYALTY % (EX: .05):.15ROYALTY EXPENSE FOR ORDER: $ 16.05