Using Process Modules

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.

Reporting

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.

Inter-Record Functions

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 3

To 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 SECTION
00305 FLD(1) + FLD(2) + FLD(3) TO FLDTOT :
:
00625 FINAL SECTION
00630 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):

Example of Reporting

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
*STRUCTURE
CUSTNO INT 5
SHIPDATE DATE
ORDATE DATE
BKTITLE CHAR 16
QTY_PUR INT 4
UNITPRICE FLOAT 4 2
DISCPRICE FLOAT 6 4
AMTDUE FLOAT 7 2
*EXTRACT
1123  10/15/91   08/01/91 ALEPH SOLUTION   30  2.11  1.5825  47.48
6430  10/15/91   09/28/91 ALEPH SOLUTION   40  2.11  2.0045  80.18
6674  10/15/91   09/12/91 ALEPH SOLUTION   45  2.11  1.7935  80.71
7432  10/15/91   09/02/91 ALEPH SOLUTION   25  2.11  1.7935  44.84
5234  10/15/91   08/10/91 DELPHI BETRAYAL  20  2.55  2.5500  51.00
6430  10/15/91   09/28/91 DELPHI BETRAYAL  30  2.55  2.4225  72.68
2242  10/15/91   09/01/91 JERICHO MAN      35  1.99  1.6915  59.20
3529  10/15/91   10/10/91 JERICHO MAN      35  1.99  1.9900  69.65
2242  10/15/91   09/01/91 MAYDAY MAYDAY    40  2.78  2.3630  94.52
6540  10/15/91   10/05/91 MAYDAY MAYDAY    25  2.78  2.7800  69.50
*LIST PM DUE
00095  !==============
00100  CONTROL SECTION
00105  !==============
00110  RELATE DI MYSTRY AS MASTER FOR INPUT
00120  RELATE SF DUE AS REPORT 1
00160  !
00165  !===============
00170  HEADINGS SECTION
00175  !===============
00175  PRINT
00180  CENTER "SUMMARY REPORT FOR MYSTERY TITLES" AT 40
00190  PRINT
00200  CENTER "PREPARED ON " + @FDATE AT 40
00210  PRINT
00220  PRINT "CUSTNO  ORDATE  BOOK  TITLE  QTY ","  UNITPRICE&
         DISCPRICE   AMTDUE",@CR
00230  !
00235  !=============
00240  DETAIL SECTION
00245  !=============
00250  PRINT CUSTNO,3B,ORDATE,2B,BKTITLE,QTY_PUR,&
         4B,UNITPRICE,6B, DISCPRICE @"D.DDDD",3B,AMTDUE
00260  !
00265  !=============
00270  TOTALS SECTION
00275  !=============
00280  ON BKTITLE
00290  PRINT 5B,"AVERAGE ORDER:",AVG QTY_PUR,15B,&
         "TOTAL DUE FOR", BKTITLE, SUM AMTDUE,@CR
00300  !
00305  !============
00310  FINAL SECTION
00315  !============
00320  PRINT 44B, "THE TOTAL AMOUNT DUE IS: ", SUM AMTDUE
00330  TYPE "THE REPORT IS AVAILABLE IN THE FILE DUE.REP"
*REPORT VIA DUE
THE 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

Altering Records - Master Set Only

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:

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).

