Conversion Functions in ABAP CDS View Entities

60 min read
Conversion Functions in ABAP CDS View Entity
Conversion Functions convert business semantic values into calculation-friendly or business-specific formats while preserving SAP business semantics.
Click image to enlarge

Introduction

Conversion functions are among the most powerful built-in functions available in ABAP CDS View Entities. They allow developers to safely convert business semantic values such as currencies, quantities, units, and amounts into formats suitable for calculations, reporting, and analytics.

One of the most common mistakes made by developers transitioning from classical ABAP to ABAP Cloud is assuming that business semantic types such as CURR and QUAN behave like ordinary numeric values. In reality, these data types carry business meaning that SAP protects during CDS processing.

Instead of relying on implicit conversions, ABAP CDS provides a rich collection of conversion functions that execute directly inside SAP HANA while preserving the business semantics defined in the Virtual Data Model (VDM).

Architect Perspective

Architect Insight

If you have ever received activation errors while performing calculations on currency or quantity fields, you have already encountered the need for conversion functions.

These functions are not optional conveniences—they are an essential part of production-ready CDS development in SAP S/4HANA Public Cloud.

Learning Objectives

By the end of this lesson, you will understand when each conversion function should be used and how to avoid the most common mistakes encountered during CDS development.

TopicCovered
GET_NUMERIC_VALUE()
CURR_TO_DECFLOAT_AMOUNT()
CURRENCY_CONVERSION()
UNIT_CONVERSION()
Parameter Reference
Error Handling
Real SAP Scenarios
Architect Best Practices

Why Do Conversion Functions Exist?

To understand conversion functions, we first need to understand the difference between a technical numeric value and a business semantic value.

Consider a billing document amount stored as a CURR field. Although it looks like a decimal number, it actually consists of two pieces of information:

  • The numeric amount.
  • The associated currency key.

Removing either piece of information changes the business meaning of the value.

Real Project Example: Invoice Amount

An invoice amount of 10,000 means nothing unless you also know whether it is INR, USD, EUR, or JPY. Business semantic types preserve this relationship.

Business Semantic Types vs Technical Numeric Types

Business TypeBusiness MeaningCan Calculate Directly?
CURRCurrency Amount❌ No
QUANQuantity❌ No
DECTechnical Decimal✅ Yes
DECFLOAT16Decimal Floating Point✅ Yes
DECFLOAT34High Precision Decimal✅ Yes

This distinction is the primary reason why conversion functions exist. SAP intentionally separates business semantics from technical numeric calculations to ensure financial and logistical accuracy.

💡 SAP Best Practice

Never use CAST simply because a calculation fails.

First identify whether the field is a business semantic type such as CURR or QUAN. In most production scenarios, one of the dedicated conversion functions is the correct solution.

The Conversion Functions Covered in This Lesson

FunctionPrimary Purpose
GET_NUMERIC_VALUE()Remove currency or quantity semantics.
CURR_TO_DECFLOAT_AMOUNT()Convert CURR into DECFLOAT for calculations.
CURRENCY_CONVERSION()Convert an amount from one currency to another.
UNIT_CONVERSION()Convert quantities between different units of measure.

GET_NUMERIC_VALUE()

One of the most common activation errors in ABAP CDS occurs when developers attempt to perform arithmetic operations directly on CURR or QUAN fields.

Since these fields contain business semantics in addition to their numeric value, CDS does not treat them as ordinary decimal numbers. The GET_NUMERIC_VALUE() function removes those semantics and returns only the underlying numeric value, making it suitable for calculations.

Syntax
ABAP CDS
get_numeric_value( amount_or_quantity )

Architect Perspective

Think of GET_NUMERIC_VALUE() as removing the business wrapper from a CURR or QUAN field.

The business meaning still exists in your data model, but the returned expression behaves like a normal numeric value that can be used in mathematical calculations.
⚙️

GET_NUMERIC_VALUE() Parameters

The following table describes all supported parameters for this function.

ParameterRequiredTypeDefaultDescriptionExample
amount_or_quantityRequiredCURR / QUANCurrency amount or quantity whose numeric value should be returned.TotalNetAmount

Example: Calculating GST

Consider the following billing amount.

Incorrect
ABAP CDS
TotalNetAmount * 0.18 as GSTAmount

