2005 May 16 4:09 PM
hi folks,
I have the character variable of size 9, if I get the value of the variable less than 9, I need to add leading zeros to it accordingly before displaying the numeric value stored in it. I tried to use the 'SHIFT' command for that it did not work out.
here is the code..
data: len type I,
amount type C,
addspace len type I.
len = strlen( amount ).
write: ' the length of the string',len.
if ( len < 9 ).
addspace = 9 - len.
write: addspace.
SHIFT amount BY addspace Places LEFT.
Thanks in advance.
hi folks,
I have the character variable of size 9, if I get the value of the variable less than 9, I need to add leading zeros to it accordingly before displaying the numeric value stored in it. I tried to use the 'SHIFT' command for that it did not work out.
here is the code..
data: len type I,
amount type C,
addspace len type I.
len = strlen( amount ).
write: ' the length of the string',len.
if ( len < 9 ).
addspace = 9 - len.
write: addspace.
SHIFT amount BY addspace Places LEFT.
Thanks in advance.
2005 May 16 4:23 PM
2005 May 16 4:26 PM
Hi Santhosh,
Have you tried using a NUMC variable?
It always has leading zeros.
Code would be:
data: amount(9) type c,
numc_amount(9) type n.
* If char field only contains numeric data
if amount co '0123456789 '. "Added a space in here!"
numc_amount = amount.
endif.
* If the numc amount is filled.
if not numc_amount is initial.
* Do something with it! (for example: WRITE)
write: / 'Number is: ' numc_amount.
endif. Hope that helps.
Brad
Message was edited by: Brad Williams
2005 May 16 5:15 PM
2005 May 16 4:27 PM
Hi Santhosh,
Use FM "CONVERSION_EXIT_MATN1_INPUT".
Pass the number to this FM . You will get zeroes prefixed to to it. Then take offset of output number.
example :
if you export g_num to FM and import l_num
then use. write l_num+9(9) to p_number.
in P_number you will get zero prefix as you want.
Regards,
Anand More.
2005 May 16 4:50 PM
Hi Santhosh,
All the suggestions here will work. Make sure that your number is on the right justified to your character field. Here is an example.
DATA: v_char09_left_justified(09) TYPE c,
v_char09_right_justified(09) TYPE c,
v_numc09(09) TYPE n.
START-OF-SELECTION.
*-- in case the value is left justified in the field
v_char09_left_justified = '9 '.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_char09_left_justified
IMPORTING
output = v_char09_left_justified.
WRITE:/ 'V_CHAR09_LEFT_JUSTIFIED from FM =', v_char09_left_justified.
v_numc09 = v_char09_left_justified.
WRITE:/ 'V_NUMC09 =', v_numc09.
*-- in case the value is right justified in the field
v_char09_right_justified = ' 9'.
SHIFT v_char09_right_justified LEFT DELETING LEADING space.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_char09_right_justified
IMPORTING
output = v_char09_right_justified.
WRITE:/ 'V_CHAR09_RIGHT_JUSTIFIED from FM =', v_char09_right_justified.
v_numc09 = v_char09_right_justified.
WRITE:/ 'V_NUMC09 =', v_numc09.