ERP; Add Leading Zero ABAP

Add Leading Zero ABAP

Add Leading Zero ABAP is a common requirement in the daily task of ABAP developper.
How to handle leading and padding zeros for SAP Data and variables in SAP using ABAP with common case of SAP Material Number

Check also Conversion ABAP: between Binary, String, XString and Table

Add Leading Zero ABAP

In order to add Leading zeros in ABAP, in general use the standard function CONVERSION_EXIT_ALPHA_INPUT.
This function will add the leading zeros until filling the length of the output. It will check the Data Type and domain in order to calculate how many zeros will be added.

Check also   How to find BTE Event in SAP with SAP BTE Liste in SAP ECC

SAP Material Add Leading Zeros ABAP

For Material, I recommend using an other function: CONVERSION_EXIT_MATN1_INPUT
In one project I have been working on, in some systems, SAP Material Numbers are stored in SAP Material Master data with Leading zeros and for some others systems, the SAP Material Number is handled without leading zeros in SAP.

In opposite, to Remove the leading Zeros in SAP Material Number use rather CONVERSION_EXIT_MATN1_OUTPUT.

These both Conversion routines are set in MATNR domain.

Check also the SAP Material Master Tables.

Add Leading Zeros in ABAP

There are some other ways to add the leading zeros in ABAP Variable.

Check also   Credit Limit for Customer in SAP SD

ABAP Unpack Statement

ABAP Statement Unpack is the easiest way to deal with zeros padding in ABAP. It can be a serious alternative for the conversion_exit_alpha_input.

ABAP Default Casting Or Write

ABAP can handle formatting SAP variables when copying variables. It will add the leading zeros for example if you copy a string variable containing a number to an integer. The Integer variable will have the needed zeros.

Other Zeros Padding Alternative in ABAP

The ABAP WRITE statement has multiple functionnalities within the formatting tools.

  • To Add leading zeros: WRITE lv_variable USING EDIT MASK ‘==ALPHA’.
  • To Remove Leading zeros: WRITE lv_variable no NO-ZERO.
Check also   SAP Transport Standard Text (SO10)

 

Leave a Reply

Your email address will not be published. Required fields are marked *