Depending on the data type, this expression may fail to activate because TotalNetAmount is a CURR field rather than a simple decimal value.

Instead, remove the currency semantics first.

Correct
ABAP CDS
get_numeric_value(
    TotalNetAmount
) * 0.18 as GSTAmount

Real Project Example: Billing Analytics

Many analytical CDS Views calculate GST, discounts, commissions, margins, and percentages. GET_NUMERIC_VALUE() is commonly used before these calculations.

CURR_TO_DECFLOAT_AMOUNT()

Although GET_NUMERIC_VALUE() removes business semantics, many financial calculations require higher decimal precision than standard packed numbers.

This is where CURR_TO_DECFLOAT_AMOUNT()becomes useful.

Syntax
ABAP CDS
curr_to_decfloat_amount( amount )

Instead of simply removing the business semantics, this function converts a CURR field into a DECFLOAT34 value suitable for high-precision financial calculations.

⚙️

CURR_TO_DECFLOAT_AMOUNT() Parameters

The following table describes all supported parameters for this function.

ParameterRequiredTypeDefaultDescriptionExample
amountRequiredCURRCurrency amount to be converted into DECFLOAT.TotalNetAmount

Example: Financial Calculation

Example
ABAP CDS
curr_to_decfloat_amount(
    TotalNetAmount
) * 1.18 as GrossAmount

The resulting value has the DECFLOAT type, making it ideal for calculations that require greater decimal precision than packed numbers.

GET_NUMERIC_VALUE() vs CURR_TO_DECFLOAT_AMOUNT()

FunctionReturnsTypical Usage
GET_NUMERIC_VALUE()Numeric ValueGeneral mathematical calculations
CURR_TO_DECFLOAT_AMOUNT()DECFLOAT34Financial calculations requiring higher precision

Architect Perspective

Both functions solve similar problems but produce different output types.

If precision is important—for example in financial reporting, taxation, or currency calculations—prefer CURR_TO_DECFLOAT_AMOUNT().

When Should You Use Each Function?

ScenarioRecommended Function
Calculate GSTGET_NUMERIC_VALUE()
Calculate Discount PercentageGET_NUMERIC_VALUE()
Margin CalculationCURR_TO_DECFLOAT_AMOUNT()
Financial ReportingCURR_TO_DECFLOAT_AMOUNT()
Currency ConversionCURRENCY_CONVERSION()

💡 SAP Best Practice

Avoid using CAST()to convert CURR fields for calculations.

SAP provides dedicated conversion functions that preserve business semantics and produce predictable results. These functions should always be preferred over generic type conversion.

Common Mistakes

  • Using CAST() instead of GET_NUMERIC_VALUE() for arithmetic operations.
  • Assuming CURR behaves like DEC in CDS.
  • Using CURR_TO_DECFLOAT_AMOUNT() when only a simple numeric calculation is required.
  • Ignoring the resulting data type after conversion.

CURRENCY_CONVERSION()

The CURRENCY_CONVERSION() function converts an amount from one currency into another using the exchange rates maintained in the SAP system.

Unlike GET_NUMERIC_VALUE() or CURR_TO_DECFLOAT_AMOUNT(), this function performs a true business conversion rather than simply changing the technical data type.

Syntax
ABAP CDS
currency_conversion(
    amount               => amount,
    source_currency      => source_currency,
    target_currency      => target_currency,
    exchange_rate_date   => exchange_rate_date
)

Architect Perspective

Currency conversion is a business operation, not a mathematical one.

SAP automatically looks up exchange rates from the currency configuration tables using the supplied exchange rate date and exchange rate type.
⚙️

CURRENCY_CONVERSION() Parameters

The following table describes all supported parameters for this function.

ParameterRequiredTypeDefaultDescriptionExample
amountRequiredCURRSource amount to convert.TotalNetAmount
source_currencyRequiredCUKYCurrency of the source amount.TransactionCurrency
target_currencyRequiredCUKYCurrency into which the amount should be converted.cast('USD' as abap.cuky(5))
exchange_rate_dateRequiredDATSDate used to determine the exchange rate.$session.system_date
exchange_rate_typeOptionalCHAR(4)'M'Exchange rate type maintained in SAP.'M'
roundOptionalCHAR(1)System DefaultApply commercial rounding.'X'
decimal_shiftOptionalCHAR(1)Shift decimal places before conversion.
decimal_shift_backOptionalCHAR(1)Shift decimal places after conversion.
clientOptionalCLNTClient used for exchange rate lookup.$session.client
error_handlingOptionalCHAR(20)'FAIL_ON_ERROR'Determines behavior if conversion fails.

