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: 

Conversion of char into currency

Former Member
0 Kudos

Hi

How to convert a character into currency value? Is there any FM available?

For instance if string = '10-' , it should be converted as 10.00.

Regards

Nithy

8 REPLIES 8

Former Member
0 Kudos

Hello,

Check this.

HRCM_STRING_TO_AMOUNT_CONVERT


one more 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.

Cheers,

Vasanth

Former Member
0 Kudos

Hi,

Try the FM 'CHAR_FLTP_CONVERSION'. Assign the value to field 'STRING'. leave the rest of the import parameters as default. If the input value is correct, you can find the value in 'FLSTR' (export parameter

Also try this:

Directly assing char value to currency field, no need of any FM.

Data: x TYPE kbetr. (currency field)

y TYPE char10.

y = '100.45'.

x = y.

<REMOVED BY MODERATOR>

Cheers,

Chandra Sekhar.

Edited by: Alvaro Tejada Galindo on Feb 25, 2008 5:17 PM

Former Member
0 Kudos

Move into a variable of type p ...

Data : v_string(3) value '10-'.

data : v_p type p decimals 2.

v_p = v_string.

write 😕 v_p.

Former Member
0 Kudos

Hi,

Try using FM PSSV_TEXT_INTO_FIELD_CURRENCY.

Thanks,

Sriram Ponna.

0 Kudos

Assigning Currency Fields to Character Type Fields:

REPORT ztest.

DATA: curr TYPE kna1-umsa1,

char(254) TYPE c,

char1(254) TYPE c.

DATA: temp TYPE p LENGTH 15 DECIMALS 2.

WRITE curr TO char LEFT-JUSTIFIED.

WRITE: 'CHAR = '.

WRITE : char.

WRITE:/ 'CURR = '.

WRITE: curr.

Assigning Character Fields to Currenecy Type Fields:

REPORT ztest.

DATA: curr TYPE kna1-umsa1,

char(254) TYPE c.

DATA: temp TYPE p LENGTH 15 DECIMALS 2.

char = '1,405.25'.

REPLACE ALL OCCURRENCES OF '.' IN char WITH space.

REPLACE ALL OCCURRENCES OF ',' IN char WITH space.

CONDENSE char NO-GAPS.

temp = char.

curr = temp / 100.

WRITE: 'CHAR = '.

WRITE: char.

WRITE:/ 'CURR = '.

WRITE: curr.

Source : [http://www.abapmadeeasy.com/2011/02/sap-abap-sample-program-on-type.html|http://www.abapmadeeasy.com/2011/02/sap-abap-sample-program-on-type.html]

Edited by: uttamagrawal on Mar 15, 2011 1:12 PM

former_member377111
Participant
0 Kudos

Please find the below example.

DATA:lv TYPE string VALUE '10-',

lv_kbetr TYPE kbetr.

MOVE lv TO lv_kbetr.

WRITE lv_kbetr CURRENCY 'INR' NO-SIGN.

Hope this helps.

Former Member
0 Kudos

Try below code.... definitely works...

REPORT ZCHAR2CURR.

parameters char(30) type c.

data : txt(30) type c,

curr(40) type c,

len type i,

temp type i.

len = strlen( char ).

temp = len - 2.

concatenate ',' char+temp(2) into txt.

curr = txt.

char = char+0(temp).

len = strlen( char ).

do.

if len gt 3.

temp = len - 3.

concatenate ',' char+temp(3) into txt.

concatenate txt curr into curr.

char = char+0(temp).

len = strlen( char ).

else.

txt = char+0(len).

concatenate txt curr into curr.

exit.

endif.

enddo.

concatenate curr '.00' into curr.

write : 'Amount in Currency format :', curr.

Former Member