Uploaded by rubhanedwin15

Unit and Currency Conversion in CDS View

advertisement
Unit Conversion in CDS View
Standard Table : T006
The code and delivery are pretty simple, create a new Data Definition via HANA Studio with the name of
ZCDS_UNIT_CONVERSION and include the following code.
@AbapCatalog.sqlViewName: 'ZCDSUNITCONV'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS Demo by Felipe Rodrigues'
define view ZCDS_UNIT_CONVERSION
as select from saplane
{
@EndUserText.label: 'Plane Type'
key planetype as PlaneType,
@EndUserText.label: 'Tank Cap'
tankcap as TankCapacity,
@EndUserText.label: 'Tank Cap (UOM)'
cap_unit as CapacityUnit,
@EndUserText.label: 'Tank Cap (in Cubic Meters)'
unit_conversion(
quantity => tankcap,
source_unit => cap_unit,
target_unit => cast('M3' as abap.unit)
)
as TankCapacityInM3,
@EndUserText.label: 'Tank Cap (in Cubic Yard)'
unit_conversion(
quantity => tankcap,
source_unit => cap_unit,
target_unit => cast('YD3' as abap.unit)
)
as TankCapacityInYD3
}
Run the Data Preview and check the result:
Let’s re-conciliate the data from the first record via google assistant.
Liters (L) to Cubic Meters (M3)
Liters (L) to Cubic Yards (YD3)
Currency Conversion for CDS View
Standard Table : TCURR
For this example, I am using Airfare (PRICE) and converting the value to Australian Dollars (AUD).
This is a pretty interesting scenario because the prices usually vary depending depending on the flight
and company, with the standard function we are able to convert the values dynamically.
To achieve this result let’s create a new Data Definition via HANA Studio with the name of
ZCDS_CURRENCY_CONVERSION and include the following code.
@AbapCatalog.sqlViewName: 'ZCDSCURRCONV'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS Demo by Felipe Rodrigues'
define view ZCDS_CURRENCY_CONVERSION
as select from sflight
{
@EndUserText.label: 'Airline Code'
key carrid as AirlineCode,
@EndUserText.label: 'Connection No.'
key connid as ConnectionNumber,
@EndUserText.label: 'Flight Date'
key fldate as FlightDate,
@EndUserText.label: 'Price'
price as Price,
@EndUserText.label: 'Currency'
currency as Currency,
@EndUserText.label: 'Price (in Australian Dollars)'
currency_conversion(
amount
=> price,
source_currency => currency,
target_currency => cast('AUD' as abap.cuky),
exchange_rate_date => fldate
)
as PriceInAUD
}
Notice the CURRENCY_CONVERSION has a mandatory parameter named EXCHANGE_RATE_DATE, for
this scenario we need to assign the Flight Date for the exchange date, the system is going to analyse the
options available in the table TCURR automatically and provide the proper conversion rate based on the
date the customer acquired the flight ticket.
Run the Data Preview and check the result below:
Important Note: The accuracy of your currency conversion will depend on how often you update
the Exchange Rate in your SAP system. In my case the conversion is not accurate because this data is
from a development environment but if you have updated conversion rates in your system you will find
the proper values in the output of this CDS view.
Download