Currency conversion in ABAP CDS

Currency conversion in ABAP CDS is one of the most useful stuff for SAP projects with global rollouts. Technical consultants working in such projects would agree with this. It’s one of the most common requirement. In this article, let’s see how the currency conversion in ABAP CDS is done.

For example, you have been asked by your technical lead to create an ABAP CDS view, which shall show the rates of the flight tickets in the user’s local currency.

Hmmm, what do we have for currency conversion in ABAP CDS. After thinking hard for a minute you try to google and the universe forces direct you to this article which says use

ABAP CDS’s conversion function ‘CURRENCY_CONVERSION’


That was a bumper….isn’t it! Let’s cut the chase now and see how it works. It’s time to QUICKLY LEARN it (respecting the blog title) and get the work done!

@AbapCatalog.sqlViewName: 'ZVIEW_CURR_CONV'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Currency Conversion in CDS'
with parameters
    transaction_date   : abap.dats,
    local_curr         : abap.cuky(5)
 as select from sflight {
        amount          => price, 
        source_currency => currency,
        target_currency => $parameters.local_curr,
        exchange_rate_date => $parameters.transaction_date ) 
        as local_price,
    $parameters.local_curr as local_currency    

It’s time to test the code. Press F8 on the Eclipse editor and fill the values for CDS parameters ‘TRANSACTION_DATE’ and ‘LOCAL_CURR’ as ‘20201121’ (YYYYMMDD date format) and ‘USD’ respectively.

Currency conversion in ABAP CDS - Output 1

Click OK to see the result in the new tab in Eclipse editor, as shown in the below screenshot. Notice the highlighted rows with the converted currency values from the result list.

Currency conversion in ABAP CDS - Output 2

Here you go with quick learning ‘Currency conversion in ABAP CDS’.