Skip to Content
author's profile photo Former Member
Former Member

converting string value to numeric

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 07, 2008 at 07:33 PM

    Hi,

    Condense the character string and assign the value to a variable declared as a numeric or floating value.

    Rgds,

    Subramanian

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 07, 2008 at 07: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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 07, 2008 at 07: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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 07, 2008 at 07: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 07, 2008 at 07: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'

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.