cancel
Showing results for 
Search instead for 
Did you mean: 

Convertion of a string to CURR

Shabarish_Nair
Active Contributor
0 Kudos

Hi all,

I have a field of char length 11.

Now i have to convert this string and post it to a

table where the field is declared as type CURR (no of char = 9 , decimal places = 2 , output length = 12).

How can this be done?

Regards,

Shabarish

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

write currfield to charfield.

Rob

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Try this.....





data: currency_field type p decimals 2.
data: string(11) type c.


string  = '12345.67'.

currency_field = string.

check sy-subrc  = 0.

Regards,

Rich Heilman

andreas_mann3
Active Contributor
0 Kudos

hi,

or validate your char with "catch":

example:

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

Former Member
0 Kudos

Please ignore my earlier post. I was doing it backwards.

(If it weren't for backwards, I'd never get anything done.)

Rob

Shabarish_Nair
Active Contributor
0 Kudos

hi all ,

Thank you for your posts. Actually the problem was in the length of the data element that had been prevoiusly

defined. Now that that has been rectified the problem has been solved.

Thanks all once again.

Regards,

Shabarish