Ansicht
Dokumentation

ABENREPLACE_FUNCTIONS - REPLACE FUNCTIONS

ABENREPLACE_FUNCTIONS - REPLACE FUNCTIONS

rdisp/max_wprun_time - Maximum work process run time   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.
SAP E-Book

- replace

1. ... replace( val = text $[ off = off$] $[len = len$]
               with = new ) ...

2. ... replace( val = text ${ sub = substring$}$|${pcre = regex$}
               with = new $[ case = case$] $[occ = occ$] ) ...


Effect

This built-in function replaces a substring of text with the character string specified in new and returns the changed text.

The substring is determined as follows:

  • The variant with the arguments off and len replaces the substring determined by the offset off and the length len. At least one of these additions must be defined.
  • The variant with the arguments sub or pcre searches the text for the occurrence specified in occ for a match with the substring specified in substring or with a regular expression specified in regex and replaces the occurrence.
regex must contain a PCRE regular expression. A regular expression in PCRE syntax is compiled in an extended mode: Most unescaped whitespace (blanks and line breaks) of the pattern are ignored outside character classes and comments can be placed behind #. In order to include whitespace and # into a pattern, they must be escaped or the extended mode must be switched of with (?-x) in the regular expression.
If occ contains the value 0, all occurrences are replaced. If substring is empty, an exception of the class CX_SY_STRG_PAR_VAL is raised. The search is case-sensitive by default, but this can be overridden using the parameter case. If no substring is found, the unchanged content of text is returned.

new is a character-like expression position. If this has a fixed length, trailing blanks are ignored.

The return value has the type string.

Notes

  • Borderline cases for the variants with the arguments off and len:
  • If only off is specified or if the value 0 is specified for len, replace works like the insert function.

  • If only len is specified or if off has the value 0, the first segment of the length len is replaced.

  • If the value of off is equal to the length of text, the value of len must be equal to 0 or len is not specified. The character string new is then appended to the end of text.

  • If a regular expression is used with regex, special replacement patterns that allow references to the respective occurrences can be specified in new. It should be noted that in regular replacement texts, the associated special characters $, &, `, and ´ as well as the escape character \ must be transformed to literal characters using the prefix \.

Example

The result of the following replacement is

aa_XX_cc

The substring "bb" starting at offset 3 having a length of 2 is replaced with "XX".

Example

The result of the following replacements are

aa_bb_cc

and

aabbcc

First, all occurrences (occ = 0) of substring "-" are replaced with "_", then these are replaced by an empty string, hence removed.

The result of the following replacement is

title>Thbi/b>s bi/b>s the iTbi/b>tle/i>/title>.

In an HTML line, a particular letter is surrounded by format tags if it is not within a tag itself.

Exceptions

Catchable Exceptions

CX_SY_RANGE_OUT_OF_BOUNDS

  • Cause: Illegal offset or length specified in off and len.
    Runtime Error: STRING_OFFSET_TOO_LARGE

CX_SY_REGEX_TOO_COMPLEX

CX_SY_STRG_PAR_VAL

  • Cause: Substring in sub or regular expression in regex is empty.
    Runtime Error: STRG_ILLEGAL_PAR





ROGBILLS - Synchronize billing plans   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.

Length: 8041 Date: 20240425 Time: 121036     sap01-206 ( 105 ms )