![]()  | 
  QUERY/iX Reference Manual
    > Chapter 4 QUERY/iX COMMANDS (cont)JOIN | 
|||||||||||||||||||||
    
  | 
  
    Syntax
  J[OIN] data item equivalence [,data item equivalence]...
    [;data set equivalence [,data set equivalence]...] [END]
    Parameters
 DiscussionThe JOIN command allows the retrieval and reporting of data item values from multiple data sets by creating a logical relation between data sets. The relation is established by equating a data item from one set with a data item from a second data set. These data item equivalences, of which QUERY allows up to 52, define a compound data set. Once you have defined a compound data set with the JOIN command, you must enter a MULTIFIND or a MULTIFIND ALL command to actually create the compound data set and access the desired items. Refer to the MULTIFIND or MULTIFIND ALL commands in this manual for details on their operation. You can only report from those data sets used in the JOIN command. A JOIN command will remain in effect until another JOIN command, valid or invalid, is entered. Each subsequent JOIN command also clears the previous select file. For example, suppose you want to make a sales report that shows information from four data sets: the name of the product, the quantity sold of that product, the quantity on hand, and the date of sale. To access all this information, define your data base with a DEFINE, DATA BASE=, or MULTIDB command and enter the JOIN command. >JOIN PRODUCT.STOCK# TO SALES.STOCK#,& >> SALES.STOCK# TO INVENTORY.STOCK# >MULTIFIND PRODUCT.DESCRIPTION = NAIL USING SERIAL READ 2 COMPOUND ENTRIES QUALIFIEDIn order for the JOIN command to be valid, all data sets used in the JOIN command must be logically connected to one another so that each data set is traceable to every other data set through the data item equivalences. If logical connections cannot be traced between data sets, the following message is returned and the JOIN does not take place. LOGICAL CONNECTIONS ARE INCOMPLETE, COMPOUND DATA SET CANNOT BE GENERATEDIn the example above, the data set SALES is common to both PRODUCT and INVENTORY, and a data equivalence is formed with the data item STOCK#. However, the data items that link the data sets need not have the same name or be of the same data type. The MULTIFIND PRODUCT.DESCRIPTION=NAIL command created the compound data set from which retrieved entries can be reported. To produce a sales report for the NAIL product, you can enter the REPORT command with the desired header and detail statements from your terminal or you can use a procedure file. The REPORT command is shown below. 
  >REPORT SALESPROC,A
  REPORT
  H1,"Report on Sales",43,SPACE A2
  H2,"Stock",7
  H2,"Product",24
  H2,"Quantity",39
  H2,"Quantity",56
  H2,"Date",70
  H3,"No.",7
  H3,"Description",24
  H3,"Sold",39
  H3,"in Stock",56
  H3,"Sold",70,SPACE A2
  D1,PRODUCT.STOCK#,6
  D1,PRODUCT.DESCRIPTION,24
  D1,SALES.QUANTITY,39
  D1,INVENTORY.ONHANDQTY,56
  D1,SALES.PURCH-DATE,70,E1
  E1,"XX/XX/XX"
  END
                            Report on Sales
  Stock          Product       Quantity         Quantity          Date
    No.      Description           Sold         In Stock          Sold
    50              NAIL            130             1200      85/01/12
    50              NAIL              5             1200      85/01/12
The compound data set was formed by matching entries from
the data sets PRODUCT, INVENTORY, and SALES that have equal values
for connecting data items named in the data item equivalence. In
this example, STOCK# is the only equated data item for all data sets.
    
