i-effect Manual
German English
German English

RPLSTRIFS, replace character string in input file

Usage

The RPLSTRIFS command can be used to replace a string in the input file with another value.

Important as of version 3.1.13: With CASE(*NO), the default value, the search string is evaluated as a regular expression. Characters such as . * + ? ( ) [ ] | then have a special meaning and must be escaped if they are to be searched for literally. Up to version 3.1.12, CASE(*NO) also searched literally. See section “Special characters with CASE(*NO)”.

Parameters and their meaning

The command has the following parameters

Parameter

Element

Value

Description

FRMPATH



Name of the input path in the IFS file system. If the command is defined in the i-effect *SERVER *IFS server entry as a *USERDEFINED processing step, the server variable %IFSPATH% can be used.

FRMIFSFILE



Name of the input file in the IFS file system without path. If the command is defined in the i-effect *SERVER *IFS server entry as a *USERDEFINED processing step, the server variable %IFSFILE% can be used.

FRMCCSID



This parameter is no longer used. The CCSID is read from the attributes of the input file.

CASE

*YES


The search is case-sensitive. The search string is searched for literally; no character has a special meaning.


*NO


Default value. The search is not case-sensitive. The search string is evaluated as a regular expression. Special characters must be escaped with \ if they are to be searched for literally (e.g. \* or \+). Alternatively, the whole string can be enclosed in \Q and \E (e.g. \QST*850\E).

REPLACE



Here you specify which search patterns are replaced with which values in the input file. Up to 50 replacement rules can be defined. They are carried out one after another in the order specified.


Element 1


This element defines the search pattern. With CASE(*YES), it is searched for literally; with CASE(*NO), it is evaluated as a regular expression.



HEXsearch pattern

By specifying the string HEX before the actual search pattern, the string to be searched for can be specified in hexadecimal notation. The values refer to the character encoding (CCSID) of the input file, e.g. line end x'0D0A' in an ASCII file (CCSID 1252) and x'0D25' in an EBCDIC file (CCSID 273).

A hexadecimal search pattern is also evaluated as a regular expression with CASE(*NO). HEX2B (character + in ASCII) then causes an error. Use HEX5C2B (\+) or CASE(*YES) to search for the character literally.


Element 2


This element defines the replacement string with which each match of element 1 is replaced.



HEXstring

By specifying the string HEX before the actual replacement string, the replacement can be specified in hexadecimal notation, also in the character encoding of the input file.

REPLACE((HEX3B HEX3B0D0A))



*CRLF

The string found is replaced with a line break CR LF (x'0D0A' in ASCII, x'0D25' in EBCDIC).

REPLACE((';' *CRLF))



*LF

The string found is replaced with a line feed LF (x'0A' in ASCII, x'25' in EBCDIC).

REPLACE((';' *LF))



*ADDCRLF

A line break CR LF is inserted after element 1.

REPLACE(('''' *ADDCRLF))



*ADDLF

A line feed LF is inserted after element 1.

REPLACE(('''' *ADDLF))

With *ADDCRLF and *ADDLF, element 1 itself is inserted, not the text found. Therefore, use these values only with search patterns without special characters, or specify CASE(*YES).



COMMAND:

Nothing is replaced. If element 1 is found in the file, the command specified after COMMAND: is run. Element 1 is always searched for literally and case-sensitively, regardless of the CASE parameter. Do not escape special characters here.

REPLACE(('ST*850' 'COMMAND: ADDENVVAR ENVVAR(MAPID) VALUE(ORDERS_X12_850) REPLACE(*YES)'))

USESEPCHAR



This parameter is no longer used and will be removed in a future version.

USEBUFFER



This parameter is no longer used and will be removed in a future version.

Special characters with CASE(*NO)

With CASE(*NO), the following characters have a special meaning in the search pattern. To search for them literally, put a \ in front of them or use CASE(*YES).

Character

Meaning in the regular expression

Search literally

.

any character

\.

*

previous character any number of times (including zero)

\*

+

previous character at least once

\+

?

previous character optional

\?

^ $

start or end

\^ \$

( )

group

\( \)

[ ]

character set

\[ \]

{ }

number of repetitions

\{ \}

|

or

\|

\

escape character

\\

Examples of use

Description

Command parameters

Replace the string EANCOM with the string UN in the input file (no special characters, no escaping needed)

RPLSTRIFS FRMPATH('/home/ieffect/as/receive') FRMIFSFILE(orders.edi) REPLACE((EANCOM UN))

Replace ST*850 with ST*860. Without escaping, nothing is found with CASE(*NO) because * is evaluated as “any number of times”.

Wrong:   RPLSTRIFS ... REPLACE(('ST*850' 'ST*860'))
Correct: RPLSTRIFS ... REPLACE(('ST\*850' 'ST*860'))
Correct: RPLSTRIFS ... REPLACE(('\QST*850\E' 'ST*860'))
Correct: RPLSTRIFS ... CASE(*YES) REPLACE(('ST*850' 'ST*860'))

Replace the character + with :. Without escaping, the command ends with an error with CASE(*NO).

Wrong:   RPLSTRIFS ... REPLACE(('+' ':'))
Correct: RPLSTRIFS ... REPLACE(('\+' ':'))

Replace 1.5 with 1,5. Without escaping, the dot matches any character, so also 105 or 1-5.

Wrong:   RPLSTRIFS ... REPLACE(('1.5' '1,5'))
Correct: RPLSTRIFS ... REPLACE(('1\.5' '1,5'))

Using a regular expression on purpose: replace several spaces with one

RPLSTRIFS ... REPLACE((' {2,}' ' '))

Insert a line break after each EDIFACT segment terminator (')

RPLSTRIFS ... REPLACE(('''' *ADDCRLF))

Insert a line break after each semicolon, in hexadecimal notation for an ASCII file

RPLSTRIFS ... REPLACE((HEX3B HEX3B0D0A))

Remove line breaks from an ASCII file

RPLSTRIFS ... REPLACE((HEX0D0A ''))

For incoming X12 files, set an environment variable with the mapping ID if ST*850 is in the file. COMMAND: searches literally, so the * is not escaped. The environment variable can then be used in RUNMAP.

RPLSTRIFS FRMPATH('%IFSPATH%') FRMIFSFILE('%IFSFILE%') REPLACE(('ST*850' 'COMMAND: ADDENVVAR ENVVAR(MAPID) VALUE(ORDERS_X12_850) REPLACE(*YES)'))
RUNMAP MAPID('%GETENVVAR:MAPID%') FS(*IFS) ERRPATH('/i-effect/edi/error') ARCPATH(*NONE)