03-30-2009 9:55 AM
Hi All,
I have a 10 character field whose valus is suppose 'A00987'.
How to add zeros at the starting of this field?
The output value for the above case should be 0000A00987.
I have tried using the FM 'CONVERSION_EXIT_ALPHA_INPUT'.
But it is returning the inputted value without appending zeros..
Any pointers would be of great help.
Thanks & Regards
Gowthami
Edited by: gowthami karunya on Mar 30, 2009 10:55 AM
03-30-2009 9:57 AM
Declare the data type of the length you required and use the Below FM.
If it is still not working Find the lenght of the field Using STRLEN and concatenate the missing vallues with zeros.
03-30-2009 10:00 AM
Hi Phanindra,
Thanks for ur prompt reply.
But finding the length of the string and appending the zeros for remaining digits would be complex for my requirement. Using the FM 'CONVERSION_EXIT_ALPHA_INPUT' is not working fine.
Regards
Gowthalmi
03-30-2009 10:01 AM
Hi,
FM 'CONVERSION_EXIT_ALPHA_INPUT' gives based on the data type declared for the field.
Eg: data : matnr TYPE matnr value '123456'.
after calling the FM the value become 000000000000123456. since MATNR is of type CHAR with 18 length...since the value of matnr here is of 6 char length, the FM will add the 12 preceding 0's..
OR
if you dont know what type of field to be declared, just declare the field type as N with required length..then system automatically adds the preceeding 0's with equal length.
eg: data : v1(10) TYPE n value '123456'.
write : v2.
output : 0000123456.
Hope its clear!!
Regards,
Pavan
03-30-2009 10:03 AM
Hi Pavan,
Thanks for ur reply.
This FM works fine if the value has only numeric values.
Please try with the example value I have given.
The field declared is of char10.
Regards
Gowthami
03-30-2009 10:23 AM
Hi,
do like below
DATA : v1(10) VALUE '100987',
v2 type i.
v2 = strlen( v1 ).
v2 = 10 - v2.
SHIFT v1 right by v2 places." deleting leading space.
do v2 times.
replace space with '0' into v1.
enddo.
OR
overlay v1 with '0000000000'.
WRITE : v1.
its working fine...i have tested it..
Regards,
Pavan
Edited by: vishnu Pavan on Mar 30, 2009 11:26 AM
03-30-2009 10:04 AM
Hi,,
See in FM docum.
If the input is not purely numeric, it is inserted in the display field from left to right and all extra spaces are filled with blanks.
so it does like this.
03-30-2009 10:04 AM
data: w_char(10) type c value 'A00987',
w_int type i.
w_int = strlen( w_char).
w_int = 10 - w_int.
shift w_char right by w_int places.
overlay w_char '0000000000' into w_char. " Blank places will be filled by zeros in front
03-30-2009 10:18 AM
03-30-2009 10:05 AM
The character 'A' is preventing the function to properly add leading zeroes.
Try:
SHIFT <your_variable> RIGHT DELETING TRAILING SPACE.
TRANSLATE <your_variable> USING ' 0'.
03-30-2009 10:06 AM
hi,
use CONVERSION_EXIT_ALPHA_INPUT -
It is used to add the Zero at the begining of the value. CONVERSION_EXIT_ALPHA_OUTPUT --- It is used to Remove Zero from the Begining of the value.
03-30-2009 10:11 AM
>
> hi,
> use CONVERSION_EXIT_ALPHA_INPUT -
It is used to add the Zero at the begining of the value. CONVERSION_EXIT_ALPHA_OUTPUT --- It is used to Remove Zero from the Begining of the value.
Unless i'm imagining things, but the original poster already stated he used that function and it didn't work.
03-30-2009 10:22 AM
HI
TRY THIS CODE..
LOOP AT <FIELD NAME>.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = FIELD NAME-LOW
IMPORTING
OUTPUT = FIELD NAME-LOW.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = FIELD NAME-HIGH
IMPORTING
OUTPUT = FIELD NAME-HIGH.
MODIFY ADVCNO INDEX SY-TABIX TRANSPORTING LOW HIGH .
ENDLOOP.
THANKS
ABHI