‎2006 Jul 25 3:09 PM
HI group,
I am having one field called v_ref with length of 18 .
This filed sometimes coming with length 10 and others
spaces in the right handside.Some times with length 13
and other 5 spaces.I need to populated this field in to
some other fileld without any spaces,could you please
suggest.
‎2006 Jul 25 3:11 PM
You want to remove the spaces on the right?
shift v_ref right deleting trailing space.
‎2006 Jul 25 3:12 PM
‎2006 Jul 25 3:13 PM
Hello,
shift v_ref right deleting trailing space.
shift v_ref left deleting leading space.
move v_ref to l_ref.
regards,
Naimesh
‎2006 Jul 25 3:14 PM
HI,
SHIFT V_VAL LEFT DELETING LEADING SPACE.
hope this helps,
do reward if it helps,
priya.
‎2006 Jul 25 3:15 PM
Hi,
You can shift the contents of a field using the following variants of the SHIFT statement. SHIFT moves field contents character by character.
Shifting a String by a Given Number of Positions
SHIFT <c> [BY <n> PLACES] [<mode>].
This statement shifts the field <c> by <n> positions. If you omit BY <n> PLACES, <n> is interpreted as one. If <n> is 0 or negative, <c> remains unchanged. If <n> exceeds the length of <c>, <c> is filled out with blanks. <n> can be variable.
With the different <mode> options, you can shift the field <c> in the following ways:
<mode> is LEFT:
Shifts the field contents <n> places to the left and adds <n> blanks at the right-hand end of the field (default).
<mode> is RIGHT:
Shift <n> positions to the right and adds <n> blanks at the left-hand end of the field.
<mode> is CIRCULAR:
Shift <n> positions to the left so that <n> characters on the left appear on the right.
DATA: T(10) VALUE 'abcdefghij',
STRING LIKE T.
STRING = T.
WRITE STRING.
SHIFT STRING.
WRITE / STRING.
STRING = T.
SHIFT STRING BY 3 PLACES LEFT.
WRITE / STRING.
STRING = T.
SHIFT STRING BY 3 PLACES RIGHT.
WRITE / STRING.
STRING = T.
SHIFT STRING BY 3 PLACES CIRCULAR.
WRITE / STRING.
Output:
abcdefghij
bcdefghij
defghij
abcdefg
defghijabc
Shifting a Structure up to a Given String
SHIFT <c> UP TO <str> <mode>.
This statement searches the field contents of <c> until it finds the string <str> and shifts the field <c> up to the edge of the field. The <mode> options are the same as described above. <str> can be a variable.
If <str> is not found in <c>, SY-SUBRC is set to 4 and <c> is not shifted. Otherwise, SY-SUBRC is set to 0.
DATA: T(10) VALUE 'abcdefghij',
STRING LIKE T,
STR(2) VALUE 'ef'.
STRING = T.
WRITE STRING.
SHIFT STRING UP TO STR.
WRITE / STRING.
STRING = T.
SHIFT STRING UP TO STR LEFT.
WRITE / STRING.
STRING = T.
SHIFT STRING UP TO STR RIGHT.
WRITE / STRING.
STRING = T.
SHIFT STRING UP TO STR CIRCULAR.
WRITE / STRING.
Output:
abcdefghij
efghij
efghij
abcdef
efghijabcd
Shifting a Structure According to the First or Last Character
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.
DATA: T(14) VALUE ' abcdefghij',
STRING LIKE T,
STR(6) VALUE 'ghijkl'.
STRING = T.
WRITE STRING.
SHIFT STRING LEFT DELETING LEADING SPACE.
WRITE / STRING.
STRING = T.
SHIFT STRING RIGHT DELETING TRAILING STR.
WRITE / STRING.
Output:
abcdefghij
abcdefghij
abcdef
Regards,
Laxmi.
‎2006 Jul 25 3:20 PM
You have opened two threads for the same question. Please close one and continue with the other.
You can check the string length and move to the appropriate variable.
report zrich_0001.
data: str1 type string.
data: var1(18) type c.
data: var2(13) type c.
data: len type i.
str1 = 'ABCDEFGHIJK'.
len = strlen( str1 ).
if len > 13.
var1 = str1.
else.
var2 = str1.
endif.
write:/ var1.
write:/ var2.
Regards,
Rich Heilman