Example of Altering

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
*STRUCTURE
CUSTNO INT 5
SHIPDATE DATE
ORDATE DATE
BKTITLE CHAR 16
QTY_PUR INT 4
UNITPRICE FLOAT 4 2
DISCPRICE FLOAT 6 4
AMTDUE FLOAT 7 2
*LIST DI MYSTRY
00100   INDEX TYPE IS RAM
00110   INDEX TO MYSTRY
00120   DOMAIN BKTITLE ON BKTITLE
*EXTRACT
1123   10/15/91  08/01/91  ALEPH SOLUTION   30  2.11  .0000  .00
6430   10/15/91  09/28/91  ALEPH SOLUTION   40  2.11  .0000  .00
6674   10/15/91  09/12/91  ALEPH SOLUTION   45  2.11  .0000  .00
7432   10/15/91  09/02/91  ALEPH SOLUTION   25  2.11  .0000  .00
5234   10/15/91  08/10/91  DELPHI BETRAYAL  20  2.55  .0000  .00
6430   10/15/91  09/28/91  DELPHI BETRAYAL  30  2.55  .0000  .00
2242   10/15/91  09/01/91  JERICHO MAN      35  1.99  .0000  .00
3529   10/15/91  10/10/91  JERICHO MAN      35  1.99  .0000  .00
2242   10/15/91  09/01/91  MAYDAY MAYDAY    40  2.78  .0000  .00
6540   10/15/91  10/05/91  MAYDAY MAYDAY    25  2.78  .0000  .00
*LIST PM UP_INVOICE
00005 !==============
00010 CONTROL SECTION
00015 !==============
00020 RELATE DI MYSTRY AS MASTER FOR UPDATE
00030 !
00035 !==============
00040 DECLARE SECTION
00045 !==============
00050 DISCOUNT,FLOAT,4,2
00060 !
00065 !==============
00070 INITIAL SECTION
00075 !==============
00080 TYPE "UPDATING INVOICES FOR NEW MYSTERIES"
00090 TYPE "QUANTITY AND EARLY ORDER DISCOUNTS GIVEN.",@CR
00100 !
00105 !=============
00110 DETAIL SECTION
00115 !=============
00120 IF QTY_PUR >= 25
00130 IF:2 SHIPDATE - ORDATE >= 60
00140      .75 TO DISCOUNT:D
00150 ORIF:2 SHIPDATE - ORDATE >= 30
00160      .85 TO DISCOUNT:D
00170 ORIF:2 SHIPDATE - ORDATE >= 15
00180      .95 TO DISCOUNT:D
00190 ELSE:2
00200      1 TO DISCOUNT:D
00210 ELSE
00220      1 TO DISCOUNT:D
00230 CONTINUE
00240 UNITPRICE * DISCOUNT:D * QTY_PUR TO AMTDUE
00250 DISCOUNT:D * UNITPRICE TO DISCPRICE
00260 !
00265 !============
00270 FINAL SECTION
00275 !============
00280 TYPE "THE TOTAL AMOUNT DUE IS: ", SUM AMTDUE
*ALTER VIA UP_INVOICE UPDATING INVOICES FOR NEW MYSTERIES QUANTITY
AND EARLY ORDER DISCOUNTS GIVEN
THE TOTAL AMOUNT DUE IS: 669.75
*EXTRACT
1123 10/15/91 08/01/91 ALEPH   SOLUTION 30 2.11 1.5825 47.48
6430 10/15/91 09/28/91 ALEPH   SOLUTION 40 2.11 2.0045 80.18
6674 10/15/91 09/12/91 ALEPH   SOLUTION 45 2.11 1.7935 80.71
7432 10/15/91 09/02/91 ALEPH   SOLUTION 25 2.11 1.7935 44.84
5234 10/15/91 08/10/91 DELPHI  BETRAYAL 20 2.55 2.5500 51.00
6430 10/15/91 09/28/91 DELPHI  BETRAYAL 30 2.55 2.4225 72.68
2242 10/15/91 09/01/91 JERICHO MAN      35 1.99 1.6915 59.20
3529 10/15/91 10/10/91 JERICHO MAN      35 1.99 1.9900 69.65
2242 10/15/91 09/01/91 MAYDAY  MAYDAY   40 2.78 2.3630 94.52
6540 10/15/91 10/05/91 MAYDAY  MAYDAY   25 2.78 2.7800 69.50

Altering & Reporting

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_DUE
00005 !==============
00010 CONTROL SECTION
00015 !==============
00020 RELATE DI MYSTRY AS MASTER FOR UPDATE
00030 RELATE SF DUE AS REPORT 1
00040 !
00045 !==============
00050 DECLARE SECTION
00055 !==============
00060 DISCOUNT, FLOAT, 4, 2
00070 !
00075 !==============
00080 INITIAL SECTION
00085   !==============
00090 TYPE "UPDATING INVOICES FOR NEW MYSTERIES"
00100 TYPE "QUANTITY AND EARLY ORDER DISCOUNTS GIVEN.", @CR
00110 !
00115 !==============
00120 HEADINGS SECTION
00125 !==============
00130 PRINT
00140 CENTER "SUMMARY REPORT FOR MYSTERY TITLES" AT 40
00150 PRINT
00160 CENTER "PREPARED ON " + @FDATE AT 40
00170 PRINT
00180 PRINT "CUSTNO ORDATE BOOK TITLE QTY UNITPRICE DISCPRICE"&
          "AMTDUE",@CR
