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.
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. |
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
Example 2
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:
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.