ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Character String and Byte String Processing → Expressions and Functions for String Processing → String Functions → Processing Functions for Character-Like Arguments
shift_left, shift_right - Shift Functions
The shift functions shift the content of a character-like argument.
Other versions: 7.31 | 7.40 | 7.54
Syntax Forms
-
... shift_left( [val =] text
[places = places]|[circular = places]| [sub = substring] ) ... -
... shift_right( [val =] text
[places = places]|[circular = places]| [sub = substring] ) ...
Effect
The functions shift_left and shift_right shift
the character string text to the left or to the right and return the result. The shift depends on the parameter pass as follows:
- If the argument
placesis given a numerical value, this many characters are removed on the left or right of the character string and the length of the character string is reduced accordingly. If the value ofplacesis negative or longer than the character string, an exception of the class CX_SY_RANGE_OUT_OF_BOUNDS is raised.
- If the argument
circularis given a numerical value, the functions work likeplaces, but insert the substring again at the end or start of the character string.
- If the argument
subis given a character string insubstring, all substrings in the character string fromtextare removed on the left or right that match the content ofsubstring. If no substrings are found or ifsubstringis given an empty string, the character string remains unchanged.
- If none of the arguments
places,circular, orsubare specified, the functions work as if thesubargument has been passed a blank character. All blank characters to the left or right are removed. In this case, an explicitval=can also be omitted.
places and circular are
numerical expression positions of type i.
The return code has the type string accordingly.
Note
When places is specified, the function shift_right
behaves differently from the statement SHIFT with the additions RIGHT
and PLACES. The function shift_right reduces the
length of the string, but the statement SHIFT makes the string longer or keeps it the same length.
Example
Exceptions
Catchable Exceptions
CX_SY_RANGE_OUT_OF_BOUNDS
-
Cause:Invalid value in
places.
Runtime Error:STRING_LENGTH_TOO_LARGEorSTRING_LENGTH_NEGATIVE