Application Development and Automation 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: 
Read only

Amount to internal format

Former Member
0 Likes
5,879

I want to convert the amount to its equivalent internal format..

For example, my amount may 200,000.000USD.. I want to get its equivalent internal format.. Is there a FM to do this?

i GUESS i can use this FM , CURRENCY_AMOUNT_DISPLAY_TO_SAP..but this FM requires my input in DEC11_4 format.. how do I handle the amount that i have in character format or with decimal places more than 4 ?

Please confirm

I want to convert the amount to its equivalent internal format..

For example, my amount may 200,000.000USD.. I want to get its equivalent internal format.. Is there a FM to do this?

i GUESS i can use this FM , CURRENCY_AMOUNT_DISPLAY_TO_SAP..but this FM requires my input in DEC11_4 format.. how do I handle the amount that i have in character format or with decimal places more than 4 ?

Please confirm

10 REPLIES 10
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
3,125

No need for a function module.



report zrich_0001.

data: amount(15) type c value '200,000,000.000'.

while sy-subrc = 0.
replace ',' with space into amount.
endwhile.
condense amount no-gaps.

write:/ amount.

Regards,

Rich Heilman

Read only

0 Likes
3,125

I had thought of replace, but was hoping SAP would have something more fancy!!!

Read only

0 Likes
3,125

Well, there is always more than one way in SAP. As Srinivas has suggested, you could use translate as well.



TRANSLATE mycharfield USING ', '.

Regards,

Rich Heilman

Read only

0 Likes
3,125

Srini, Rich Thanx.. How does it handle the '-' sign?

Do we need to do anything special?

Also what is the easiest way to validate if my 'character number field' is actually a valid number (i am allowing -,' ', ',', '.')..

Read only

0 Likes
3,125

You should have to do anything special there. In the character field, it is coming on the RIGHT side, right?

If so, I don't see any problems there.

Please make sure that you award points for answers that have helped you. Thanks.

Regards,

RIch Heilman

Read only

0 Likes
3,125

You can do something like this.



report zrich_0001.


data: amount(50) type c value '200,abc,123.000'.
data: length type i.

shift amount left deleting leading space.
length = strlen( amount ).
if amount+0(length) co '1234567890,.'.
  write:/ 'Looks ok to me'.
else.
  write:/ 'Hey, this is not a number'.

endif.

Regards,

Rich Heilman

Read only

0 Likes
3,125

Rich, my primary concern is that ',' or '.' can be used interchangeably in display mode... So how do i convert my truely display format to internal format?

For example, a user may have a display notation of 1.234.567,89 ... How can I convert that to the internal format? If my input amount is 1.234.567,89, when I send it to SAP, it should go as 1234567.89 right? Now if i do string manipulation, then I have to know the user's display property..

Read only

0 Likes
3,125

You can do something like this.



report zrich_0001.

data: amount(15) type c value '200,000,000.000'.

data: xusr01 type usr01.


select single * from usr01 into xusr01
               where bname = sy-uname.

case xusr01-dcpfm.
  when  'X'.
    translate amount using ', '.
  when  ' '.
    translate amount using '. '.
    translate amount using ',.'.

  when  'Y'.
    translate amount using ',.'.
endcase.

condense amount no-gaps.

write:/ amount.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
3,125

Amounts are controlled by the currency key for the number of decimal places. In the table itself they may be stored with any number of decimal places, but once you select them, they will have the right number of decimals. So always select both the amount and the currency key fields.

Now if you are asking about just removing the formatting characters from an amount that is in a character field, then you can do as follows

SHIFT mycharfield LEFT DELETING LEADING SPACE.

TRANSLATE mycharfield USING ', '.

CONDENSE mycharfield NO-GAPS.

Srinivas

Read only

Former Member
0 Likes
3,125

try Set Country command after assigning values.

e.g.: SET COUNTRY 'US'.

Reward if helpful