FINDREP 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
Copyright
2024
First publish date
2010
Last updated
2024-11-06
Published on
2024-11-06T17:38:26.716054

The FINDREP parameter allows you to find one or more constants in a record and replace them with a provided constant.

FINDREP compares the current position in an input record to an input constant, seeking a match. By default it starts with position 1 for fixed-length records and position 5 for variable-length records. The current position will increase by 1 until a match is found. Once FINDREP discovers a match at the current position, the output constant will supplant the input constant, the current position will advance beyond the location of the replaced input constant, and the process will continue. Bytes appearing after the replaced constants will be moved either left or right as necessary until the current position reaches the record's final position and processing ceases.

For fixed-length records if a record needs to be shortened due to a shorter replace constant, it will be padded with trailing blanks as needed. If a fixed-length record is lengthened, 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.

FINDREP processing requires input and output constants to be specified. An input constant can be any of the following: a single hexadecimal string, a repeated hexadecimal string, a single character string, or a repeated character string. An output constant can be any of the following: a single hexadecimal string, a repeated hexadecimal string, a single character string, a repeated character string, or a null string. Permissible syntax expressions for input and output constants are listed below.

  • C’string’

  • nC’string’

  • X’string’

  • nX’string’

  • C”    This expression can only be used to define a null output constant.

Note the following considerations for defining input and output constants:

  • The maximum length of either an input or an output constant is 256 bytes.

  • Two apostrophes must be used to specify a single apostrophe.

  • Input constants can be removed through use of a null output constant.

The format of the FINDREP parameter is shown below:
Figure 1. FINDREP Parameter Format

IN=(ic1[,ic2]…[,icn] )

Specifies one or more input constants that will be searched for during the FINDREP operation. Each ic specifies an input constant to search for. See description above on how to specify input constants.

OUT=oc

Specifies the output constant that will be used to replace any of the input constants that are found. oc represents the output constant used in the replace operation. See description above on how to specify output constants.