00190 !
00195 !=============
00200 DETAIL SECTION
00205 !=============
00210   IF QTY_PUR >= 25
00220 IF:2 SHIPDATE - ORDATE >= 60
00230      .75 TO DISCOUNT:D
00240 ORIF:2 SHIPDATE - ORDATE >= 30
00250      .85 TO DISCOUNT:D
00260 ORIF:2 SHIPDATE - ORDATE >= 15
00270      .95 TO DISCOUNT:D
00280 ELSE:2
00290      1 TO DISCOUNT:D
00300 ELSE
00310      1 TO DISCOUNT:D
00320 CONTINUE
00330 UNITPRICE * DISCOUNT:D * QTY_PUR TO AMTDUE
00340 DISCOUNT:D * UNITPRICE TO DISCPRICE
00350 PRINT CUSTNO,3B,ORDATE,2B,BKTITLE,QTY_PUR, 4B,UNITPRICE,&
          6B, DISCPRICE @"D.DDDD",3B,AMTDUE
00360 !
00365 !=============
00370 TOTALS SECTION
00375 !=============
00380 ON BKTITLE
00390 PRINT 5B,"AVERAGE ORDER:",AVG QTY_PUR,15B, &
"TOTAL DUE FOR", BKTITLE, SUM AMTDUE,@CR
00400 !
00405 !=============
00410 FINAL SECTION
00415 !=============
00420 TYPE "THE TOTAL AMOUNT DUE IS: ", SUM AMTDUE
00430 PRINT 44B,"THE TOTAL AMOUNT DUE IS: ", SUM AMTDUE
00440 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

Updating Records - Master & Transaction

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.

Example of Updating

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
*STRUCTURE
TITLE_CODE CHAR 6
TYPE_CODE CHAR 12
QTY_ONHAND INT 6
QTY_SHIPPED INT 6
RESTOCK INT 6
*SORT ON TITLE_CODE, TYPE_CODE
*EXTRACT
CP2264   computer   150   0   0
CP3681   computer   100   0   0
FL0839   for_lang    60   0   0
FL2772   for_lang    70   0   0
HI0034   history    630   0   0
MY4312   mystery      0   0   0
TR7022   travel     350   0   0
TR7657   travel      20   0   0
*USE DS ORDERS
*STRUCTURE
STORE_CODE CHAR 4
TITLE_CODE CHAR 6
TYPE_CODE CHAR 12
QTY_ORDERED INT 6
QTY_SHIPPED INT 6
*SORT ON TITLE_CODE, STORE_CODE
*EXTRACT
6359  CP2264   computer   100   0
6360  CP2264   computer    45   0
5742  FL0839   for_lang    75   0
6360  FL2772   for_lang    25   0
7106  FL2772   for_lang    30   0
6418  HI0034   history     65   0
5742  TR7022   travel     200   0
7238  TR7657   travel      30   0
1234  ZZ1109   govt        10   0

PM 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 DAILY
00010   !
00015   !==============
00020   CONTROL SECTION
00025   !==============
00030   RELATE DS NEW_BOOKS AS MASTER FOR UPDATE
00040   RELATE DS ORDERS AS TRANSACTION FOR UPDATE
00050   !
00055   !==============
00060   INITIAL
00065   !==============
00070   TYPE "UPDATING OF BOOK INVOICES FOR ", @DATE, @CR
00080   !
00085   !==============
00090   MATCHED
00095   !==============
00100   SETUP TO REWRITE TRANSACTION
00110   IF QTY_ONHAND:M < QTY_ORDERED:T
00120      QTY_ONHAND:M TO QTY_SHIPPED:T
00125      QTY_SHIPPED:M + QTY_SHIPPED:T TO QTY_SHIPPED:M
00130      0 TO QTY_ONHAND:M
00140   ELSE
00150      QTY_ONHAND:M - QTY_ORDERED:T TO QTY_ONHAND:M
00160      QTY_ORDERED:T + QTY_SHIPPED:M TO QTY_SHIPPED:M
00170      QTY_ORDERED:T TO QTY_SHIPPED:T
00180   !
00185   !==============
00190   UNMATCHED:M
00195   !==============
00200   IF QTY_ONHAND:M = 0 AND RESTOCK:M = 0
00210      SETUP TO OMIT MASTER
00220      TYPE"RECORD FOR BOOK",TITLE_CODE:M,1B, TYPE_CODE:M, &
              "OMITTED",@CR
