These examples apply to creating an index or view within a table definition.
The table definition used in these examples is called CUSMST (Customer master table) and contains these columns:
Column | Description | Type | Len | Dec |
|---|---|---|---|---|
CUSTNO | Customer number (primary key) | S | 7 | 0 |
NAME | Name of person / organization | A | 30 | |
ADDR1 | Address line 1 | A | 35 | |
ADDR2 | Address line 2 | A | 35 | |
ADDR3 | Address line 3 | A | 35 | |
POSTCD | Post code | A | 4 | |
STATE | State mnemonic | A | 3 | |
ACTIVE | Active / inactive flag | A | 1 | |
CREDIT | Credit limit | P | 11 | 2 |
AMTDUE | Current amount due all accounts | P | 11 | 2 |
ACCTYP | Customer account type | P | 1 | 0 |
Create an index/table called CUSMSTV1 that will order CUSMST by NAME and allow generic searching by NAME:
Index name : CUSMSTV1
Desc of index : Customer master by customer name
Access path maint opt : IMMED Unique? NO Dynamic select? NO
Key column details
Column Description A/D S/U/A
NAME___ A _
_______ _ _ +
_______ _ _ +
+
Create an index/table called CUSMSTV2 that will order CUSMST by STATE then POSTCD (i.e. POSTCD within STATE):
Index name : CUSMSTV2
Desc of index : Cust master by state and postcode
Access path maint opt : IMMED Unique? NO Dynamic select? NO
Key column details
Column Description A/D S/U/A
STATE____ _ _
POSTCD___ _ _
_ _ +
Note that no ascend/descend value has been specified. In this case the value will default to ascend for both keys.
Create an index/table called CUSMSTS1 that will order CUSMST by CUSTNO. Only records with ACTIVE = 'Y' are to be "visible" when using this index:
Index name : CUSMSTS1
Desc of index : Active customers by customer no
Access path maint opt : IMMED Unique? NO Dynamic select? NO
Key column details:
Column Description A/D S/U/A
CUSTNO__ _ _
________ _ _ +
________ _ _ +
+
Select/Omit criteria:
AND/OR SELECT/OMIT Column Operation(s)
SELECT____ ACTIVE COMP(EQ 'Y')_____
Create an index/table called CUSMSTS2 that will order CUSMST by AMTDUE. Only records with CREDIT greater than 100000 and AMTDUE greater than or equal to 20000 are to be visible via this view. Records are to be ordered from highest amount due to lowest amount due. Use the dynamic select feature as well.
Index name : CUSMSTS2
Desc of index : High credit, large debt customers
Access path maint opt: IMMED Unique? NO Dynamic select? YES
Key column details:
Column Description A/D S/U/A
AMTDUE__ D S
________ _ _ +
________ _ _ +
+
Select/Omit criteria :
AND/OR SELECT/OMIT Column Operation(s)
SELECT___ CREDIT___ COMP(GT 100000)_______
AND _________ AMTDUE___ COMP(GE 20000)________
Note that since no entry was made in the SELECT/OMIT column for the second select/omit statement the 2 statements are ANDed together. In this case only customers with CREDIT greater than 100000 AND AMTDUE greater than or equal to 20000 are selected.
Create an index/table called CUSMSTS3 that will order CUSMST by CREDIT. Only records with CREDIT greater than 100000 or AMTDUE greater than or equal to 20000 are to be visible via this view.
Index name : CUSMSTS3
Desc of index : High credit or large debt customers
Access path maint opt : IMMED Unique? NO Dynamic select? NO
Key column details:
Column Description A/D S/U/A
CREDIT__ _ _
________ _ _ +
________ _ _ +
+
Select/Omit criteria:
AND/OR SELECT/OMIT Column Operation(s)
SELECT___ CREDIT___ COMP(GT 100000)________
OR SELECT___ AMTDUE___ COMP(GE 20000)_________
Note that since an entry was made in the SELECT/OMIT column for the second select/omit statement the 2 statements are read together. In this case only customers with CREDIT greater than 100000 OR . AMTDUE greater than or equal to 20000 are selected.
Create an index/table called CUSMSTS4 that will order CUSMST by STATE and CUSTNO. Only records with a STATE of NSW, VIC or QLD are to be visible via this view.
Index name : CUSMSTS4
Desc of index : East coast customers by state, cust
Access path maint opt : IMMED Unique? NO Dynamic select? NO
Key column details
Column Description A/D S/U/A
STATE___ _ _
CUSTNO__ _ _
________ _ _ +
+
Select/Omit criteria:
AND/OR SELECT/OMIT Column Operation(s)
SELECT____ STATE___ COMP(EQ 'NSW')________
OR SELECT____ STATE___ COMP(EQ 'VIC')________
OR SELECT____ STATE___ COMP(EQ 'QLD')________
An identical condition can be made using the VALUES keyword:
Select/Omit criteria
AND/OR SELECT/OMIT Column Operation(s)
SELECT____ STATE VALUES('NSW' 'VIC' 'QLD')
Create an index/table called CUSMSTS5 that will order CUSMST by CUSTNO. Only records with an ACCTYP value of 2, 3 or 4 are to be visible via this view.
Index name : CUSMSTS5
Desc of index : Customers with type 2, 3 or 4 accounts
Access path maint opt : IMMED Unique? NO Dynamic select? NO
Key column details:
Column Description A/D S/U/A
CUSTNO__ _ _
________ _ _ +
________ _ _ +
Select/Omit criteria:
AND/OR SELECT/OMIT Column Operation(s)
SELECT____ ACCTYP___ COMP(EQ 2)_____
OR SELECT____ ACCTYP___ COMP(EQ 3)_____
OR SELECT____ ACCTYP___ COMP(EQ 4)______
The select /omit condition could also be expressed as:
SELECT____ ACCTYP___ COMP(GE 2)________
AND ACCTYP____ COMP(LE 4)_________
or :
SELECT____ ACCTYP__ VALUES(2 3 4)______
or :
SELECT____ ACCTYP___ RANGE(2 4)______