IFTHEN Parameter (Optional) - mfx - 3.1

Syncsort™ MFX Programmers Guide

Product type
Software
Portfolio
Integrate
Product family
Syncsort™ Software
Product
Syncsort™ MFX > MFX
Version
3.1
Language
English
Content type
Programmer’s Guide
Product name
Syncsort™ MFX
Title
Syncsort™ MFX Programmers Guide
Topic type
How Do I
Copyright
2024
First publish date
2010
Last edition
2024-08-27
Last publish date
2024-08-27T08:14:56.318001

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.

The format of the IFTHEN parameter is illustrated below.
Figure 1.  IFTHEN Parameter Format

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.

The following describes the IFTHEN subparameters:

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

BEGIN=(conditions)

Determines the logical test used to specify that a record starts a group. Each record meeting the criteria set by the logical test will begin a new group.

Under the INCLUDE/OMIT control statement, see OND Parameter (Required) for a complete description of comparisons and logical expressions. However, the following cannot be used in WHEN=GROUP:

  •    D2 format

  •    FORMAT=f

  •    Locale processing

  •    VLTESTI (during IFTHEN processing, blanks replace missing bytes in input fields)

END=(conditions)

Determines the logical test used to specify that a record ends a group. Each record meeting the criteria set by the logical test will end a group. All logical expressions used for the BEGIN option, discussed above, can be used for the END option.

WHEN=GROUP

KEYBEGIN=(p,l)

Establishes the start of a new group for a record when the field in the record beginning in column p for length l changes. The first input record will start a group. The maximum column p is 32752 and the maximum length l is 256. If KEYBEGIN and BEGIN are both used in a WHEN=GROUP clause, a new group will begin when either parameter dictates one. A dictionary_name may be used for p,l.

RECORDS=n

Determines the maximum number of records, defined by n, that can be contained in a group. This number can be defined from 1 to 2000000000. If none of the KEYBEGIN, BEGIN, or END options is specified when a RECORDS option is defined, every n records will be grouped together.

WHEN=GROUP

PUSH=([c:]psh1[,psh2]... [,pshn])

Defines the input field, sequence number, or identifier that will be overlaid for each group’s records. The following options can be used to define PUSH:

c: Specifies a record’s output column that will be overlaid. If c: is not defined for the first item, 1 will be used as a default. For variable-length records, column 5 or higher should be specified to avoid overlaying the RDW. If c: is not specified for any item, the next item starts immediately after the previous item.

If the value used for c extends the output record beyond the input record, blank bytes will be added to the left, increasing the record’s length. Should the c value extend the length of a variable-length record, the RDW length will be adjusted after all of the items are processed.

The following describes the psh elements that can be placed in a record:

p,l Specifies the position and length of a field to propagate from each group’s first input record to every record in the group. Blanks will replace missing bytes within specified input fields, allow­ing the short or missing fields to be processed.

ID=n Specifies a printable Zoned Decimal (ZD) identifier n bytes long, which will be added to every record of each group. For the first group, the identifier will start at 1 and for each subsequent group it will be increased by 1. The number n can be from 1 to 15.

SEQ=n Specifies a printable ZD sequence number n bytes long, which will be added to every record of each group. For the first record of each group, the identifier will start at 1 and for each subsequent record it will be increased by 1. The number n can be from 1 to 15.

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.

conditions

The conditions must be formulated into a comparison or logical expression that can be evaluated to true or false.

Under the INCLUDE/OMIT control statement, see COND Parameter (Required) for a complete description of comparisons and logical expressions. However, the following cannot be used in WHEN=(conditions):

  • D2 format

  • FORMAT=f

  • Locale processing

  • VLTESTI (during IFTHEN processing, blanks replace missing bytes in input fields)

The second subparameter is required. The PARSE and HIT=NEXT subparameters are optional.

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 con­junction with the WHEN=(conditions) or WHEN=ANY subparameter. IFTHEN processing stops by default once a WHEN=(conditions) sub­parameter 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.

A header record (code ‘H’) with a register number and date, detail SKU records (code ’S’) with an SKU number, unit price and quantity, and a trailer total record (code ’T’) are generated for each transaction. A file with 20-byte fixed-length records for three transactions might look like:
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
INREC WHEN=GROUP can be used with BEGIN to identify a header record starting a group and END to identify a trailer record ending a group. PUSH extends each record by placing the date and register number from the header record at the end of each record in the group, followed by a 5-byte group number and a 3-byte record sequence number. This enables all the records in a group to be sorted together.
Figure 2. Sample WHEN=GROUP Parameter

The data will be transformed into:
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
The records are then sorted using the new PUSH data.
Figure 3. Sample SORT Statement

The data added by PUSH can be eliminated from the output data with a simple OUTREC statement for the original 20 bytes of the record, or by specifying LRECL=20 on the SORTOUT DD statement, creating the following correctly sorted output.
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
If desired, a simple report can be created using OUTFIL IFTHEN to identify each different record type, format it appropriately, and remove the data added by PUSH. SECTIONS is used to generate a report header for each transaction.
Figure 4. Sample IFTHEN Parameter

The report produced is:

 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.

The following is an example of the IFTHEN parameter:
Figure 5. Sample IFTHEN Parameter

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.