00230   !
00235   !=============
00240   AFTER:M
00245   !=============
00250   200 TO RESTOCK:M IF QTY_ONHAND:M < 10
00260   !
00265   !=============
00270   UNMATCHED:T SECTION
00285   !==============
00280   READY MASTER
00290      TITLE_CODE:T TO TITLE_CODE:M:R
00300      TITLE_CODE:T TO TITLE_CODE:M:R
00310      0 TO QTY_ONHAND:M:R
00320      200 TO RESTOCK:M:R
00330   CREATE MASTER HUSH

This 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/91
RECORD    FOR BOOK MY4312 mystery OMITTED.

The master and transaction sets, after updating, are shown below.

*USE DS NEW_BOOKS
*EXTRACT
CP2264   computer     5   145   200
CP3681   computer   100     0     0
FL0839   for_lang     0    60   200
FL2772   for_lang    15    55     0
HI0034   history    565    65     0
TR7022   travel     150   200     0
TR7657   travel       0    20   200
ZZ1109   govt         0     0   200
*USE DS ORDERS
*EXTRACT
6359   CP2264   computer  100   100
6360   CP2264   computer   45    45
5742   FL0839   for_lang   75    60
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    20
1234   ZZ1109   govt       10     0

Updating & Reporting

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 COMPLETE
00010   !
00015   !==============
00020   CONTROL SECTION
00025   !==============
00030   RELATE DS NEW_BOOKS AS MASTER FOR UPDATE
00040   RELATE DS ORDERS AS TRANSACTION FOR UPDATE
00050   RELATE SF CURSTK AS REPORT 1
00060   RELATE SF RESTK AS REPORT 2
00070   RELATE SF DONE AS REPORT 3
00080   !
00085   !==============
00090   DECLARE SECTION
00095   !==============
00100   FILLED,INT,3
00110   PART_FILL,INT,3
00120   UNFILL,INT,3
00130   !
00135   !==============
00140   INITIAL
00145   !==============
00150   TYPE "UPDATING OF BOOK INVOICES FOR", @DATE, @CR
00160   2 TO @FOOTING_SIZE(3)
00170   !
00175   !==============
00180   HEADINGS SECTION
00185   !==============
00190   REPORT 1
00200      SKIP 1
00210      CENTER "CURRENT BOOK STOCK" AT 15
00220      SKIP 1
00230      CENTER @FDATE AT 15
00240      SKIP 1
00250      PRINT"TITLE_CODE",3B,"TYPE_CODE",2B,&
           "ON HAND",2B,"RESTOCK"
00260   !
00270   REPORT 2
00280      PRINT @CR, "RESTOCK LIST AS OF ", @FDATE, @CR
00290      PRINT "TITLE_CODE",3B,"TYPE_CODE",2B,"RESTOCK QTY"
00300   !
00310   REPORT 3
00320      SKIP 1
00330      CENTER "ORDERS SHIPPED ON " + @FDATE AT 28
00340      SKIP 1
00350      PRINT"STORE_CODE",2B,"TITLE_CODE",3B,"TYPE_CODE",&
           3B,"ORDERED",2B,"SHIPPED",2B,"BACKORDERED",2B
00360   !
00365   !==============
00370   FOOTINGS SECTION
00375   !==============
00380   REPORT 3
00390   PRINT @CR, 5B, "P = PARTIAL SHIPMENT"
00400   !
00405   !==============
00410   MATCHED
00415   !==============
00420   SETUP TO REWRITE TRANSACTION
00430   IF QTY_ONHAND:M < QTY_ORDERED:T
00440      QTY_ONHAND:M TO QTY_SHIPPED:T
00450      QTY_SHIPPED:M + QTY_SHIPPED:T TO QTY_SHIPPED:M
00460      0 TO QTY_ONHAND:M
00470   ELSE
00480      QTY_ONHAND:M - QTY_ORDERED:T TO QTY_ONHAND:M
00490      QTY_ORDERED:T + QTY_SHIPPED:M TO QTY_SHIPPED:M
00500      QTY_ORDERED:T TO QTY_SHIPPED:T
00510   !
00515   !==============
00520   UNMATCHED:M
00525   !==============
00530   IF QTY_ONHAND:M = 0 AND RESTOCK:M = 0
00540      SETUP TO OMIT MASTER
00550      TYPE"RECORD FOR BOOK ",TITLE_CODE:M,1B, TYPE_CODE:M, &
              "OMITTED",@CR
