Use the WHEN directive when you want to include multiple record definitions or REDEFINES in the XFD. The WHEN directive typically is used to force certain columns of data to be available that wouldn't be available otherwise. See REDEFINES Clause for information about REDEFINES.
Recall that the key fields and the fields from the largest record are automatically included as explicit columns in the indexed file database table. So you should use the WHEN directive if you want the user to be able to access all the data in the COBOL file in a way that is understandable. See How XFDs are Formed for details about how fields are included in the database table.
WHEN declares that the field (or subordinate fields, if it is a group item) that immediately follows the directive must appear as a column (or columns) in the indexed file database table. It also states one condition under which the columns are to be used. The WHEN directive thus guarantees that the fields will be explicitly included in the table (as long as they aren't FILLER and don't occupy the same area as key fields).
$XFD WHEN field operator value
*(( XFD WHEN field operator value ))where
|field||Specifies the name of a data item that corresponds to a field; if there is a NAME directive for this data item, the name used in the WHEN directive is the name given to the item by the NAME directive, not its COBOL name|
|operator||Specifies the relation between the field value and the alphanumeric literal that satisfies the condition;
operator can be one of the following:
|value||Is one of the following:
01 key-record. * employee-number is a key data item 03 employee-number pic 99999. 03 emp-type pic x. $xfd when emp-type="1" * record has this form when emp-type="1" 01 data-record-1. 03 filler pic 99999. 03 filler pic x. 03 name-1 pic x(35). 03 pay-rate-1 pic 99.99. $xfd when emp-type="2" * record has this form when emp-type="2" 01 data-record-2 03 filler pic 99999. 03 filler pic x. 03 name-2 pic x(35). 03 pay-rate-2 pic 999.99. 03 subordinates pic 999. 03 position pic x(50).
If each data item is subordinate to at most one WHEN directive, as in this example, the following occurs:
If a data item is subordinate to two or more WHEN directives, the following applies: