Skip to Content

While working recently with the SHIFT LEFT DELETING LEADING statement, I sometimes received what I felt were incorrect results. I decided to carry out some additional research into the statement and found that my actual understanding of what the statement was supposed to do and how it works was incorrect.

 

Let me show you my findings – what I thought at the beginnng and what I now know!

 

I began with reviewing the online documentation for the SHIFT statement:

http://help.sap.com/saphelp_nw73/helpdata/en/9f/db999535c111d1829f0000e829fbfe/frameset.htm

 

I then wrote a simple ABAP Program to test the statement:

Program Code 

I ran the program and this was the generated output:

Output 

All appeared fine – however, when I looked a little closer, I found that the output from the last test on g_var6 – wasn’t what I had expected.

g_var6

 I thought I would be returned: ZMVPZSBU… but the initial Z character was missing! Where had it disappeared to?

 

In search of the missing Z!

I showed my coding and output to a colleague, he was also unsure why the output seemed incorrect. So, I went back to the documentation and reviewed it again. Then it hit me! I had been trying to see something that wasn’t there! Here is what I found:

  1. The characters listed after the LEADING statement are treated as a pattern. These are not considered as a sequence of characters which should match, i.e. they are not a substring
  2. The content of the field is moved as long as the first or last character is contained in the pattern

 

So for g_var6:

  • The SHIFT statement was not comparing the first n characters with the given substring ‘0106ZUSA’
  • Instead it was checking each first character of g_var6 to see if it was contained in the pattern ‘0106ZUSA’. If yes, then it was removed and the rest shifted
  • As the second Z of 0106ZUSAZMVPZSBU is also contained in ‘0106ZUSA’, it was also removed. The next first character is M, which is not contained in the pattern provided, hence the SHIFT is finished at this position

 

Findings:

When I started working with the SHIFT statement, I was actually treating it like a FIND statement. However, this was incorrect!

  • If you want to work with substrings   –   use the FIND statement!
  • If you want to work with patterns      –   use the SHIFT statement!
To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

    1. Clemens Li
      Yes, REGEX are fine. But if you use them in mass processing you can save up to 80 % time if you use find, shift, CS, CA and the like.

      I was really shocked when I did a runtime analysis in a complex oo application where I filled an ALV with some ten thousand cells and made massive use of regex for dynamic assignments and calculations.

      regex are powerful and effective – but slow.

      Regards, Clemens

      (0) 
  1. Michelle Crapo
    Now I know.  I never really have had that problem.  But yikes!  If I did I would spend way too much time trying to figure out why.  It always seems that way.  A long time to figure out, and a quick fix.

    I’m with Blag – I have not used shift deleting statement.

    I HAVE however used “find”. 

    Great job – good detective work!

    Michelle

    (0) 

Leave a Reply