REPLACE f WITH g INTO h.
... LENGTH len (length specification for field f )
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
SY_SUBRC = 4
String not replaced.
MOVE 'ABCB' TO FIELD.
REPLACE 'B' WITH 'string' INTO FIELD.
FIELD = 'AstringCB', SY-SUBRC = 0
The fields f and g in the REPLACE
statement should not overlap. Otherwise, the result is undefined.
... LENGTH len ... (length specification for
field f )
Searches for the string f in the field h
not in its (full) field length, but in the length len .
does not change FIELD , since 'ABC ' does not occur in
abcdeABCDE ' .
DATA: PATTERN(5) VALUE 'ABC',
LEN TYPE I,
REPL_STRING(5) VALUE '12345',
FIELD(12) VALUE 'abcdeABCDE'.
REPLACE PATTERN WITH REPL_STRING
changes FIELD to 'abcde12345DE' .
LEN = STRLEN( PATTERN ).
REPLACE PATTERN LENGTH LEN
© SAP AG 1996