07-07-2008 8:31 PM
hi
how to convert string value or character variable (that actually has numeric or floating value) to its original numeric value or floating value.
is there any function module
07-07-2008 8:33 PM
Hi,
Condense the character string and assign the value to a variable declared as a numeric or floating value.
Rgds,
Subramanian
07-07-2008 8:37 PM
Check this code:
data val type i.
***********************************************************************
SELECTION SCREEN *
***********************************************************************
PARAMETERS: lines(5) TYPE c obligatory.
START-OF-SELECTION.
try.
val = lines.
catch cx_root.
write: 'Conversion not possible'.
endtry.
Same can be done for float as well.
Regards,
Joy.
07-07-2008 8:40 PM
Hello,
See the code bellow:
data:
lv_c type c length 10,
lv_p type p decimals 2.
lv_c = '123.456'.
CONDENSE lv_c NO-GAPS.
lv_p = lv_c.
Regards.
07-07-2008 8:43 PM
You can achieve this by moving the String contents to the Numberic variables. Make sure that you catch the runtime exception when you don't have numeric value in your String variable.
Like:
DATA: L_STRING TYPE STRING,
L_P TYPE P DECIMALS 2.
DATA: L_CONV TYPE REF TO CX_SY_CONVERSION_NO_NUMBER,
L_TEXT TYPE STRING.
L_STRING = '15.25'.
TRY.
L_P = L_STRING.
CATCH CX_SY_CONVERSION_NO_NUMBER INTO L_CONV.
L_TEXT = L_CONV->GET_TEXT( ).
WRITE: / L_TEXT.
ENDTRY.
WRITE: / L_STRING,
/ L_P.
L_STRING = 'abc'.
TRY.
L_P = L_STRING.
CATCH CX_SY_CONVERSION_NO_NUMBER INTO L_CONV.
L_TEXT = L_CONV->GET_TEXT( ).
WRITE: / L_TEXT.
ENDTRY.
WRITE: / L_STRING,
/ L_P.
Regards,
Naimesh Patel
07-07-2008 8:56 PM
juss declare a numeric variable...and move the value of character variable to this newly declared variable it will get converted... this is called 'type-casting'