Basic Example

Convert Billing Amount into USD
ABAP CDS
@Semantics.amount.currencyCode: 'TransactionCurrency'

currency_conversion(

    amount               => TotalNetAmount,

    source_currency      => TransactionCurrency,

    target_currency      => cast( 'USD' as abap.cuky(5) ),

    exchange_rate_date   => $session.system_date

) as USDAmount

SAP automatically determines the exchange rate using the configured exchange rate tables and converts the billing amount into USD.

Why Do We Need CAST()?

One of the most common activation errors looks like this:

Activation Error
text
Literal of type CHAR is not supported for parameter TARGET_CURRENCY

Many developers naturally write:

Incorrect
ABAP CDS
target_currency => 'USD'

However, the target_currency parameter expects a value of type CUKY, not a plain character literal.

Correct
ABAP CDS
target_currency => cast(
    'USD'
    as abap.cuky(5)
)

💡 SAP Best Practice

Whenever a CDS function expects a semantic business type such as CUKY or UNIT, use CAST() to convert string literals into the appropriate semantic type.

Handling Conversion Errors

Another common question is:

Developer Question
text
What happens if SAP cannot determine an exchange rate?

By default, CDS raises an exception and the query fails.

To control this behavior, use the error_handling parameter.

ValueBehavior
'FAIL_ON_ERROR'Raise an exception (default).
'SET_TO_NULL'Return NULL when conversion fails.
'KEEP_UNCONVERTED'Return the original amount without conversion.

Example with Error Handling

Recommended Example
ABAP CDS
currency_conversion(

    amount               => TotalNetAmount,

    source_currency      => TransactionCurrency,

    target_currency      => cast(
        'USD'
        as abap.cuky(5)
    ),

    exchange_rate_date   => $session.system_date,

    error_handling       => 'SET_TO_NULL'

) as USDAmount

Real Project Example: Missing Exchange Rates

Production systems occasionally encounter missing exchange rates for historical dates or rarely used currencies. Returning NULL is often preferable to causing the entire CDS query to fail.

Architect Perspective

Many developers discover the error_handling parameter only after encountering runtime errors.

As an architect, decide the desired business behavior up front:
  • Financial reporting usually requires FAIL_ON_ERROR.
  • Analytical dashboards often prefer SET_TO_NULL.
  • Operational reports sometimes use KEEP_UNCONVERTED.

Common Mistakes

  • Passing 'USD' directly instead of casting it to CUKY.
  • Ignoring the error_handling parameter.
  • Using today's date when historical exchange rates should be used.
  • Assuming currency_conversion() only changes the data type—it performs a business conversion using SAP exchange rates.

UNIT_CONVERSION()

Just as CURRENCY_CONVERSION() converts monetary values between different currencies, UNIT_CONVERSION() converts quantities between different units of measure using the conversion rules maintained in SAP.

Instead of manually multiplying values by conversion factors, SAP automatically determines the correct conversion ratio based on the configured Unit of Measure (UoM) master data.

Syntax
ABAP CDS
unit_conversion(

    quantity        => quantity,

    source_unit     => source_unit,

    target_unit     => target_unit

)

Architect Perspective

Unit conversion is a business conversion rather than a mathematical multiplication.

SAP determines the appropriate conversion factor from the Unit of Measure configuration rather than relying on hard-coded formulas.
⚙️

UNIT_CONVERSION() Parameters

The following table describes all supported parameters for this function.

ParameterRequiredTypeDefaultDescriptionExample
quantityRequiredQUANQuantity to be converted.OrderQuantity
source_unitRequiredUNITCurrent unit of measure.BaseUnit
target_unitRequiredUNITTarget unit of measure.cast('KG' as abap.unit(3))
clientOptionalCLNTClient used during conversion.$session.client
error_handlingOptionalCHAR(20)'FAIL_ON_ERROR'Determines the behavior if conversion cannot be performed.

Basic Example

