Fine-Tuning MATCH Processing

You can fine-tune the MATCH process using the PRINT and SUM commands. To understand their difference, you should have an understanding of the one-to-many relationship: SUM generates one record from many, while PRINT displays each individual record. Through proper choices of BY fields, it is possible to use only the SUM command and get the same result that PRINT would produce.


Top of page

Example: Using Display Commands in MATCH Processing

To illustrate the effects of PRINT and SUM on the MATCH process, consider data sources A and B and the series of requests that follow:

     A               B
 
F1  F2  F3      F1  F4  F5
 
1   x   100     1   a   10
2   y   200     1   b   20
                2   c   30
                2   d   40

Request 1: This request sums the fields F2 and F3 from file A, sums the fields F4 and F5 from file B, and uses F1 as the common high-order sort field.

MATCH FILE A
SUM F2 AND F3 BY F1
RUN 
FILE B
SUM F4 AND F5 BY F1
AFTER MATCH HOLD OLD-OR-NEW
END

The HOLD file contains the following data:

F1   F2   F3   F4   F5
 
1    x    100  b    30
2    y    200  d    70

Note that the resulting file contains only 1 record for each common high-order sort field.

Request 2: This request sums fields F2 and F3 from file A, prints fields F4 and F5 from file B, and uses F1 as the common high-order sort field.

MATCH FILE A
SUM F2 AND F3 BY F1
RUN 
FILE B PRINT F4 AND F5 BY F1
AFTER MATCH HOLD OLD-OR-NEW
END

The HOLD file contains:

F1   F2   F3   F4   F5
 
1    x    100  a    10
1    x    100  b    20
2    y    200  c    30
2    y    200  d    40

Note that the records from file A are duplicated for each record from file B.

Request 3: This request prints fields F2 and F3 from file A, sums fields F4 and F5 from file B, and uses F1 as the common high-order sort field.

MATCH FILE A
PRINT F2 AND F3 BY F1
RUN 
FILE B
SUM F4 AND F5 BY F1
AFTER MATCH HOLD OLD-OR-NEW
END

The HOLD file contains:

F1   F2   F3   F4   F5
 
1    x    100  b    30
2    y    200  d    70

Note that each record from file A is included, but only the last record from file B for each common high-order sort field is included.

Request 4: This request prints fields F2 and F3 from file A, prints fields F4 and F5 from file B, and uses F1 as the common high-order sort field.

MATCH FILE A
PRINT F2 AND F3 BY F1
RUN 
FILE B PRINT F4 AND F5 BY F1
AFTER MATCH HOLD OLD-OR-NEW
END

The HOLD file contains:

F1   F2   F3   F4   F5
 
1    x    100  a    10
1         0    b    20
2    y    200  c    30
2         0    d    40

Note the blank value for F2 and the 0 for F3.

Request 5: This request sums the fields F2 and F3 from file A, sums the field F5 from file B and sorts it by field F1, the common high-order sort field, and by F4.

MATCH FILE A
SUM F2 AND F3 BY F1
RUN 
FILE B
SUM F5 BY F1 BY F4
AFTER MATCH HOLD OLD-OR-NEW
END

The HOLD file contains:

F1   F2   F3   F4   F5
 
1    x    100  a    10
1    x    100  b    20
2    y    200  c    30
2    y    200  d    40

Note that the records for file A are printed for every occurrence of the record in file B.


WebFOCUS