Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

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:

 

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!
4 Comments