Leading zeros – adding and removing characters

Welcome to the Brandeis Training website!

You are not logged in or enrolled in this course, so you will not be able to see all of the content. On the left side you will find the table of contents. But there are some free trial lessons there, which you can recognize by the same yellow background and the lock symbol.

The following SQL functions can be used to pad the start and end of strings with a character template up to a specified length be filled. Most of the time this is either “0” or space.

  • LPAD(<Characterstring>,<length>[,<pattern>])
  • RPAD(<Characterstring>,<length>[,<pattern>])

With the function ABAP_ALPHANUM (<Characterstring>,<Length>) numeric Strings with leading zeros up to a specified length can be filled. As soon as there is a non-numeric character in the string, this function does nothing.

The function TO_ALPHANUM is only available in HANA 2.0 and is not available in the SAP HANA Cloud. Please therefore always use ABAP_ALPHANUM .

And vice versa, you can remove a lot of characters from the beginning or end of a character string with the following functions:

  • LTRIM(<character string>[,<character set>])
  • RTRIM(<character string>[,<character set>])
  • TRIM( [<option>] <character set> FROM <character string>)

Pages 181-182 in the book