If a value for the data item named in the data item equivalence
occurs more than once in one of the data sets named in the equivalence,
and at least once in the other data set named, this entry will be
repeated in the compound data set. Given the following data sets and
a data item equivalence using upper-limit and price, the name JOHN
SMITH will appear twice in the compound data set.
            CLIENT                                 SELLER
  ------------------------------       -----------------------------
       NAME     UPPER LIMIT $                 NAME         PRICE
  ------------------------------       -----------------------------
    JOHN SMITH     $1000                   MARY SMITH      $1000
                                         GEORGE BROWN      $1000
  ------------------------------       -----------------------------
  >JOIN CLIENT.UPPER-LIMIT TO SELLER.ASKING-PRICE
  >MULTIFIND ALL
  2 COMPOUND ENTRIES QUALIFIED
  >REPORT ALL
  SALES:  CLIENT
  NAME            =JOHN SMITH
  UPPER-LIMIT     =$1000
  SALES:  SELLER
  NAME            =MARY SMITH
  ASKING-PRICE    =$1000
  SALES:  CLIENT
  NAME            =JOHN SMITH
  UPPER-LIMIT     =$1000
  SALES:  SELLER
  NAME            =GEORGE BROWN
  ASKING-PRICE    =$1000
    Data Item TypesEquated (joined) data items can be of different types and lengths, with the exception of character types, which may only be equated to other character types. If two items of different lengths are equated, QUERY treats the shorter one as if it were padded with blanks to match the length of the longer data item. Null Connecting Data Items The IMAGE subsystem initializes numeric type data items to zero, and character type data items to ASCII null. When data items are equated with a relational operator for retrieval, QUERY compares data item values based on their types. When comparing two numeric type data items, QUERY considers the two items equal when both items have a zero value. If the comparison is between character type data items with the values of ASCII null, QUERY does not consider the relationship equal, and no entries are joined. Zoned Type Data Items When joining zoned type data items, the zoned numbers with the sign overpunch are considered equal to the equivalent value without an overpunch. For example, 5A is considered equivalent to 51. When QUERY converts a different data type to zoned, it will pad with leading blanks. Leading nulls are not considered equivalent to leading blanks. Packed Data Type Items When QUERY converts a different data type to packed, it uses a COBOL Convention, a positive sign of 1100, a negative sign of 1101, and unsigned 1111. Positive and unsigned numbers are considered equivalent. Data Set EquivalenceEquating data sets is a way of renaming a data set to enable the information contained in it to be used in more than one way. For example, assume you have the following simple data set EMP-DETAIL containing three data entries, and you want to create a REPORT that prints the employee's name and the employee's manager's name: 
                              EMP-DETAIL
  ------------------------------------------------------------------
      EMP-#                    EMP-NAME                   MGR-#
  ------------------------------------------------------------------
      1792                     G. Smith                   1833
      1833                     H. Jones                   3421
      3421                 J. President                   ****
  ------------------------------------------------------------------
In this data set, the data item MGR# identifies both an employee
and an employee's manager. For example, MGR# 1833 identifies G.
Smith's manager (H. Jones) and is at the same time H. Jones employee number.
    
To create the desired report, the data set EMP-DETAIL must
be equated to a dummy data set, and these two data sets connected
with a JOIN command, to specify a compound data set from which the
report can be generated.
    
The dummy data set MGR-DETAIL is a temporary name to which
the existing data set is equated. Note that this equation must be
specified after the data item equivalences.
>JOIN EMP-DETAIL.MGR-# TO MGR-DETAIL.EMP-#;& >> MGR-DETAIL = EMP-DETAIL >MULTIFIND ALL USING SERIAL READ 2 COMPOUND ENTRIES QUALIFIEDThe data set equivalence above is not actually executed until a MULTIFIND or MULTIFIND ALL command is entered to retrieve some or all of the compound entries you have formed. Two compound entries have been retrieved from which the desired report can be created. >REPORT ALL EMP:EMP-DETAIL EMP-# =1792 EMP-NAME =G. SMITH MGR-# =1833 EMP:MGR-DETAIL EMP-# =1833 EMP-NAME =H. JONES MGR-# =3421 EMP:EMP-DETAIL EMP-# =1833 EMP-NAME =H. JONES MGR-# =3421 EMP:MGR-DETAIL EMP-# =3421 EMP-NAME =J. PRESIDENT MGR-# =****Below is another report showing employee and manager names: 
  >REPORT
  >>H1,"Employee Name",30
  >>H1,"Manager Name",55,SPACE A2
  >>D1,EMP-DETAIL.EMP-NAME,27
  >>D1,MGR-DETAIL.EMP-NAME,55
  >>END
               Employee Name             Manager Name
                 G. SMITH                    H. JONES
                 H. JONES                J. PRESIDENT
    Using the @ ParameterThe optional @ parameter allows you to preserve all of the data item values in one of the data sets of a data item equivalence. The values in the data set which is next to the @ (on the same side of the TO as the @) will be preserved when data sets are joined even if a corresponding data item value for the equated data items does not exist in the second data set. For example, given the following data sets: 
           SALES-DETAIL                        STOCK-DETAIL
  -----------------------------      -------------------------------
    ACCT-#    STOCK-#    QUAN          STOCK-#    DESCR    ON-HAND
  -----------------------------      -------------------------------
    666         90       350            110         NUT      970
    222         60        25             60        BOLT     1200
  -----------------------------      -------------------------------