Convert Quantity into Kilograms
ABAP CDS
@Semantics.quantity.unitOfMeasure: 'BaseUnit'

unit_conversion(

    quantity        => OrderQuantity,

    source_unit     => BaseUnit,

    target_unit     => cast(
        'KG'
        as abap.unit(3)
    )

) as QuantityInKG

SAP automatically converts the quantity into kilograms using the maintained Unit of Measure conversion definitions.

Why CAST() Is Required

Just like currency conversion, the target_unit parameter expects the semantic data type UNIT, not a character literal.

Incorrect
ABAP CDS
target_unit => 'KG'
Correct
ABAP CDS
target_unit => cast(

    'KG'

    as abap.unit(3)

)

💡 SAP Best Practice

Whenever a conversion function expects a semantic business type such as UNIT or CUKY, always CAST literals to the appropriate semantic type.

Error Handling

UNIT_CONVERSION() supports the same error handling strategies as CURRENCY_CONVERSION().

ValueBehavior
'FAIL_ON_ERROR'Raise an exception.
'SET_TO_NULL'Return NULL if conversion fails.
'KEEP_UNCONVERTED'Return the original quantity.
Recommended Example
ABAP CDS
unit_conversion(

    quantity        => OrderQuantity,

    source_unit     => BaseUnit,

    target_unit     => cast(
        'KG'
        as abap.unit(3)
    ),

    error_handling  => 'SET_TO_NULL'

) as QuantityInKG

Real-World Example

Real Project Example: Procurement Dashboard

Suppliers may deliver materials in different units such as G, KG, LB, TON, EA, or BOX. Before comparing procurement quantities across suppliers, all values should be converted into a common reporting unit using UNIT_CONVERSION().

CURRENCY_CONVERSION() vs UNIT_CONVERSION()

FeatureCURRENCY_CONVERSION()UNIT_CONVERSION()
ConvertsCurrency AmountQuantity
Business Semantic TypeCURRQUAN
Target TypeCUKYUNIT
Configuration SourceExchange Rate TablesUnit of Measure Configuration
Typical ScenarioFinancial ReportingInventory & Logistics

Which Conversion Function Should You Use?

RequirementRecommended Function
Remove CURR semanticsGET_NUMERIC_VALUE()
Convert CURR to DECFLOATCURR_TO_DECFLOAT_AMOUNT()
Convert CurrencyCURRENCY_CONVERSION()
Convert QuantityUNIT_CONVERSION()

Common Mistakes

  • Passing 'KG' directly instead of casting it to UNIT.
  • Using multiplication instead of UNIT_CONVERSION().
  • Ignoring error handling for missing unit conversions.
  • Confusing UNIT_CONVERSION() with GET_NUMERIC_VALUE().

Architect Perspective

One of the biggest differences between classical ABAP and ABAP CDS is trusting the SAP business configuration.

Rather than maintaining your own conversion factors, always use UNIT_CONVERSION() and CURRENCY_CONVERSION() whenever business semantics are involved. This ensures that your CDS Views remain aligned with SAP configuration and continue to work correctly even when conversion rules change.

Understanding Error Handling

Both CURRENCY_CONVERSION() and UNIT_CONVERSION() perform business conversions using SAP configuration.

In production systems, conversions may occasionally fail because exchange rates or unit conversion definitions are unavailable. Instead of allowing the entire CDS query to fail, SAP provides the error_handling parameter to control the desired behavior.

Architect Perspective

Never choose an error handling strategy based only on technical convenience.

The correct option depends entirely on the business requirement.

Supported Error Handling Options

OptionBehaviorTypical Usage
'FAIL_ON_ERROR'Raises an exception and stops processing.Financial postings, statutory reporting
'SET_TO_NULL'Returns NULL when conversion fails.Analytical CDS Views, dashboards
'KEEP_UNCONVERTED'Returns the original value without conversion.Operational reports

Example: FAIL_ON_ERROR

Financial Reporting
ABAP CDS
currency_conversion(

    amount               => TotalNetAmount,

    source_currency      => TransactionCurrency,

    target_currency      => cast(
        'USD'
        as abap.cuky(5)
    ),

    exchange_rate_date   => $session.system_date,

    error_handling       => 'FAIL_ON_ERROR'

) as USDAmount

