Hello friends,
I want to add leading zeros for a field.
the field is a character string.
for example ,
data: A(5) type c.
now when A = 'ab' (non-numeric value)
i want this to be converted in '000ab'
so, is there any standard Function module or any other way for doing this conversion ?
I tried the FM 'CONVERSION_EXIT_ALPHA_INPUT' but this FM does not work for non-numeric inputs..
Thanks.
Hi,
The packed field is transported right-justified to the character field, if required with a
decimal point. The first position is reserved for the sign. Leading zeros appear as
blanks. If the target field is too short, the sign is omitted for positive numbers. If this is still not sufficient, the field is truncated on the left. ABAP indicates the truncation with an asterisk (*). If you want the leading zeros to appear in the character field, use UNPACK instead of MOVE.
UNPACK
Converts variables from type P to type C.
Syntax
UNPACK <f> TO <g>.
Unpacks the packed field <f> and places it in the string <g> with leading zeros. The opposite of PACK.
Regards,
Bhaskar
i think you cant add zero for non numeric value by std fn modules.
do like this.
data : a(5) value 'ab',
len type i.
compute len = strlen( text ).
len = 5 - len."since you have declared a(5)
do len times.
concatenate '0' a into a.
enddo.
regards
shiba dutta
Hello,
Check this code. It's working for me.
DATA: char TYPE char5. DATA: strglen TYPE i. DATA: len TYPE i. char = 'AB'. len = STRLEN( char ). strglen = 5 - len. DO strglen TIMES. CONCATENATE '0' char INTO char. ENDDO. WRITE:/ char. Regards, Deepu.K
Add a comment