WHERE keyword
The WHERE keyword provides the capability to specify conditional expressions that determine which segments are selected for processing. WHERE can be specified with each SELECT primary command object keyword.

Usage Notes
Values that include spaces or the following special characters must be delimited by single quotation marks.
= Equal + Plus
- Minus | Vertical Bar
> Greater than < Less than
( Left paren ) Right paren
. Period / Slash
: Colon ; Semi-Colon
& Ampersand * Asterisk
! Exclamation MarkIf a value contains an embedded quotation mark, use three adjacent quotation marks for each embedded one. For example,
JOHN’S NAME
would be entered as
JOHN’’’S NAME- Segments that meet the WHERE selection criteria are bypassed until the start and skip frequencies are satisfied. The remaining segments are then processed until the maximum indicated is reached.
The conditional expression following the WHERE keyword must begin with a valid field name followed by a subscript when applicable, a relational operator, and a literal value or variable input assignment. The expression must also supply the record type value (RTV) for segments that use multiple layouts. For more information of processing segments with multiple layouts, see Segments with Multiple Layouts. The field name is one of the following:
- A COBOL or PL/I layout name or a DBD field name.
- $RTVn where n=1 for the first record type value or 2 for the second.
Following is an example of a simple expression:
SELECT SEGMENT A
WHERE FLDA-KEY=A10327 AND $RTV1=$ALL;Conditional expressions can be combined using logical connectors to form complex expressions. Following is an example of a complex expression:
SELECT SEGMENT A
WHERE FLDA-01(2)>=1985 AND FLDA-01(2)<=1990 AND $RTV1=PO;- A field value can be specified with a literal or an input file variable. For more information, see Step 5.
- The end of a conditional expression is determined by another optional keyword, an object keyword, or a sub-command.
Relational Operators:
Operator
Description
EQ or =
Equal to
NE or Ø = or =Ø
Not equal to
GT or >
Greater than
LT or <
Less than
GE or > = or =>
Greater than or equal to
LE or < = or =<
Less than or equal to
BT
Between; within a range of two values (endpoints inclusive)
NB
Not between; outside a range of two values (endpoints exclusive)
CO
Contains; scans for the presence of the data value.
NC
Not contains; scans for the absence of the data value.
Logical Connectors:
Connector
Description
AND or &
Logical AND
OR or |
Logical OR
- When using a PL/I layout with a data type of BIT, WHERE is limited to the first 16 bits of a bit string. Externally, each bit of the field referenced by the WHERE is represented by a character 0 or a character 1.
- IX_INVALID 10. Select segments with an invalid field value by entering the word INVALID. Use the word INVALID for alphanumeric, binary, packed decimal, and zoned decimal fields only. For numeric fields, any value that does not conform to the field’s data type is invalid. For alphanumeric fields, any value that contains non-displayable data is invalid.
- Search conditions within parentheses are evaluated first. If the order of evaluation is not specified by parentheses, AND is applied before OR.
- 1 The BT relational operator includes the endpoints of the range you specify. The NB relational operator does not include the endpoints. The BT and NB relational operators are not valid for Double-Byte Character Set (DBCS) support.
- 1 The CO and NC relational operators can be specified only for alphanumeric fields (PIC X or PIC 9 for COBOL, CHAR, PIC X, or PIC 9 for PL/I).
Examples
The following SELECT command statement defines the criteria for a specific customer using the WHERE keyword. If the customer is found, the customer record is printed in an unformatted mode.
PSB DBNAME=CUSTPDBD;
SET PRINT=SPRINT;
TITLE LINE01=’RECORD OF CUSTOMER 10357’;
SELECT SEGMENT=CUSTOMER
WHERE CUST-NUMBER=10357
CHILD MAX=ALL
PRINT SEGMENT=CUSTOMER
CHILD;
The following command statements define the criteria for all customers in sales zone 3 and region 18 with a sales representative of 539. Because OPTION=PATH is the default for PRINT, the CUSTOMER segment is printed only if both the customer and sales representative segments are satisfied. If OPTION=NOPATH is specified, only the customers without sales representative 539 are printed.
PSB PCB=4;
TITLE LINE01=’ALL CUSTOMERS IN ZONE 3 AND REGION 18 WITH SALES REP 539’;
SELECT SEGMENT=CUSTOMER MAX=ALL
WHERE CUST-SALES-ZONE=3 AND CUST-SALES-REGION=18
SEGMENT=SALESREP MAX=ALL
WHERE CUST-SALES-REP-NUMBER=539
PRINT SEGMENT=CUSTOMER;
The following command statements define the criteria using a WHERE keyword and an input file to select a list of specific customers for printing. All customer segments that satisfy the selection criteria are printed.
PSB PCB=4;
SET INPUT=DISCOUNT;
TITLE LINE01=’ALL CUSTOMERS FROM SPECIAL DISCOUNT INPUT DATASET’;
SELECT SEGMENT=CUSTOMER MAX=ALL
WHERE CUST-NUMBER=INPUT(10,6,C)
SEGMENT=CUSTORDR MAX=ALL
PRINT SEGMENT=CUSTOMER OPTION=ALWAYS
FIELD=(CUST-NUMBER,CUST-NAME,CUST-BALANCE)
SEGMENT=CUSTORDR FIELD=(CUST-ORDR-NUMBER,CUST-ORDR-AMOUNT);
The following command statements define the criteria to find all CUSTOMER segments with CUST-STATUS fields that are INVALID and change them to CUST-STATUS=A.
PSB DBNAME=CUSTPDBD;
SET INPUT=DISCOUNT;
TITLE LINE01=’CHANGE INVALID CUST-STATUS’;
SELECT SEGMENT=CUSTOMER
WHERE CUST-STATUS INVALID
CHANGE SEGMENT=CUSTOMER
SET=(CUST-STATUS=A);
The following command statements define the criteria to find all CUSTOMER segments with CUST-NUMBER 10357 and CUST-STATUS A, B, or C.
PSB DBNAME=CUSTPDBD;
SELECT SEGMENT=CUSTOMER
WHERE
CUST-NUMBER = 10357 AND
(CUST-STATUS = A OR
CUST-STATUS = B OR
CUST-STATUS = C)
PRINT SEGMENT=CUSTOMER;
The following command statements define the criteria to find all CUSTOMER segments with CUST-NUMBER between 10000 and 20000, including endpoints 10000 and 20000.
PSB DBNAME=CUSTPDBD;
SELECT SEGMENT=CUSTOMER
WHERE
CUST-NUMBER BT 10000 : 20000
PRINT SEGMENT=CUSTOMER;
Related topics