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

convert text to amount

hi,

given this simple problem:

data: text(10), amount type p decimals 2.
text = '20,000.00'.

how do i pass the value of 20,000.00 to the amount variable without incurring ABAP runtime errors, besides manually removing the "," delimiters for each thousand?

(actually the amount field is type currency, but i know currency and packed are the same in nature)

ryan.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Feb 22, 2005 at 08:57 AM

    Hello Ryan,

    here's an example to catch/change the value:

    REPORT z6.

    DATA digit(11) VALUE ' 0123456789'.

    PARAMETERS: text(16) DEFAULT '20,000.00'.

    DATA c_text(16).

    DATA amount TYPE p DECIMALS 2.

    DATA n TYPE n.

    DATA i TYPE i.

    c_text = text.

    CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.

    MOVE c_text TO amount.

    ENDCATCH.

    IF sy-subrc EQ 1.

    CALL FUNCTION 'PREPARE_STRING'

    EXPORTING

    i_valid_chars = digit

    i_xvalid_check = 'X'

    i_xchar_repl = 'X'

    i_xtoupper = 'X'

    CHANGING

    c_string = c_text.

    CONDENSE c_text NO-GAPS.

    DESCRIBE FIELD amount DECIMALS n.

    i = 10 ** n.

    amount = c_text / i.

    ENDIF.

    WRITE:/ text, 50 amount.

    regards Andreas

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 22, 2005 at 07:33 AM

    Hello,

    - If you don't want a short time error, use the command catch.

    Ex :

    catch system-exceptions conversion_errors = 1.

    move ... to text.

    endcatch.

    if sy-subrc eq 1.

    ....

    endif.

    - I write always my own form to convert text amount to value amount with replace '.' by ',' ...

    Regards

    Frédéric

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 22, 2005 at 10:24 PM

    hi,

    you can use as well funtion module <b>HRCM_STRING_TO_AMOUNT_CONVERT</b>.

    Best regards.

    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.