Ansicht
Dokumentation

ABAPREPLACE_OPTIONS - REPLACE OPTIONS

ABAPREPLACE_OPTIONS - REPLACE OPTIONS

Addresses (Business Address Services)   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.
SAP E-Book

REPLACE, options

Short Reference



... $[VERBATIM$]
    $[RESPECTING$|IGNORING CASE$]
    $[REPLACEMENT COUNT rcnt$]
    ${ ${$[REPLACEMENT OFFSET roff$]
       $[REPLACEMENT LENGTH rlen$]$}
    $| $[RESULTS result_tab$|result_wa$] $} ...

Additions

1. ... VERBATIM

2. ... RESPECTING$|IGNORING CASE

3. ... REPLACEMENT COUNT rcnt

4. ... REPLACEMENT OFFSET roff

5. ... REPLACEMENT LENGTH rlen

6. ... RESULTS result_tab$|result_wa

Effect

These additions control the statement REPLACE pattern IN and provide extended evaluation options. The addition CASE can be used to determine whether the search is case-sensitive. The additions REPLACEMENT and RESULTS can be used to determine the number, position, and length of the strings replaced.

Addition 1

... VERBATIM

Effect

The addition VERBATIM can only be used together with PCRE$|REGEX. It causes all characters in the operand new to be used literally. Special characters for replacement patterns have no effect.

Note

A REPLACE statement with addition VERBATIM is always faster than one without.

Example

While in the first REPLACE statement the $ characters have a special meaning as operators for addressing subgroups, this is not the case when the addition VERBATIM is used in the second REPLACE statement. In the third REPLACE statement, the special characters are escaped using \. While the effect of escaping is the same as for the addition, the addition VERBATIM is faster.

Addition 2

... ${RESPECTING$|IGNORING$} CASE

Effect

This addition is only allowed in character string processing. It has the same syntax and effect as the corresponding addition for searching for a substring in a data object using the FIND statement. This addition is not allowed when using an instance of class CL_ABAP_REGEX.

Example

Replacement of all uppercase characters in a string with a backquote. If IGNORING CASE were specified, all characters would be replaced.

Addition 3

... REPLACEMENT COUNT rcnt

Effect

This addition saves the number of replacements made in data object dobj to rcnt. The following can be specified for rcnt:

  • An existing variable that expects the data type i.

If no replacements are made, rcnt is set to 0.

Note

In data objects with a fixed length, the number of replacements made in data object dobj can be less than the number of occurrences.

Addition 4

... REPLACEMENT OFFSET roff

Effect

This addition saves the offset related to the data object dobj at which the last replacement was made to roff. The following can be specified for roff:

  • An existing variable that expects the data type i.

If no replacement is made, roff retains its previous value or stays initial.

Notes

  • When ALL OCCURRENCES is used, REPLACEMENT OFFSET generally returns a different value than MATCH OFFSET for the FIND statement because the position of the last found location can be shifted by previous replacements.
  • In data objects of fixed length, the value in roff refers to the last replacement within the data object. Occurrences that are shifted by previous replacements in the data object are no longer relevant.

Addition 5

... REPLACEMENT LENGTH rlen

Effect

This addition saves the length of the last substring inserted into dobj to rlen. The following can be specified for rlen:

  • An existing variable that expects the data type i.

If no replacement is made, rlen retains its previous value or stays initial.

Note

In data objects with a fixed length, the length of the last inserted string can be shorter than the length of new if the interim result is truncated.

Pattern-based replacement of all occurrences of the substring "know" in the data objects text1 and text2 with "should know that". After the first REPLACE statement, text1 contains the complete content "I should know that you know" and sy-subrc contains 0. The data objects cnt, off, and len have the values 2, 23, and 16. After the second REPLACE statement, text2 contains the truncated content "I should know that" and sy-subrc contains 2. The data objects cnt, off, and len have the values 1, 2, and 16.

Addition 6

... RESULTS result_tab$|result_wa

Effect

If at least one replacement is made, the RESULTS addition saves the offsets of the positions at which replacements were made and the lengths of the inserted substrings either in an internal table result_tab or in a structure result_wa. The syntax and meaning of the addition are otherwise the same as those for the identically named addition for the FIND statement, with the difference that the data types for result_tab and result_wa must be REPL_RESULT_TAB and REPL_RESULT, for which there is no SUBMATCHES component. As in FIND, an inline declaration DATA(var) or FINAL(var) can be specified after RESULTS.

Example

A result table results is declared inline and supplied with the properties of the seven replaced characters.






BAL_S_LOG - Application Log: Log header data   CL_GUI_FRONTEND_SERVICES - Frontend Services  
This documentation is copyright by SAP AG.

Length: 9343 Date: 20240328 Time: 195841     sap01-206 ( 157 ms )