SHIFT

SHIFT

Variants:

1. SHIFT c.
2. SHIFT c BY n PLACES.
3. SHIFT c UP TO c1.
4. SHIFT c LEFT DELETING LEADING c1.
5. SHIFT c RIGHT DELETING TRAILING c1.

Note

As with any string processing statement, all the operands are processed here as type C fields (regardless of type). No internal conversion is performed.

Additions:

1. ... CIRCULAR
2. ... RIGHT
3. ... LEFT

Effect

Shifts the field c one position to the left. The first letter is omitted and a blank is inserted on the right.

Example

DATA ALPHABET(10) VALUE 'ABCDEFGHIJ'. 
SHIFT ALPHABET.

ALPHABET now contains 'BCDEFGHIJ '.

Effect

Shifts the field c, so the "lost" character on the left appears on the right.

Example

DATA ALPHABET(10) VALUE 'ABCDEFGHIJ'. 
SHIFT ALPHABET CIRCULAR.

ALPHABET now contains 'BCDEFGHIJA'.

Effect

Shifts the field c to the right instead of the left.

Example

DATA ALPHABET(10) VALUE 'ABCDEFGHIJ'. 
SHIFT ALPHABET RIGHT CIRCULAR.

ALPHABET now contains 'JABCDEFGHI'. Both additions can also be combined.

Effect

Shifts the field c to the left. Since this is the default, you can omit this addition.

Additions:

Similar to variant 1.

Effect

Shifts the field c by n positions to the left and inserts blanks on the right.

Example

DATA ALPHABET(10) VALUE 'ABCDEFGHIJ', 
	 FIVE TYPE I  VALUE 5. 
SHIFT ALPHABET BY FIVE PLACES.

ALPHABET now contains 'FGHIJ '.

Note

If n = 0 or has a negative value, c remains unchanged.
If n is greater than the field length of c, c is padded with blanks.

Additions:

Similar to variant 1.

Effect

Searches c for the character string in c1 (starting on the left!). If it finds a match, it shifts the contents of c to the left until the character string concerned appears on the left. If no match is found, c remains unchanged.

SY-SUBRC = 4:

c1 was not found in c; c remains unchanged.

Example

DATA ALPHABET(10) VALUE 'ABCDEFGHIJ', 
	 THREE(3)	 VALUE	'DEF', 
	 FOUR(4)	VALUE	'DEF '. 
SHIFT ALPHABET UP TO FOUR.

SY-SUBRC is now set to 4 and the field ALPHABET remains unchanged.

SHIFT ALPHABET UP TO THREE CIRCULAR.

SY-SUBRC is now set to 0 and the field ALPHABET contains 'DEFGHIJABC'.

Note

The operation searches c for the full length of the string in c1, together with any existing blanks.

Effect

Shifts the field c to the left or right so that it begins or ends with a character which occurs in c1 and pads it with blanks accordingly.
If c does not begin or end with a character from c1, c remains unchanged.

Example

DATA: ALPHABET(15) VALUE '	 ABCDEFGHIJ', 
	M1(4)		VALUE 'ABCD', 
	M2(6)		VALUE 'BJJCA '. 
SHIFT ALPHABET LEFT DELETING LEADING M1.

The field ALPHABET is unchanged.

SHIFT ALPHABET LEFT DELETING LEADING SPACE.

The field ALPHABET now contains 'ABCDEFGHIJ '.

SHIFT ALPHABET RIGHT DELETING TRAILING M2.

The field ALPHABET now contains ' ABCDEFGHI'.

Avoid using the SHIFT command in WHILE loops for performance reasons.
Shifting a field one position to the right or left requires approx. 5 msn (standardized microseconds), while cyclical shifting requires approx. 7 msn. The variant ... LEFT DELETING LEADING ... needs about 3,5 msn, the variant ...RIGHT DELETING TRAILING ... about 4,5 msn.

Related

CONCATENATE, SEARCH, SPLIT