The next JOIN command produces the following compound data set:
  >JOIN SALES-DETAIL.STOCK# TO STOCK-DETAIL.STOCK#
  <--------(SALES DETAIL)--------> <---------(STOCK-DETAIL)--------->
  -------------------------------------------------------------------
    ACCT-#    STOCK-#     QUAN       STOCK-#     DESCR      ON-HAND
  -------------------------------------------------------------------
     222        60         25          60         BOLT        1200
  -------------------------------------------------------------------
If you want to keep all of the entries in the SALES-DETAIL
data set, use the @ parameter. Placing the @ sign on the SALES-DETAIL
side of the TO ensures that all entries for the SALES-DETAIL data
set will be included in the resulting compound data set even if
there is no corresponding value for STOCK# in the STOCK-DETAIL data
set. For example, the JOIN below produces the following compound data set.
  >JOIN SALES-DETAIL.STOCK# @ TO STOCK-DETAIL.STOCK#
  <-------(SALES DETAIL)-------><---------(STOCK-DETAIL)-------->
  ---------------------------------------------------------------
    ACCT-#    STOCK-#    QUAN       STOCK-#    DESCR    ON-HAND
  ---------------------------------------------------------------
     666        90       350           *        ****        *
     222        60        25          60        BOLT     1200
  ---------------------------------------------------------------
The compound entry STOCK# = 90 is included, but there is no
STOCK# = 90 in the STOCK-DETAIL set. The corresponding missing entry
from STOCK-DETAIL is represented with asterisks. Missing entries
can be retrieved using the MULTIFIND or SUBSET command with the
$MISSING parameter.
    
Placing the @ sign on the other side of the TO preserves all
entries in the data set STOCK-DETAIL, and marks missing entries
from the SALES-DETAIL with asterisks. The next JOIN command produces
the following compound data set.
  >JOIN SALES-DETAIL.STOCK# TO @ STOCK-DETAIL.STOCK#
  <---------(SALES-DETAIL)-------> <--------(STOCK-DETAIL)------>
  ---------------------------------------------------------------
    ACCT-#    STOCK-#    QUAN       STOCK-#    DESCR    ON-HAND
  ---------------------------------------------------------------
     *           *         *         110         NUT       970
    222         60        25          60        BOLT      1200
  ---------------------------------------------------------------
Note: When forming compound entries for three or more data
sets, once an entry from a data set is considered missing, no further
joins can be made with the missing entry, and missing entries will
be propagated.
    
When joining data sets with the @ parameter, the following restrictions apply:
    
 >JOIN SETA.ITEM1 @ TO SETB.ITEM1, & >> SETB.ITEM2 @ TO SETA.ITEM3 ![]() >JOIN SETA.ITEM1 TO @ SETB.ITEM2,& >> SETB.ITEM3 TO @ SETC.ITEM3,& >> SETC.ITEM2 TO @ SETA.ITEM2 ![]() 
 Propagating @ SignsExample 1 In this example, an @ sign is associated with SETA in the equivalence between SETA and SETB. Therefore, the data set on the opposite side of the TO from the @ sign (SETB) must also have an @ sign associated with it. The @ sign associated with SETB requires that @ sign be associated with SETC. The @ sign associated with SETC requires that an @ sign be associated with SETD if SETD was joined to another data set. Since SETD is not connected to another data set, no @ sign is necessary. >JOIN SETA.ITEM1 @ TO SETB.ITEM2,& >> SETB.ITEM3 @ TO SETC.ITEM4,& >> SETC.ITEM5 @ TO SETD.ITEM6 ![]() >JOIN SETA.ITEM1 TO SETB.ITEM2,& >> SETB.ITEM2 @ TO SETC.ITEM3,& >> SETC.ITEM4 @ TO SETD.ITEM5 ![]() >JOIN SETA.ITEM1 TO @ SETB.ITEM2,& >> SETB.ITEM1 @ TO SETC.ITEM2,& >> SETC.ITEM1 @ TO SETD.ITEM4 ![]() >JOIN SETA.ITEM1 @ TO SETB.ITEM2,& >> SETB.ITEM3 @ TO SETC.ITEM2,& >> SETB.ITEM4 @ TO SETD.ITEM1,& >> SETD.ITEM2 @ TO SETE.ITEM3 ![]() ![]() ![]() 
 
  |