sapdev logo background
sapdev logo sapdev logo
Comments

ABAP REPLACE IN POSITION Statement syntax, information and example SAP source code



Return to Statement index



REPLACE SECTION OF

Short Reference

ABAP Syntax_2 REPLACE SECTION [OFFSET off] [LENGTH len] OF dobj WITH new
[IN {CHARACTER|BYTE} MODE].

ABAP_ADDITION:
... IN {CHARACTER|BYTE} MODE

What does it do? When position-based replacements are performed, the section in dobj is replaced starting at the offset specified in off for the length specified in len with the content of the operand new . off and len are numerical expression positions
with the operand type i . new is a functional operand position .
At least one of the additions OFFSET or LENGTH must be specified. If an offset is specified but no length, the content of the data object dobj is replaced starting at the offset off and continuing to the end. If a length is specified but no offset, the offset 0 is used implicitly. The values of off and len must be greater than or equal to 0 and the section specified by off
and len must libe located within the length of dobj .

ABAP_ADDITION ... IN {CHARACTER|BYTE} MODE

What does it do? The optional IN {CHARACTER|BYTE} MODE addition determines whether character string or byte string processing is carried out. If the addition is not specified, character string processing is carried out. Depending on the processing type, dobj and new have to be character-like or byte-like.

Example ABAP Coding The statement FIND is used to determine the offset and length of the first word "know" in the data objects text1
and text2 and to replace this section in a position-based manner in 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. After the second REPLACE statement, text2 contains the truncated content "I should know that" and sy-subrc contains 2.
DATA: text1 TYPE string,
text2 TYPE c LENGTH 18,
off TYPE i,
len TYPE i.

text1 = text2 = 'I know you know'.

FIND 'know' IN text1 MATCH OFFSET off
MATCH LENGTH len.

REPLACE SECTION OFFSET off LENGTH len OF:
text1 WITH 'should know that',
text2 WITH 'should know that'.



Runtime Exceptions

Catchable Exceptions

CX_SY_RANGE_OUT_OF_BOUNDS
Reason for error: Specified offset or length violated the bounds of the string dobj .
Runtime error: REFI_WRONG_SECTION
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved








comments powered by Disqus