00570   !
00575   !==============
00580   UNMATCHED:T SECTION
00585   !==============
00590   READY MASTER
00600      TITLE_CODE:T TO TITLE_CODE:M:R
00600      TITLE_CODE:T TO TITLE_CODE:M:R
00620      0 TO QTY_ONHAND:M:R
00630      200 TO RESTOCK:M:R
00640   CREATE MASTER HUSH
00650   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:M
00685   !==============
00700   200 TO RESTOCK:M IF QTY_ONHAND:M < 10
00710   PRINT ON 1 TITLE_CODE,2B,TYPE_CODE,2B,QTY_ONHAND,5B,RESTOCK
00720   PRINT ON 2 TITLE_CODE,2B,TYPE_CODE,5B,RESTOCK IF RESTOCK>0
00730   !
00735   !==============
00740   AFTER:T SECTION
00745   !==============
00750   PRINT ON 3 STORE_CODE:T,4B,TITLE_CODE:T,1B,TYPE_CODE:T, &
           3B, QTY_ORDERED:T,NOCR
00760   IF QTY_SHIPPED:T = QTY_ORDERED:T
00770      PRINT ON 3 5B, QTY_SHIPPED:T
00780      INCR FILLED:D
00790   ELSE
00800      IF:5 QTY_SHIPPED:T = 0
00810         PRINT ON 3 14B, QTY_ORDERED:T
00820         INCR UNFILL:D
00830      ELSE:5
00840         PRINT ON 3 5B,QTY_SHIPPED:T,1B,"P",4B, &
        QTY_ORDERED:T QTY_SHIPPED:T@"ZZZ"
00850         INCR PART_FILL:D
00860   !
00865   !==============
00870   FINAL SECTION
00875   !==============
00880   PRINT ON 3 @CR,"THE NUMBER OF FILLED ORDERS IS:",6B,FILLED:D
00890   PRINT ON 3 "THE NUMBER OF UNFILLED ORDERS IS:",4B,UNFILL:D
00900   PRINT ON 3 "THE NUMBER OF PART FILLED ORDERS IS:",PART_FILL:D
00910   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/91
RECORD 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:      6
THE NUMBER OF UNFILLED ORDERS IS:    1
THE NUMBER OF PART FILLED ORDERS IS: 2
 
P = PARTIAL SHIPMENT

Converting a Data Set with a Process Module

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:

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.

Example of Converting

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
*STRUCTURE
RECORD OLD_BOOK
   RT CHAR 1
   TITLE_CODE CHAR 6
   NOTES CHAR 20
   ONHAND INT 6
   ONORDER INT 6
   PRICE FLOAT 7 2
RECORD LIB
   RT CHAR 1
   TITLE_CODE CHAR 6
   LIBNO INT4
RECORD RETAIL
   RT CHAR 1
   TITLE_CODE CHAR 6
   TYPE_CODE CHAR 12
   STORE_CODE CHAR 4
   QTY_ORDERED INT 4
   ORDER_DATE DATE
*EXTRACT
O   CP2264   slow   25    0    7.99
O   FL4049   sale    5   20   15.25
L   TR7022   MM25
R   TR7022   5789   20   04/13/91
L   MY4312   ML09
R   ZZ1019   7089   15   08/08/91
O   SF8812   hot    70   100   10.00

The 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
*STRUCTURE
RECORD OLD_BOOK
   RT CHAR 1
   TITLE_CODE CHAR 6
   TYPE_CODE CHAR 12
   NOTES CHAR 20
   ONHAND INT 6
   PRICE FLOAT 7 2
RECORD LIB
   RT CHAR 1
   TITLE_CODE CHAR 6
   LIBNO INT 4
   ZONE INT 2
