The IFTHEN parameter employs conditional logic, which enables you to reformat your records based on specified criteria. Multiple IFTHEN parameters may be specified within the same control statement and are processed sequentially.
The IFTHEN parameter may be used within the INREC, OUTREC, and OUTFIL control statements.
At the beginning of IFTHEN processing, a temporary record is created from each of your input records.
The IFTHEN parameter automatically makes the following changes to the temporary record to accommodate any adjustments in length. In a variable-length record, the RDW length is adjusted accordingly. In a fixed-length record, the record is padded with blanks when necessary. Blanks also replace missing bytes in input fields.
The IFTHEN parameter has two main parts: the WHEN subparameter and a second subparameter. As shown in figure IFTHEN Parameter Format, the WHEN subparameter may be WHEN=INIT, WHEN=GROUP, WHEN=(conditions), WHEN=ANY, or WHEN=NONE. Except for WHEN=GROUP, the second subparameter may be FINDREP, PARSE and BUILD or OVERLAY. The WHEN subparameter defines a condition that must be satisfied before the second subparameter is applied to the temporary records. If the WHEN subparameter condition is not satisfied, then the second subparameter is not applied to the temporary records.
Since IFTHEN parameters refer to the temporary records instead of the input records, all subsequent IFTHEN parameters within the same control statement will take previous FINDREP, BUILD or OVERLAY changes into account. Once IFTHEN processing for each record stops, the temporary record becomes the output record.
When SEQNUM is used within a BUILD or OVERLAY parameter in an IFTHEN clause, the sequence number will be incremented each time that the BUILD or OVERLAY for that clause is performed. This may lead to different sequence numbers being generated for the same input record when SEQNUM is used in different IFTHEN clauses.
You can use %pp parsed fields in IFTHEN expressions. If the %pp field is defined in a WHEN=INIT, WHEN=(conditions), WHEN=ANY, or WHEN=NONE expression, it can be used in the IFTHEN BUILD or IFTHEN OVERLAY of that expression. Additionally, for WHEN=INIT, the %pp fields can be used in any subsequent IFTHEN BUILD or OVERLAY expression. See PARSE Parameter (Optional) for further description on PARSE.
WHEN=INIT |
The WHEN=INIT subparameter condition is automatically satisfied. It applies the remaining IFTHEN subparameters to each temporary record. A second subparameter is required. PARSE is optional if BUILD or OVERLAY is specified. |
||||
WHEN=GROUP | The WHEN=GROUP subparameter is satisfied if a record meets the specified grouping options. A WHEN=GROUP clause can be combined with WHEN=INIT clauses, but must be defined before using the WHEN=(conditions), WHEN=NONE, or WHEN=ANY subparameters. WHEN=GROUP groups records and propagates fields, identifiers, and sequence numbers based on the criteria specified in the BEGIN=(conditions), END=(conditions), KEYBEGIN=(p,l), RECORDS=n, and PUSH=(c:item,...) options. At least one BEGIN=(conditions), END=(conditions), KEYBEGIN=(p,l) or RECORDS=n option must be specified. |
||||
WHEN=GROUP |
|
||||
WHEN=GROUP |
|
||||
WHEN=GROUP |
|
||||
WHEN=(conditions) |
The WHEN=(conditions) subparameter condition is satisfied if a
temporary record meets the specified conditions. It applies the
specified second subparameter to each temporary record that
meets the specified conditions.
|
||||
WHEN=ANY |
The WHEN=ANY subparameter condition is satisfied if one or more of its associated WHEN=(conditions) subparameter conditions have been satisfied. Its associated WHEN=(conditions) subparameters are those that precede it but no other WHEN=ANY subparameter. If the WHEN=ANY subparameter condition is satisfied, it applies the specified second subparameter to the temporary record. The second subparameter is optional. If it is not used, IFTHEN processing simply stops if the WHEN=ANY subparameter condition is satisfied unless the optional HIT=NEXT subparameter has been specified. |
||||
WHEN=NONE |
The WHEN=NONE subparameter condition is satisfied if none of the preceding WHEN=(conditions) subparameter conditions is satisfied or if there are no WHEN=(conditions) subparameters. If the WHEN=NONE subparameter condition is satisfied, it applies the specified second subparameter to the temporary record. The second subparameter is optional. If it is not used, IFTHEN processing simply stops if the WHEN=NONE subparameter condition is satisfied unless the optional HIT=NEXT subparameter has been specified. |
The IFTHEN parameters must be specified such that the WHEN subparameters are in the following order:
-
WHEN=INIT and/or WHEN=GROUP
-
WHEN=(conditions) and WHEN=ANY
-
WHEN=NONE
BUILD |
Except for the WHEN=GROUP subparameter, the IFTHEN parameter will accept BUILD as a second subparameter. See FIELDS/BUILD Parameter for a complete description of the BUILD subparameter. |
OVERLAY |
Except for the WHEN=GROUP subparameter, the IFTHEN parameter will accept OVERLAY as a second subparameter. See OVERLAY Parameter (Optional) for a complete description of the OVERLAY subparameter. |
HIT=NEXT |
The HIT=NEXT subparameter is optional, but can only be used in conjunction with the WHEN=(conditions) or WHEN=ANY subparameter. IFTHEN processing stops by default once a WHEN=(conditions) subparameter condition or WHEN=ANY subparameter condition is satisfied. Including the HIT=NEXT subparameter will continue IFTHEN processing regardless of whether or not the WHEN subparameter condition is satisfied. |
PARSE |
The PARSE parameter is optional except in WHEN=INIT if BUILD or OVERLAY is not specified. PARSE is used to extract variable-position and variable-length fields from records and place the resultant data into fixed-length parsed fields. PARSE cannot be used in a WHEN=GROUP clause. See PARSE Parameter (Optional)for further description. |
FINDREP |
The FINDREP parameter provides the ability to find and replace one or more constants in a record. A constant to be searched for can be specified as a character or hexadecimal string and its replacement constant can be either a character, hexadecimal or null string. Depending on the length of the replacement constant, subsequent characters will be shifted left or right. For fixed-length records, if data is shifted left, the record will be padded with blanks as needed. If data is shifted right, any trailing blank characters will be removed. Variable-length records will have their length adjusted as appropriate. If a variable-length record exceeds its maximum record length, trailing blanks will be deleted. Optionally, controls are provided to specify the positions to be scanned, the number of times a find/replace operation can occur, actions to be taken if a non-blank character needs to be shifted past the record length, a new record length or whether a replace or overlay of the find constant is to be performed. See FINDREP Parameter (Optional) for details on its use. |
The following example outlines the use of the WHEN=GROUP parameter.
WHEN=GROUP can be useful for keeping together groups of unlike input records, enabling them to be correctly sorted.
For instance, if each transaction at a store generates a series of unlike records, and all the records are collected in a file that needs to be sorted by date and register number, WHEN=GROUP can generate appropriate sort keys for each record in the group.
H 0003 2008/08/17
S 872567 0010.22 001
S 510945 0001.99 003
S 734018 0003.98 002
T 0024.15
H 0005 2008/08/16
S 013298 0000.69 004
S 510945 0017.03 001
T 0019.79
H 0002 2008/08/17
S 212134 0003.49 003
T 0010.47
H 0003 2008/08/17 2008/08/17000300001001
S 872567 0010.22 0012008/08/17000300001002
S 510945 0010.99 0032008/08/17000300001003
S 734018 0003.98 0022008/08/17000300001004
T 0024.15 2008/08/17000300001005
H 0005 2008/08/16 2008/08/16000500002001
S 013298 0000.69 0042008/08/16000500002002
S 510945 0017.03 0012008/08/16000500002003
T 0019.79 2008/08/16000500002004
H 0002 2008/08/17 2008/08/17000200003001
S 212134 0003.49 0032008/08/17000200003002
T 0010.47 2008/08/17000200003003
H 0005 2008/08/16
S 013298 0000.69 004
S 510945 0017.03 001
T 0019.79
H 0002 2008/08/17
S 212134 0003.49 003
T 0010.47
H 0003 2008/08/17
S 872567 0010.22 001
S 510945 0001.99 003
S 734018 0003.98 002
T 0024.15
DATE REG# ID
2008/08/16 0005 00002
SKU#: 013298 PRICE: $0000.69 QUANTITY: 004
SKU#: 510945 PRICE: $0017.03 QUANTITY: 001
TOTAL: $0019.79
DATE REG# ID
2008/08/17 0002 00003
SKU#: 212134 PRICE: $0003.49 QUANTITY: 003
TOTAL: $0010.47
DATE REG# ID
2008/08/17 0003 00001
SKU#: 872567 PRICE: $00010.22 QUANTITY: 001
SKU#: 510945 PRICE: $0001.99 QUANTITY: 003
SKU#: 734018 PRICE: $0003.98 QUANTITY: 002
TOTAL: $0024.15
IFTHEN Processing Considerations
In an OUTFIL control statement, the IFTHEN parameter may be used with FTOV, VLTRAIL, or VLTRIM. The IFTHEN parameter may not be used with CONVERT or VTOF. Under the OUTFIL control statement, see FTOV Parameter (Optional) for a complete description of the FTOV parameter, VLTRAIL Parameter (Optional) for a complete description of the VLTRAIL parameter, and VLTRIM Parameter (Optional) for a complete description of the VLTRIM parameter.
IFTHEN processing continues until:
-
All IFTHEN parameters have been processed.
-
A WHEN=(conditions) or WHEN=ANY subparameter condition is satisfied and the HIT=NEXT subparameter is not included.
-
Multiple output records are created with the / subparameter. Under the OUTREC parameter of the OUTFIL control statement, see [n]/ for a complete description of the / subparameter.
This OUTREC control statement refers to 80-byte input records containing a salesperson’s weekly sales in dollars in the first field (1,8,ZD) of each record. There are five IFTHEN parameters in the example and they reformat each input record as follows:
-
The first IFTHEN parameter uses WHEN=INIT to take the sales total in the first field (1,8,ZD), increase it by 7%, and enter the result in a new 15-byte ZD field in column 81.
-
The second IFTHEN parameter uses WHEN=(conditions) to test if the newly adjusted sales total in the field (81,15,ZD) is over $10,000. If it is, the second IFTHEN parameter increases the total by $500 and replaces the result in that field.
-
The third IFTHEN parameter uses WHEN=(conditions) to test if the newly adjusted sales total in the field (81,15,ZD) is over $20,000. If it is, the third IFTHEN parameter increases the total by $2,000 and replaces the result in that field.
-
The fourth IFTHEN parameter uses WHEN=ANY to test the second and third IFTHEN parameters. If one or both WHEN subparameter conditions are satisfied, indicating that the salesperson is getting a bonus, the fourth IFTHEN parameter inserts an “*” in column 96 to denote a bonus, calculates a commission rate of 15%, and enters the result in column 97.
-
The fifth IFTHEN parameter uses WHEN=NONE to test the second and third IFTHEN parameters. If neither WHEN subparameter condition is satisfied, indicating that the salesperson is not getting a bonus, the fifth IFTHEN parameter calculates a commission rate of 12% and enters the result in column 97.