The FindReplace procedure scans a text string for a pattern and replaces the pattern in the text string with replacement text.
The FindReplace procedure can be used to replace or delete/remove text from an existing character field. The original data is not modified by the procedure. The new value is returned to the caller as the return value for the procedure and may be assigned (copied to) another field or the same field.
varying-length-char-value FindReplace( szFindWhat 4096A Const Varying : szReplaceWith 4096A Const Varying : szSearchedText 65535A Const Varying : bOptions 1A Const Options(*NOPASS : *OMIT) : |
| Symbolic Named Constant | Value | Description |
| FR_FINDFIRST | X'01' | Causes the search to end after one match is detected and replaced. |
| FR_MATCHCASE | X'02' | Causes the search to use the upper/lower case letters to match the find text. |
| FR_CHAR | X'04' | Causes the search to be performed individually for each character of the szFind parameter. That is each character in the szFind parameter is located and individually replaced with the szReplace text. |
The default for bOptions is not FR_FINDFIRST it means find-all-matches and if it is not FR_MATCHCASE it means ignore upper lower case while searching but respect it when inserting the replacement text. To use this parameter, a bit mask must be created. In RPG IV under OS/400 V5R2 and later use the %BITOR built-in function, under earlier releases, use the BITON operation code as follows:
.....DName+++++++++++EUDS.......Length+TDc.Functions++++++++++++++++++++++++++++
D bOptions S 1A Inz(X'00')
.....CSRn01..............OpCode(ex)Extended-factor2+++++++++++++++++++++++++++++
C/IF DEFINED(*V5R2M0)
C Eval bOptions = %BITOR(bOptions : FR_FINDFIRST)
C/ELSE
C BitOn FR_FINDFIRST bOptions
C/ENDIF
If the function succeeds, the return value is the a varying length text string that contains the modified szSearchText value with the szFindWhat text replaced with the szReplaceWith text.
If the function fails, the return value is empty.
This procedure updates the following exported fields.
- FR_OVERFLOW - Indy: *ON if the result is longer than the original szSearchText field's lengths.
- FR_RESULTLEN - Int(4): Contains the length of the new text with the replacement text inserted. Check this field to determine if your result field was large enough to accommodate the entire replacement string.
- FR_REPLACECNT - Int(4): Indicates the number of times the find/replace action was performed. Use this field or pass the nCount parameter to receive this value.