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 pass amounts from Character field to a currency field?

Former Member
0 Kudos
2,091

Hi ,

I have a problem while im trying to do the following

data: l_amount bseg-wrbtr,

l_char(16).

l_char = '7.000,00'.

l_amount = l_char.

Im getting a short dump when i move amount from character(l)char) to a currency field(l_amount).

I have all my values in character field and i cant change my program now.

Is there a way where i can write or do something to take this value from character field to an amount field?

Do reply ASAP.

Thanks,

Anita

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
298

There are a couple ways of doing this. If you number format is always like X.XXX,XX then the following code will work. All you need to do is get rid of the thousands separator and make the decimal separator as '.'. This is the internal format of a PACK decimal field.




report zrich_0001 .


data: l_amount type bseg-wrbtr,
      l_char(16).

l_char = '7.000,00'.

translate l_char using '. '.
translate l_char using ',.'.
condense l_char no-gaps.

l_amount = l_char.

write:/ l_amount.

Regards,

Rich Heilman

11 REPLIES 11

Former Member
0 Kudos
298

hi,

We cant directly pass char field to currency field.

we should use PACK statement.

data: v_char(3) type c,

v_curr like ekbz-wrbtr.

PACK v_char to v_curr.

Regards,

Sailaja.

former_member223537
Active Contributor
0 Kudos
298

Hi,

Write l_from to l_to_curr currency <currency name>.

Best regards,

Prashant

Message was edited by: Prashant Patil

Former Member
0 Kudos
298

Hi,

Use this...

data: l_amount bseg-wrbtr,

l_char(16).

l_char = '7.000,00'.

PACK l_char to l_amount.

0 Kudos
298

this doesnt work.. Still getting dump.

can you also check this?

0 Kudos
298

Hi,

You can try this FM <b>HRCM_STRING_TO_AMOUNT_CONVERT</b>

pass the character (which hold the amount) and get the Amount into amount variable.Check it.

Regards

vijay

0 Kudos
298

Hi,

Have a look at this thread...

Regards

vijay

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
299

There are a couple ways of doing this. If you number format is always like X.XXX,XX then the following code will work. All you need to do is get rid of the thousands separator and make the decimal separator as '.'. This is the internal format of a PACK decimal field.




report zrich_0001 .


data: l_amount type bseg-wrbtr,
      l_char(16).

l_char = '7.000,00'.

translate l_char using '. '.
translate l_char using ',.'.
condense l_char no-gaps.

l_amount = l_char.

write:/ l_amount.

Regards,

Rich Heilman

0 Kudos
298

DATA: v_dcpfm    TYPE usr01-dcpfm,
      v_amount   TYPE bseg-wrbtr,
      v_char(16) TYPE C.

SELECT SINGLE dcpfm FROM usr01
                    INTO v_dcpfm
                   WHERE bname = sy-uname.
IF v_dcpfm = 'X'.
*-- decimal point is '.' and thousands separator is ','
  TRANSLATE v_char USING ', '.
  CONDENSE v_char NO-GAPS.
  v_amount = v_char.
ELSEIF v_dcpfm = 'Y'.
*-- decimal point is ',' and thousands separator is '.'
  TRANSLATE v_char USING '. '.
  CONDENSE v_char NO-GAPS.
  v_amount = v_char.
ELSE.
*-- decimal point is ',' and thousands separator is space
  CONDENSE v_char NO-GAPS.
  v_amount = v_char.
ENDIF.

Former Member
0 Kudos
298

Hi

Use move statement :

move char to curr.

Thanks.

Former Member
0 Kudos
298

hi,

Try doing it.

data: l_char(16) type c,

v_curr like ekbz-wrbtr.

start-of-selection.

l_char = '7.000,00'.

translate l_char using ', '.

translate l_char using '. '.

condense l_char no-gaps.

pack l_char to v_curr.

write 😕 v_curr.

Regards,

Sailaja.

Former Member
0 Kudos
298

Hi,

You can use following code :

data: l_amount like bseg-wrbtr,

l_char(16).

l_char = '7.000,00'.

translate l_char using '. '.

translate l_char using ',.'.

condense l_char no-gaps.

l_amount = l_char.

write : l_amount.

Cheers,

Vikram

Pls reward for helpful replies!!