RECORD RETAIL
   RT CHAR 1
   TITLE_CODE CHAR 6
   STORE_CODE CHAR 4
   QTY_ORDERED INT 4
   ORDER_DATE DATE
   SHIPPED_QTY INT 4
   SHIPPED_DATE DATE

The 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 MODSET
00010   !
00015   !==============
00020   CONTROL SECTION
00025   !==============
00030   RELATE DS MULDAT AS MASTER FOR INPUT
00040   RELATE DS MDAT AS New FOR CREATE
00050   !
00055   !==============
00060   DETAIL SECTION
00065   !==============
00070   READY New
00080   !
00090   IF RT = "O"
00100      RT:M TO RT:New
00110      TITLE_CODE:M TO TITLE_CODE:New HUSH
00120      TYPE_CODE:M TO TYPE_CODE:New HUSH
00130      ONHAND:M TO ONHAND:New HUSH
00140      PRICE:M TO PRICE:New HUSH
00150      NOTES:M TO NOTES:New HUSH
00160   !
00170   ORIF RT = "L"
00180      RT:M TO RT:New HUSH
00190      TITLE_CODE:M TO TITLE_CODE:New HUSH
00200      LIBNO:M TO LIBNO:New HUSH
00210      TYPE "PLEASE ENTER ZONE FOR LIB", LIBNO, ":", NOCR
00220      ACCEPT ZONE:New
00230   !
00240   ELSE
00250      RT:M TO RT:New HUSH
00260      TITLE_CODE:M TO TITLE_CODE:New HUSH
00270      STORE_CODE:M TO STORE_CODE:New HUSH
00280      QTY_ORDERED:M TO QTY_ORDERED:New HUSH
00290      ORDER_DATE:M TO ORDER_DATE:New HUSH
00300   CONTINUE
00310   !
00320   CREATE New

After 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 MODSET
PLEASE ENTER ZONE FOR LIB MM25: 15
PLEASE ENTER ZONE FOR LIB ML09: 17
*USE DS MDAT
*EXTRACT
O   CP2264   slow   25    7.99
O   FL4049   sale   5    15.25
L   TR7022   MM25   15
R   TR7022   5789   20 04/13/91   0   ********
L   MY4312   ML09   17
R   ZZ1019   7089   15 08/08/91   0   ********
O   SF8812   hot    70   10.00

Customizing Commands

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 CODES

The 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_UPDATE
00010   CONTROL
00020   RELATE SD MAIL AS MASTER FOR UPDATE
00030   RELATE SD MAILCD AS CODES FOR UPDATE
00040   !
00050   DETAIL
00060   IF @OPER="ENTER"
00070      GET FIRST FROM CODES
00080      ADD 1 TO LAST_NUM:CODES
00090      PUT CODES
00100      TYPE "***Author Code:",LAST_NUM:CODES@"",1S,"Assigned."
00110      DATE TO CREATE_DATE:M
00120   CONTINUE
00130      @DATE TO CHANGE_DATE:M

Stand-Alone Process Modules

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:

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 ROYALTY
00010   !This PM figures the royalty expense per order.
00015   !
00020   !==============
00020   DECLARE SECTION
00025   !==============
00030   QTY_ORDER, INT, 6
00040   PRICE, FLOAT, 10, 2
00050   ROY_PCT, FLOAT, 3
00060   ROY_EXP, FLOAT, 10, 2
00070   !
00075   !==============
00080   FINAL SECTION
00085   !==============
00090   !
00100   !   get information
00110   TYPE @CR, "ORDER QUANTITY FOR BOOK: ", NOCR
00120   ACCEPT QTY_ORDER
00130   TYPE "BOOK PRICE: ", NOCR
00140   ACCEPT PRICE
00150   TYPE "BOOK ROYALTY % (Ex: .05): ", NOCR
00160   ACCEPT ROY_PCT
00170   !
00180   !   calculate entries
00190   QTY_ORDER * PRICE * ROY_PCT TO ROY_EXP
00200
00210   !   display information
00220   TYPE @CR,"ROYALTY EXPENSE FOR ORDER:$",ROY_EXP
*USE PM ROYALTY
BOOK PRICE: $5.35
BOOK ROYALTY % (EX: .05):.15
ROYALTY EXPENSE FOR ORDER: $   16.05