Reading Selection Values From a File

Instead of typing literal test values in a WHERE or IF phrase, you can store them in a file and refer to the file in the report request. You can then select records based on equality -- or inequality -- tests on values stored in the file.

How to:

Read Selection Values From a File (WHERE)

Read Selection Values From a File (IF)

Reference:

Usage Notes for Reading Values From a File

Example:

Reading Selection Values From a File (WHERE)

Reading Selection Values From a File (IF)

This method has the following advantages:


Top of page

Syntax: How to Read Selection Values From a File (WHERE)

WHERE [NOT] fieldname IN FILE file 

where:

fieldname

Is the name of the selection field. It can be any real or temporary field in the data source.

file

Is the name of the file.

For MVS, this is the ddname assigned by a DYNAM or TSO ALLOCATE command. On CMS, the ddname is assigned by a FILEDEF command.

For related information, see Usage Notes for Reading Values From a File.


Top of page

Syntax: How to Read Selection Values From a File (IF)

IF fieldname operator (file) [OR (file) ... ]

where:

fieldname

Is any valid field name or alias.

operator

Is the EQ, IS, NE, or IS‑NOT operator (see Operators Supported for WHERE and IF Tests).

file

Is the name of the file.

For MVS, this is the ddname assigned by a DYNAM or TSO ALLOCATE command.

For CMS, this is the ddname assigned by a FILEDEF command.


Top of page

Reference: Usage Notes for Reading Values From a File

In order to read selection criteria from a file, the file must comply with the following rules:

If your list of literals is too large, an error is displayed.


Top of page

Example: Reading Selection Values From a File (WHERE)

Create a file named EXPER, which contains the values B141 and B142.

This request uses selection criteria from the file EXPER. All records for which PRODUCT_ID has a value of B141 or B142 are selected:

TABLE FILE GGPRODS
SUM UNIT_PRICE
BY PRODUCT_DESCRIPTION
WHERE PRODUCT_ID IN FILE EXPER
END

If you include the selection criteria directly in the request, the WHERE phrase specifies the values explicitly:

WHERE PRODUCT_DESCRIPTION EQ 'B141' or 'B142'

The output is:

                     Unit
Product Price
------- -----
French Roast 81.00
Hazelnut 58.00

Top of page

Example: Reading Selection Values From a File (IF)

Create a file named EXPER, which contains the values B141 and B142.

This request uses selection criteria from the file EXPER. All records for which PRODUCT_ID has a value of B141 or B142 are selected:

TABLE FILE GGPRODS
SUM UNIT_PRICE
BY PRODUCT_DESCRIPTION
IF PRODUCT_ID IS (EXPER)
END

If you include the selection criteria directly in the request, the IF phrase specifies the values explicitly:

IF PRODUCT_DESCRIPTION EQ 'B141' or 'B142'

The output is:

 

Unit
Product Price
------- -----
French Roast 81.00
Hazelnut 58.00

The value of PRODUCT_ID is compared to the values in the EXPER file for the selection criterion.