Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

shift satetment problem

Former Member
0 Kudos

hi

i am not understanding the output of he last one why the out put is 'abcdefghi'

SHIFT ALPHABET RIGHT DELETING TRAILING M2.

t

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'

thanks

2 REPLIES 2

Former Member
0 Kudos

the descriptoin in help for shift is as follows...

SHIFT <c> LEFT DELETING LEADING <str>.

SHIFT <c> RIGHT DELETING TRAILING <str>.

This statement shifts the field <c> to the left or to the right, provided the first character on the left or the last character on the right occur in <str>. The right or left of the field is then padded with blanks. <str> can be a variable.

now in your example the 1st shift statement does nothing because the first character is a space so it does not delete anything. 2nd shift deletes all the spaces in front...

the third shift statement looks at the last character in ALPHABET and tries to match it with a character in M2. Only 'J' is available and once it is removed form right...there are no more characters from ALPAHBET to be removed from the right with chars in M2.

Thanks,

Renjith

Former Member
0 Kudos

Hi sanjeev,

1. I tried the same at my end.

I was also confused, but now

i understood what is happening actually.

2. Its not an error.

Its the way how the ABAP syntax behaves.

3. In your same program (taken from F1 help)

i have added EXTENSIONS

which will make clear

-how this behaves

4. If we take the literal meaning of the words,

RIGHT = moves the charcters right

DELETING = Deletes something

TRAILING = deletes something from right only

mw = delete M2 if it is in right only (not in left)

5. Try this code to get a taste of it( just copy paste)

6.

REPORT abc.

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.

break-point.

*the field alphabet now contains 'ABCDEFGHIJ ' .

SHIFT alphabet RIGHT DELETING TRAILING m2

.

*the field alphabet now contains 'ABCDEFGHI'

*----


EXETENSIONS

alphabet = 'ABCDEFGHIJ'.

m2 = 'IJ'.

SHIFT alphabet RIGHT DELETING TRAILING m2.

*alphabet is 'ABCDEFGH' 'IJ' Deleted

alphabet = 'ABCDEFGHIJ'.

m2 = 'HIJ'.

SHIFT alphabet RIGHT DELETING TRAILING m2.

*alphabet is 'ABCDEFG' 'HIJ' Deleted

alphabet = 'ABCDEFGHIJ'.

m2 = 'GHIJ'.

SHIFT alphabet RIGHT DELETING TRAILING m2.

*alphabet is 'ABCDEF' 'GHIJ' Deleted

break-point.

regards,

amit m.