Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125
Beginner

How to remove the leading zeros from the output of program in SAP ABAP ?

Common Methods to Remove Leading Zeros in ABAP

WRITE statement with NO-ZERO

When outputting with WRITE, you can suppress leading zeros like this:

code:

DATA: lv_num TYPE n LENGTH 10 VALUE ‘0000123456’.

WRITE lv_num NO-ZERO. ” Output: 123456

SHIFT statement

You can shift the contents to the left to remove zeros:

code:

DATA: lv_num TYPE n LENGTH 10 VALUE ‘0000123456’.

SHIFT lv_num LEFT DELETING LEADING ‘0’.
WRITE lv_num. ” Output: 123456

CONDENSE with NO-GAPS

Works if the field is CHAR/NUMC:

DATA: lv_char TYPE char10 VALUE ‘0000123456’.

CONDENSE lv_char NO-GAPS. ” removes spaces
SHIFT lv_char LEFT DELETING LEADING ‘0’.
WRITE lv_char. ” Output: 123456

 

Conversion Exit (for SAP standard fields)

Some SAP fields (like Material Number MATNR) have conversion exits to display without leading zeros.

 

DATA: lv_matnr TYPE matnr VALUE ‘000000000000123456’.

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_OUTPUT’
EXPORTING
input = lv_matnr
IMPORTING
output = lv_matnr.

WRITE lv_matnr. ” Output: 123456

 

 

Best practice:

  • Use CONVERSION_EXIT_ALPHA_OUTPUT if dealing with SAP database fields like MATNR, KUNNR, LIFNR.

  • Use SHIFT ... DELETING LEADING '0' or WRITE ... NO-ZERO for simple variables.

 

Related Questions

Leave an answer

Leave an answer