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: 

abap -SHIFT

Former Member
0 Kudos

hi folks,

I have small confusion with the use of SHIFT.

when do you use 'LEFT DELETING LEADING' and 'RIGHT DELETING TRAILING'

because I have a character variable

z1 = Operation# and I need to get rid of the '#'. I have declared z1 as char type.

I need to get it clarified once for all.

Thanks

Vinu.

23 REPLIES 23

Former Member
0 Kudos

Hi Vinu,

The best explanation is given in F1 help with example..

Shifts the contents of c to the left or right for as long as the string begins or ends with a character contained in c1.

If c does not begin or end with a character from c1, it 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 remains unchanged.

SHIFT ALPHABET LEFT DELETING LEADING SPACE.

The field ALPHABET now has the following contents:

'ABCDEFGHIJ '.

SHIFT ALPHABET RIGHT DELETING TRAILING M2.

ALPHABET now has the following contents:

' ABCDEFGHI'.

0 Kudos

Hi Vinu,

When you use SHIFT (LEFT/RIFGT) pl note that the left or right of the field is then padded with blanks. If you do not want the blanks, you are better off moving the field contents using offsets.

Regards,

Suresh Datti

Former Member
0 Kudos

myvariable = 'xxx123'.
SHIFT myvariable LEFT DELETING LEADING 'x'.
WRITE:/ myvariable.

The output in this case will be '123'.


myvariable = '123xxx'.
SHIFT myvariable RIGHT DELETING TRAILING 'x'.
WRITE:/ myvariable.

The output in this case will be

'   123'

.

0 Kudos

Is that really a '#' or is it some special character like tab that got uploaded from a file? When you upload a file that has special characters, you will see '#' in the contents, but when you try to remove it using any of the string operations you will not be able to do it.

0 Kudos

Thanks but the syntax is not working in the program when I am trying to remove the trailing '#' sign.

ZAUS02 = itab_in-aus02 ( the value is Operation#)

and aus02 is CHAR(10) declared in the itab.

SHIFT ZAUS02 RIGHT DELETING TRAILING '#'.

After that I have to compare the value in ZAUS02 USING if CONDITION.

IF ZAUS02 = 'Operation'

.

..

I hope you got the point here.

Thanks

Vinu.

0 Kudos

You would have to shift it back to the left removing leading spaces. Try using replace instead.

Rob

0 Kudos

Infact I tried that but it did not work, so I came to this, It's so simple but what am I missing here?

Vinu

0 Kudos

Did you se the code I posted? You can just cut and paste it to see if it does what you want.

Rob

0 Kudos

Srinivas, you are right, it comes from the external file in the .csv format, hecne I am not able to remove it.

But in a similar case in a different program I was able to remove the leading '##' signs using 'left DELETING leading' syntax for the value getting from the flat file.

why not here?

Thanks

Vinu

0 Kudos

why not change the if to:

IF ZAUS02(9) = 'Operation'.

0 Kudos

Then try:


DATA : code TYPE x VALUE '09'.
REPLACE code WITH '' INTO z1.

Rob

0 Kudos

Folks, I got the issue.

Please help with the logic.

For the field 'ZAUS02' i AM READING THE VALUE from flat file the length of the field is CHAR10.

when the value is less than 10 it reads the value as with a trailing '#' like in 'Operation#'

Only in such case I need to get rid of the '#' sign and when the value of the field is equal to the size 10 no '#' sign is displayed.

then i go it works fine to check the IF condition..

Foe example:

ZAUS02 = Functional

it is fine

if ZAUS02 = 'Functional'

.

.

elseif ZAUS02 = 'Operation' (for this ZAUS02 needs to get rid of the # sign)

.

.

This is what I am trying to achieve here.

Thanks

Vinu

.

that's fine

0 Kudos

Assuming the # is really a tab, the (second) code I posted should work. It did when i tested it. If it's not a tab, you'll have to find out the hex value of it.

Rob

0 Kudos

I am sorry Rob, I did not understand the 'code' can you elaborate on it ?

Thanks.

Vinu

0 Kudos

The variable CODE is a one byte hex field with the value X'09' (which I believe is the value of a tab). If you replace any instances of X'09' with a blank or null, it should get rid of it.

Do a F1 on DATA->Simple field definition->Addition 1 (type). It's discussed there.

Rob

Does this help:


DATA : tab TYPE x VALUE '09'.
REPLACE tab WITH '' INTO z1.

Message was edited by: Rob Burbank

0 Kudos

Sorry Rob, both did not work, I find it really strange, because for an earlier program I used the 'SHIFT' command to eliminate the leading '#' for the values and was able to upload.

That was a Numeric char variable and this is a char variable.

Thanks foryour help. Let me know if You have any leads to it, I shall continue working on it.

I shall ward the points and keep the thread open.

Vinu.

0 Kudos

SHIFT or REPLACE should work equally well.

Sorry it didn't work out, but remember others helped as well. Srinivas was the one who figured out your problem wasn't with the character '#'.

If you want, paste the portion of your code that you're having trouble with. I can look at it later.

Rob

Message was edited by: Rob Burbank

0 Kudos

how about the Contains string variant:

IF ZAUS02 CS 'Operation'.

0 Kudos

Last try - declare a variable:


  DATA : var.

make sure you have 'Operation#' in z1, then:


    MOVE z1+9(1) TO var.    "Make sure it's the last char
    REPLACE var WITH '' INTO z1.

Rob

0 Kudos

Hi Vinu,

did you try this ..

DATA: z1(20) VALUE 'Operation#'.
  replace all occurrances of  CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB In Z1 with space .

regards

satesh

ferry_lianto
Active Contributor
0 Kudos

Hi Vinu,

Please take a look at this link for sample code.

http://www.kabai.com/abaps/z82.htm

Hope this will help.

Regards,

Ferry Lianto

Former Member
0 Kudos

Hi Vinu,

DATA: TEXT(10) VALUE 'Operation#'.

SHIFT TEXT RIGHT DELETING TRAILING '#'.

write:/ TEXT.

Former Member
0 Kudos

Why not just use REPLACE:


DATA: z1(20) VALUE 'Operation#'.

REPLACE '#' WITH '' INTO z1.

Rob