SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software SAP ABAP Programming and HANA Database Tutorials
Development resources, articles, tutorials, code samples and tools and downloads for ASP.Net, SQL Server, R Script, Windows, Windows Phone, AWS, SAP HANA and ABAP, like SAP UI5, Screen Personas, etc.

Install SAP Free

How to Remove Preceeding Zeros in ABAP Development

I have developed a simple ABAP report / ABAP program which displays the contents of an SAP table on screen and writes the total number of lines or total number of records in the related SAP table on the screen.

The output of the ABAP program where I write the lines number of the sample SAP table SAPLANE is as follows :

remove preceeding zeros in numeric variables in abap

As seen in the above screenshot, for a better result we have to remove the preceeding zeros using various methods in ABAP.

Sample ABAP Code for Removing Preceeding Zeros

Here is the source code of an ABAP program which requires to be corrected in order to display the lines count without preceeding zeros.


  gs_saplane TYPE saplane,
  gt_saplane TYPE TABLE OF saplane,
  gv_lin TYPE n LENGTH 5,
  gv_txt TYPE string.

SELECT * FROM saplane
  INTO TABLE gt_saplane.

DESCRIBE TABLE gt_saplane LINES gv_lin.

CONCATENATE 'Table SAPLANE has' gv_lin 'number of lines'
  INTO gv_txt SEPARATED BY space.

WRITE / gv_txt.


Remove Preceeding Zeros using SHIFT LEFT DELETING LEADING

Calling the SHIFT ... LEFT DELETING LEADING '0' is a nethod that can be implemented in ABAP codes in order to delete the zeros before the integer part of the variable.

And the solution is as simple as using the SHIFT ... LEFT DELETING LEADING '0' ABAP code before CONCATENATE command call.

* Remove preceeding zeros

Remove Preceeding Zeros by Calling CONVERSION_EXIT_ALPHA_OUTPUT funcion

To call the CONVERSION_EXIT_ALPHA_OUTPUT function is an other solution for removing preceeding zeros.
Here is how the function CONVERSION_EXIT_ALPHA_OUTPUT is called with parameters.

  input = gv_lin
  output = gv_lin.

SAP Resources

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table

Meetup Sunumu 1 meetup

Copyright © 2004 - 2020 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems