CDS Conversion Functions (CAST, Unit Conversion, Currency Conversion)

CDS SQL Expressions

CAST Expression

Supported Operands: Literal, column, path expression, build-in function, arithmetic expression

  • Various data types in ABAP namespace supported
  • Result length determined at activation time
  • No nesting of CAST expressions
  • Alias names required for resulting columns

Cast foreign currency amount from sbook as reduced_amount and Savings

@AbapCatalog.sqlViewName: 'Zcds_cast_sql'
define view Zcds_cast as select from sbook
  forcuram as Amount,
  cast( forcuram as abap.fltp ) + ( cast ( -forcuram as abap.fltp ) * 0.03 ) as ReducedAmount,
  cast( forcuram as abap.fltp )* 0.03 as Savings

Unit Conversion

The function UNIT_CONVERSION performs a unit conversion for the value passed to the formal parameter quantity.

@AbapCatalog.sqlViewName: 'zcds_unit_sql'
define view zcds_unit as select from sbook
  unit_conversion (
    quantity => luggweight,
    source_unit => wunit,
    target_unit => cast( 'G' as abap.unit ) ) as `Weight_In_Grams

Currency Conversion

The function CURRENCY_CONVERSION performs a currency conversion for the value passed to the formal parameter amount.

@AbapCatalog.sqlViewName: 'zcds_curr _sql'
@ClientDependent: true
define view zcds_curr as select from sbook
    amount => loccuram,
    source_currency => loccurkey,
    target_currency => cast('EUR' as abap.cuky(5)),
    exchange_rate_date => order_date ) as euro_amount

What do you think?

Written by admin

Leave a Reply

Your email address will not be published. Required fields are marked *

CDS SQL Expressions

SAP ABAP CDS SQL Expressions – CASE expressions ( Simple CASE, Searched CASE & Nested CASE ), COALESCE

CDS String Functions(Concat, Instr, Left / Right, Length, Lpad / Rpad, Ltrim / Rtrim ,Replace)