Ansicht
Dokumentation

ABENSHIFT_FUNCTIONS - SHIFT FUNCTIONS

ABENSHIFT_FUNCTIONS - SHIFT FUNCTIONS

BAL_S_LOG - Application Log: Log header data   ABAP Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

- shift_left, shift_right

The shift functions shift the content of a character-like argument.

1. ... shift_left( $[val =$] text
                  $[places = places$]$|$[circular = places$]$|$[ sub = substring$] ) ...

2. ... shift_right( $[val =$] text
                   $[places = places$]$|$[circular = places$]$|$[ sub = substring$] ) ...


Effect

The built-in 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 places is given a numeric value, the corresponding number of characters is removed on the left or right of the character string and the length of the character string is reduced accordingly. If the value of places is negative or longer than the character string, an exception of the class CX_SY_RANGE_OUT_OF_BOUNDS is raised.
  • If the argument circular is given a numeric value, the functions behave like places, but insert the removed substring at the end or start of the character string.
  • If the argument sub is given a character string in substring, all substrings in the character string from text are removed on the left or right that match the content of substring. If no substrings are found or if substring is given an empty string, the character string remains unchanged.
  • If none of the arguments places, circular, or sub are specified, the functions behave as if the sub argument were passed a blank character. All blank characters to the left or right are removed. In this case, an explicit val can also be omitted.

places and circular are numeric expression positions of type i.

The return value has the type string.

Note

When places is specified, the function shift_right behaves differently than the statement SHIFT with the additions RIGHT and PLACES. The function shift_right reduces the length of the string, but the statement SHIFT lengthens it or it remains the same.

Example

The following program line

txt = shift_right( txt ).

has the same meaning as

txt = shift_right( val = txt sub = ` ` ).

and removes the trailing blanks from a string txt.

String Functions, shift and substring

Exceptions

Catchable Exceptions

CX_SY_RANGE_OUT_OF_BOUNDS

  • Cause: Invalid value in places.
    Runtime Error: STRING_LENGTH_TOO_LARGE or STRING_LENGTH_NEGATIVE





BAL Application Log Documentation   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.

Length: 4428 Date: 20240328 Time: 163920     sap01-206 ( 62 ms )