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: 

currency to character & character to currency conversions

Former Member
0 Kudos

I am using a Currency field from SAPScript in an ABAP Program to retrieve certain values. So I am passing the currency value as text field along with the commas and decimals to the Program from the SAPscript . I need to convert this to currency format so that I could use this in the select statement. How do I achieve this?

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

Try with this code:

DATA: P_DBMTR TYPE DMBTR.
DATA: C_VALUE(20).

c_value = '123,456.78'.

* Convert to amount
replace all OCCURENCES of ',' in c_value  with ' '.
condense c_value.
move c_value to P_DBMTR.


* convert back from amount to char
write: P_DBMTR to c_value.

Regards,

Naimesh Patel

8 REPLIES 8

Former Member
0 Kudos

Hi Anjana,

Declare a character variable with the same lenght as currency variable.

Just Move the currency variable value to character varaiable.

If you have any problem with comma in the currency variable just replace with ''.

Regards,

Satish

0 Kudos

My main problem is conversion from character to currency. How can I remove the commas in the character field?

0 Kudos

Replace Comma with '.'.

Regards,

Satish

Message was edited by:

Satish Panakala

naimesh_patel
Active Contributor
0 Kudos

Try with this code:

DATA: P_DBMTR TYPE DMBTR.
DATA: C_VALUE(20).

c_value = '123,456.78'.

* Convert to amount
replace all OCCURENCES of ',' in c_value  with ' '.
condense c_value.
move c_value to P_DBMTR.


* convert back from amount to char
write: P_DBMTR to c_value.

Regards,

Naimesh Patel

0 Kudos

Naimesh, I assume 'all occurences' work only in higher versions of SAP. I get a syntax error when I used this...we are still on 45B.

0 Kudos

Ok than try with this:

replace ',' in c_value  with ' '.
replace ',' in c_value  with ' '.
replace ',' in c_value  with ' '.
replace ',' in c_value  with ' '.
condense c_value.
move c_value to P_DBMTR.

Regards,

Naimesh Patel

0 Kudos

Thanks Naimesh and Sadish for your helpful answers. It is working now.

Anjana

Former Member
0 Kudos

Refer this code.....

http://theabap.blogspot.in/2012/02/character-to-currencyformat-conversion.html

Hope you will like it really...