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

custom conversion routine for currency output

Former Member
0 Likes
4,321

Hi,

First of all: I know how to convert one currency to another, that is not the question here!

I need to format the output decimal places for a currency. I know that SAP does that automatically, but I am using a custom conversion routine for my currencies, therefore SAP-standard is not used.

Currently my conversion focussed on the input, but now it is required to provide the correct output for foreign currencies like JPY and so on, which have other decimal places than the standard 2.

My question:

How can I do the decimal conversion, when I only have the amount, but not the currency to convert for?

Can I get the SAP-standard conversion routine for output of currencies to work somehow although I have a special implementation? Or at least find out how the standard-routine does its job?

I hope that someone has an idea on this!

Regards,

Robert

Edited by: Robert Schulz on Oct 24, 2011 1:11 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,843

Hi Robert,

If you have Currency than below logic may help you...

DATA: lv_amount TYPE vtcur12_cum,

ls_tcurx TYPE tcurx,

shift(2) TYPE p.

SELECT SINGLE currdec

FROM tcurx

INTO ls_tcurx-currdec

WHERE currkey = currency key.

IF sy-subrc = 0.

shift = 2 - ls_tcurx-currdec.

lv_amount = lv_amount * ( 10 ** shift ).

ENDIF.

Regards,

Ganesh Lathi.

Edited by: Ganesh Lathi on Oct 25, 2011 8:57 AM

Hi,

First of all: I know how to convert one currency to another, that is not the question here!

I need to format the output decimal places for a currency. I know that SAP does that automatically, but I am using a custom conversion routine for my currencies, therefore SAP-standard is not used.

Currently my conversion focussed on the input, but now it is required to provide the correct output for foreign currencies like JPY and so on, which have other decimal places than the standard 2.

My question:

How can I do the decimal conversion, when I only have the amount, but not the currency to convert for?

Can I get the SAP-standard conversion routine for output of currencies to work somehow although I have a special implementation? Or at least find out how the standard-routine does its job?

I hope that someone has an idea on this!

Regards,

Robert

Edited by: Robert Schulz on Oct 24, 2011 1:11 PM

7 REPLIES 7
Read only

Former Member
0 Likes
2,844

Hi Robert,

If you have Currency than below logic may help you...

DATA: lv_amount TYPE vtcur12_cum,

ls_tcurx TYPE tcurx,

shift(2) TYPE p.

SELECT SINGLE currdec

FROM tcurx

INTO ls_tcurx-currdec

WHERE currkey = currency key.

IF sy-subrc = 0.

shift = 2 - ls_tcurx-currdec.

lv_amount = lv_amount * ( 10 ** shift ).

ENDIF.

Regards,

Ganesh Lathi.

Edited by: Ganesh Lathi on Oct 25, 2011 8:57 AM

Read only

0 Likes
2,843

Hi Ganesh,

Thanks for the reply!

Unfortunately I already got this logic from function module BAPI_CURRENCY_CONV_TO_EXTERNAL.

But my issue is that, for example in ALV-display I do not know the current currency...or at least have no idea how to get it for that line.

Regards,

Robert

Read only

0 Likes
2,843

Hi Robert,

If problem is with ALV than conversion is not needed. This can be achived by defining the refrence currency field name in the fieldcatalog of amount field.

In field catalog for amount field , fill the CFIELDNAME (ALV control: Field name for currency unit referenced) field with the refrence currency field which the amount field is following.

The ALV will automatically do all the conversions and will display correctly.

Regards,

Ganesh.

Edited by: Ganesh Lathi on Oct 25, 2011 11:53 AM

Read only

0 Likes
2,843

Hi Ganesh,

Unfortunately I already have a custom programmed conversion exit. Therefore only this exit is called, but not the generic currency output conversion.

Therefore I need to know how to get the referenced currency within a conversion exit.

Regards,

Robert

Read only

0 Likes
2,843

Hi Robert,

Can you please give a small cade of your custome conversion exit, as without any refrence currency how its done.

This may give some clue.

Regards,

Ganesh.

Read only

Former Member
0 Likes
2,843

Hi Robert ,

You want to display the currency based on the output . I din't your question can ypu xplain it briefly so that i can helpful for you.

Read only

Former Member
0 Likes
2,843

Hi,

I will try to summarize my issue again:

Situation as is:

- values stored with 3 decimal places -> own output conversion exit programmed which reduces output to 2 decimal places

- referenced currency (for values) is in other table

- automatic output conversion for currency only works if currency is in same table / display-structure

- error in automatic currency output conversion: comma is deleted -> internal value 12.345 JPY gets converted to 12,345 JPY for output - which is wrong

What I am looking for:

A way to find out the currency for an output value in my output conversion exit.

-> Type descriptors only lead to the name of the reference field for the currency, but not its actual value (USD, JPY, ...).

Coding of my conversion exit currently:


"INPUT -> Type CURR, No. Characters 20, Decimal Places 3
DATA: lv_number TYPE /sie/ad_z0vppr_volume_2. "Type CURR, No. Characters 20, Decimal Places 2

lv_number = input.
WRITE lv_number TO output.
CONDENSE output NO-GAPS.

As you can see, there is no currency specific conversion implemented yet.

Kind Regards,

Robert