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.
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
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
hi,
you can use as well funtion module <b>HRCM_STRING_TO_AMOUNT_CONVERT</b>.
Best regards.
Add a comment