Real Project Example: Statutory Financial Reporting

When preparing statutory financial statements, silently ignoring missing exchange rates is unacceptable. The report should fail immediately so the missing configuration can be corrected.

Example: SET_TO_NULL

Analytical Dashboard
ABAP CDS
currency_conversion(

    amount               => TotalNetAmount,

    source_currency      => TransactionCurrency,

    target_currency      => cast(
        'USD'
        as abap.cuky(5)
    ),

    exchange_rate_date   => $session.system_date,

    error_handling       => 'SET_TO_NULL'

) as USDAmount

Real Project Example: Management Dashboard

A dashboard should continue loading even if a few historical exchange rates are missing. Returning NULL allows users to continue analyzing the remaining data.

Example: KEEP_UNCONVERTED

Operational Report
ABAP CDS
currency_conversion(

    amount               => TotalNetAmount,

    source_currency      => TransactionCurrency,

    target_currency      => cast(
        'USD'
        as abap.cuky(5)
    ),

    exchange_rate_date   => $session.system_date,

    error_handling       => 'KEEP_UNCONVERTED'

) as USDAmount

Real Project Example: Operational Monitoring

Warehouse or operational reports sometimes prefer displaying the original value rather than interrupting users with an exception.

Architect Best Practices

💡 SAP Best Practice

  • Use GET_NUMERIC_VALUE() when removing business semantics before calculations.
  • Use CURR_TO_DECFLOAT_AMOUNT() for high-precision financial calculations.
  • Use CURRENCY_CONVERSION() instead of manually multiplying exchange rates.
  • Use UNIT_CONVERSION() instead of maintaining custom conversion factors.
  • Always CAST string literals supplied to semantic parameters such as CUKY and UNIT.
  • Select the appropriate error_handling strategy according to the business requirement rather than personal preference.

Interview Questions

BeginnerInterview Question

Why can't CURR fields always be used directly in calculations?

Answer: Because CURR is a business semantic type rather than a simple numeric value.

ExperiencedInterview Question

What is the difference between GET_NUMERIC_VALUE() and CURR_TO_DECFLOAT_AMOUNT()?

Answer: GET_NUMERIC_VALUE() removes business semantics, whereas CURR_TO_DECFLOAT_AMOUNT() converts the amount into a DECFLOAT value suitable for high-precision calculations.

ExperiencedInterview Question

Why must 'USD' be cast when supplied as target_currency?

Answer: Because target_currency expects the semantic type CUKY rather than a character literal.

ExperiencedInterview Question

When should SET_TO_NULL be preferred over FAIL_ON_ERROR?

Answer: For analytical CDS Views or dashboards where displaying partial results is preferable to terminating the query.

ArchitectInterview Question

Should currency conversion be implemented using multiplication or CURRENCY_CONVERSION()?

Answer: Always use CURRENCY_CONVERSION() because SAP automatically determines the correct exchange rate from system configuration.

💱
Developer Reference

Conversion Functions Cheat Sheet

4 Functions • Business Conversions • SAP HANA Pushdown

Quick reference for the most commonly used conversion functions in ABAP CDS View Entities.

FunctionSyntaxPurpose
GET_NUMERIC_VALUE()get_numeric_value(field)Remove business semantics
CURR_TO_DECFLOAT_AMOUNT()curr_to_decfloat_amount(field)Convert CURR to DECFLOAT
CURRENCY_CONVERSION()currency_conversion(...)Convert currency values
UNIT_CONVERSION()unit_conversion(...)Convert units of measure

💡 Key Takeaway

Conversion functions are essential for building production-ready CDS View Entities. Rather than relying on generic type conversion or manual calculations, SAP provides specialized functions that preserve business semantics while executing efficiently in SAP HANA.

Understanding when to use GET_NUMERIC_VALUE(), CURR_TO_DECFLOAT_AMOUNT(), CURRENCY_CONVERSION(), and UNIT_CONVERSION() is a fundamental skill expected from every ABAP Cloud developer and SAP Technical Architect.

Watch the Complete ADT Walkthrough

In the accompanying video, we'll implement every conversion function discussed in this lesson using Eclipse ADT and SAP S/4HANA Public Cloud. We'll troubleshoot common activation errors, explore error handling strategies, and build production-ready examples.