Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to convert char to packed number (type p)

Hello everyone,

I have a problem with data convert from char to packed number.

Ex code:

data: str(10) value '1,200.12'.

data: amount(13) type p decimals 2.

amount = str.

I got an runtime error: "Unable to interpret "1,200.12 " as a number"

Could you please help me to convert char to number?

Many thanks!

Tags:
Former Member
Former Member replied
data: str(10) value '1,200.12'.
data: amount(13) type p decimals 2.
REPLACE ALL OCCURRENCES OF ',' IN str WITH ''.

Else to make it better

  SELECT SINGLE dcpfm         "Decimal notaion
  FROM   usr01                "User master record (runtime data)
  INTO   l_user_decimal
  WHERE  bname EQ sy-uname.

  CASE l_user_decimal.
    WHEN ' '.  " Decimal point is comma: N.NNN,NN
      TRANSLATE str USING '. '.
      TRANSLATE str USING ',.'.
    WHEN 'X'.  " Decimal point is period: N,NNN.NN
      TRANSLATE str USING ', '.
    WHEN 'Y'.  " Decimal point is N NNN NNN,NN
      TRANSLATE str USING ',.'.
  ENDCASE.
  CONDENSE str NO-GAPS.
amount = str.

Edited by: Swastik Bharati on Sep 24, 2008 9:20 AM

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question