Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert char to packed number (type p)

Former Member
0 Kudos

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!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

4 REPLIES 4

Former Member
0 Kudos

remove comma then try

former_member585060
Active Contributor
0 Kudos

Remove the coma in the value and pass, as coma is given by system itself according to user settings

Data :

char(10) type c value '1200.12',

pack type p decimals 2,

int type i.

pack = char.

int = char.

Write 😕 pack,

int.

Former Member
0 Kudos

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

0 Kudos

Thank you Swastik Bharati,

I gave points to all of you!

Thanks again!