REPLACE (ABAP Keyword)

REPLACE is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details.

REPLACE


Basic form
REPLACE f WITH g INTO h.

Addition


... LENGTH len (length specification for field f )

Effect
Replaces the first occurrence of the contents of field f in field h with the contents of field g . All fields are handled in their defined length; this means that closing blanks are not ignored.

The return code value indicates whether the string f was found in h and replaced by g :

SY-SUBRC = 0 String replaced.
SY_SUBRC = 4 String not replaced.

Example

DATA FIELD(10).
MOVE 'ABCB' TO FIELD.
REPLACE 'B' WITH 'string' INTO FIELD.


returns:

FIELD = 'AstringCB', SY-SUBRC = 0

Note
The fields f and g in the REPLACE statement should not overlap. Otherwise, the result is undefined.

Addition
... LENGTH len ... (length specification for field f )

Effect
Searches for the string f in the field h not in its (full) field length, but in the length len .

Example

DATA: PATTERN(5) VALUE 'ABC',
LEN TYPE I,
REPL_STRING(5) VALUE '12345',
FIELD(12) VALUE 'abcdeABCDE'.

REPLACE PATTERN WITH REPL_STRING
INTO FIELD.


does not change FIELD , since 'ABC ' does not occur in abcdeABCDE ' .


LEN = STRLEN( PATTERN ).
REPLACE PATTERN LENGTH LEN
WITH REPL_STRING
INTO FIELD.


changes FIELD to 'abcde12345DE' .

Most readed SAP Tutorials

Latest Added SAP documents

Custom Search
ABAP Tutorials ABAP Syntax BAPI SAP Jobs SAP Glossary SAP Netweaver SAP XI SAP Download SAP Interview questions

Complete SAP Study materials | SAP JOBS | PDF Tutorials   List of SAP Companies India

Google-Translate-Chinese (Simplified) BETA Google-Translate-English to French Google-Translate-English to German Google-Translate-English to Italian Google-Translate-English to Japanese BETA Google-Translate-English to Korean BETA Google-Translate-English to Russian BETA Google-Translate-English to Spanish

All of the product names here are trademarks of their respective companies. The site sapbrainsonline.com no way affiliated with SAP AG. Use information on this site at your own risk. Information furnished in the site is collected from various sites and posts from users. This site does not host any files on its server. If any compliants about the posts please contact us at sapbrain.support@gmail.com

Sitemap
web counter