Delete leading zeros ABAP in SAP important and easy task. Five examples how to remove leading 0 in ABAP program. There are more then one way how we can delete zeros in ABAP, but all have differences the choice is yours.
Remove leading zeros ABAP with CONVERSION_EXIT_ALPHA_OUTPUT
For deleting leading zeros ABAP we can use function module CONVERSION_EXIT_ALPHA_OUTPUT. Parameters function module CONVERSION_EXIT_ALPHA_OUTPUT ABAP:

Example using function module CONVERSION_EXIT_ALPHA_OUTPUT
Using CONVERSION_EXIT_ALPHA_OUTPUT in ABAP program for remove leading zeros in partner number SAP:
1 2 3 4 5 6 7 |
lv_partner = '0000000001'. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = lv_partner IMPORTING output = lv_partner. " result lv_partner = '1'. |
ADDITION: If you send to function module not number for example: ‘HR00000001’ (in SAP CRM in this field also there are and numbers with ‘HR’, for example). As result function module back to you the same value without changing and without dumps.
Delete leading zeros ABAP with New ABAP syntax
Remove leading zeros (0) in ABAP with new ABAP syntax. We have good opportunities for using new syntax ABAP constructions in deleting zeros task. Using ALPHA ABAP = OUT more short and useful then FM CONVERSION_EXIT_ALPHA_OUTPUT.
1 2 3 |
DATA(lv_partner) = CONV bu_partner( '0000000001' ). lv_partner = |{ lv_partner ALPHA = OUT }|. " result lv_partner = '1'. |
ADDITION: If you send to function module not number for example: ‘HR00000003’ (in SAP CRM in this field also there are and numbers with ‘HR’, for example). As result function module back to you the same value without changing and without dumps.
Remove leading zeros in ABAP with SHIFT
This useful construction you can use in new ABAP and in Old ABAP syntax also. Construction SHIFT LEFT DELETING LEADING ‘0’ is short and good option for deleting leasing zeros in ABAP.
1 2 3 |
DATA(lv_partner) = CONV bu_partner( '0000000001' ). SHIFT lv_partner LEFT DELETING LEADING '0'. " result lv_partner = '1'. |
ADDITION: If you send to function module not number for example: ‘HR00000005’ as result function module back to you the same value without changing and without dumps.
Delete leading zeros in ABAP with PACK
Using PACK ABAP is not advisable in my opinion, but you need to know how this construction work for reading ABAP code.
1 2 3 |
DATA(lv_partner) = CONV bu_partner( '0000000001' ). PACK lv_partner TO lv_partner. "result lv_partner = 1 |
ADDITION: If you try to send not number ( ‘HR00000004’ for example ) to PACK as result you get dump with ‘CX_SY_CONVERSION_NO_NUMBER’. Construction PACK only change 0 to empty in lv_partner, not the same like in others:

Remove leading 0 in ABAP with WRITE
This is an unnecessary and unused option to delete. I just added it because it exists.
1 2 3 |
DATA(lv_partner) = CONV bu_partner( '0000000001' ). WRITE / lv_partner. "result = 1 |
How add leading zeros in ABAP you can find on this page: