Posts

Showing posts with the label leading

SAP ABAP: Adding leading zero to char or string.

Here are the three ways to add leading zeros to a char or string. 1). Using numeric and character field with the same length. DATA: lv_Belnr(10) TYPE C VALUE '48',             lv_Num(10)   TYPE N. lv_Num =  lv_Belnr. ADD 1 TO  lv_Num. lv_Belnr  = lv_Num . WRITE  lv_Belnr. 2). Using FM CONVERSION_EXIT_ALPHA_INPUT. DATA: lv_Belnr(10) TYPE C VALUE '48'.   ADD 1 TO lv_Belnr.   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'            EXPORTING                    INPUT  = lv_Belnr                      IMPORTING                    OUTPUT = lv_Belnr.  3). Using UNPACK.  DATA: lv_Belnr(10) TYPE C VALUE '48'. ADD 1 TO lv_Belnr. UNPACK lv_Belnr TO lv_Belnr. That's all. Mabuhay!