SHIFT keyword in ABAP is used for shifting the characters in a string to left , right or circular. There are many options like how many places should shift, and from which character should shift happen etc with this statement. We will get a clear idea by going through various usage of this keyword as follows.
Additions used with
- SHIFT string_variable.
DATA NUMBERSTRING(10) VALUE ‘0123456789’.
Result : Now the NUMBERSTRING will be ‘123456789’ ( by default it will shift to LEFT direction )
- SHIFT NUMBERSTRING RIGHT.
Result : NUMBERSTRING will be ‘012345678’
- SHIFT NUMBERSTRING CIRCULAR.
Result : NUMBERSTRING will be ‘1234567890’ ( now the missing left side character comes into the right end. That means it will shift circularly )
- SHIFT NUMBERSTRING RIGHT CIRCULAR.
Result : NUMBERSTRING will be ‘9012345678’
- SHIFT NUMBERSTRING BY FIVE PLACES.
Result : NUMBERSTRING will be ‘56789’ ( Here it specifies how many characters should shifted ) We can use the same RIGHT, LEFT, CIRCLAR additions with this type of shifting
- SHIFT NUMBERSTRING UP TO ‘456’.
Result : NUMBERSTRING will be ‘456789’ ( It will search the string 456 in main string and will do the shift till the searched string will be one left side )
- SHIFT NUMBERSTRING CIRCULAR UP TO ‘456’.
Result : NUMBERSTRING will be ‘4567890123’
- SHIFT NUMBERSTRING LEFT DELETING LEADING character1. ( Shifting till the first character of character1 will be on left, blank spaces will be added )
- SHIFT NUMBERSTRING LEFT DELETING LEADING SPACE. ( Leading blank spaces will be deleted )
- SHIFT NUMBERSTRING RIGHT DELETING TRAILING character1.
DELETING LEADING addition can be used for deleting the leading blanks in a string.