INOUT=(ic1,oc1[,ic2,oc2]…[,icn,ocn]  

Specifies pairs of input constants and output constants that will be used in the FINDREP operation. Each ic specifies an input constant to search for. Each oc represents the output constant for the replace operation. See description above on how to specify input and output constants.

By default, the FINDREP function starts at position 1 for fixed-length records or position 5 for variable-length records and ends processing at the end of the record. The following options will alter the default FINDREP behavior:

STARTPOS=p

Use this option to change the starting position of a fixed-length record’s default position of 1 or a variable-length record’s default position of 5. The STARTPOS=p option uses the variable p to denote starting position. For variable-length records, p will be reset to 5 if a value less than 5 is specified. If p is greater than the length of the input record, FINDREP will perform no action on the record.

ENDPOS=q

Use this option to change the ending position of the FINDREP operation. The ENDPOS=q option uses the variable q to denote the last position to scan in the input record. For variable-length records, q will be reset to 5 if a value less than 5 is specified. When both ENDPOS=q and STARTPOS=p are defined, if q is less than p, FINDREP will perform no action for the record. ENDPOS does not affect the shifting of bytes during the FINDREP operation.

DO=n

Use this option to limit the maximum number of times FINDREP will be performed for a record. The DO=n option uses the n variable to denote the number of times an input constant is found and replaced, in which n can be between 1 and 1000. FINDREP will stop scanning for input constants when n input constants have been found and replaced.

MAXLEN=m

Use this option to change the maximum length of the output record, which has a default of the maximum record length input to FINDREP. The MAXLEN=m option uses the m variable to denote the maximum length of the record. MAXLEN can increase or decrease the record length, except for an IFTHEN FINDREP where it can only increase the record length. MAXLEN can be used to increase the record length when the replace constants are longer than the find constants. For further details, see the "Considerations" section.

OVERRUN=ERROR

Use the default OVERRUN=ERROR option to specify how overruns are handled by MFX. Overruns will occur when non-blank bytes need to be shifted beyond the maximum record length or when MAXLEN=n is used to shorten an output record’s length to be fewer than the total number of trailing non-blank bytes. OVERRUN=ERROR will issue the WER439A error message and terminate MFX when overruns occur.

OVERRUN=TRUNC

Use the OVERRUN=TRUNC option to truncate the output record and prevent an error message from appearing if an overrun happens. If you choose to employ the OVERRUN=TRUNC option, MFX will eliminate all bytes beyond the end of the output record length.

Use this option to change how an output constant will replace an input constant of a different length. The default SHIFT=YES option will instruct MFX to accommodate longer output constants by shifting bytes to the right and shorter output constants by shifting bytes to the left. If you select the SHIFT=NO option, MFX will overlay an input constant with its corresponding output constant without moving bytes left or right. When SHIFT=NO is specified, the current position for FINDREP will be advanced by the shorter of the input and output constants when a match is found.

Considerations:

  • In an IFTHEN clause, you cannot use FINDREP with BUILD or OVERLAY.

  • In an INREC or OUTREC statement, you cannot use FINDREP with BUILD, OVERLAY, IFTHEN or IFOUTLEN, although FINDREP within an IFTHEN clause is permitted.

  • In an OUTFIL statement, you cannot use FINDREP with BUILD, OVERLAY, IFTHEN, IFOUTLEN, VTOF, CONVERT or VLFILL, although FINDREP within an IFTHEN clause is permitted.

  • After a constant has been replaced at the current position in a single FINDREP option, no further checks are performed at that position. One FINDREP statement cannot be used to replace a constant and then replace the original constant’s replacement.

  • In an IFTHEN clause employing FINDREP on a fixed-length record, the FINDREP uses the input record length.

The following examples outline the proper uses of the FINDREP parameter and its subparameters.

Example 1

The following is an example of the FINDREP parameter on an OUTREC statement which is used to replace state abbreviations in a record with their full names. The FINDREP operation is restricted to columns 60 to 75. The input consists of 80-byte fixed-length records. Trailing blanks will be truncated from the records when the replace constant is substituted.
Figure 2. Sample FINDREP Parameter

If the original records contained:
Figure 3. Sample of Original Records

The modified records would contain:
Figure 4. Sample of Modified Records

In the above example, if the values to be replaced were positioned closer to column 80, it would be possible that the trailing zip code would be pushed past column 80. By default this would generate an error since only blanks can be truncated from a record. This error could be avoided by specifying the MAXLEN parameter to extend the record length to accommodate the new longer replacement literals. The following OUTREC control statement could address this problem:
Figure 5. Sample FINDREP Parameter with MAXLEN

If non-blank characters after the replacement string are not needed, the OVERRUN=TRUNC option can be specified to remove the trailing characters from the record. For example, the following can be used:
Figure 6. Sample FINDREP Parameter with OVERRUN=TRUNC

Example 2

In the following example an INREC statement will be used to abbreviate each instance of ‘NEW JERSEY’ and ‘NEW YORK’ in a record when position 24 of the record contains a X’01’.
Figure 7. Sample FINDREP Parameter

For the input record:
Figure 8. Sample Input Record

The output record would contain:
Figure 9. Sample Output Record

If the records are variable-length, the RDW of the record would be reduced to indicate the new length after the shorter literals are substituted. If the records are fixed-length, spaces would be appended to the end of the record to replace the deleted characters.

Example 3:

In the following example, the input constant will be replaced by the output constant without shifting bytes to accommodate the replaced constant. This can be used to replace only a portion of the input search constant with a new constant. In this example, a portion of the input constant will be replaced.
Figure 10. Sample FINDREP Parameter

For the input record:
Figure 11. Sample Input Record

The output record would be
Figure 12. Sample Output Record

Note that in this instance where the output constant is shorter than the input constant, the FINDREP operation will resume at the next character after the output constant rather than the input constant as would normally be the case.