SAP ABAP CDS View – CONCATENATE (String Concatenation)
In ABAP Core Data Services (CDS) views, you can use the || operator to concatenate multiple fields or values into a single string. This is useful for formatting output, creating composite keys, or enhancing UI display.
🔹 Basic Syntax of String Concatenation in CDS
define view ZDEMO_CDS as select from sflight { key carrid, key connid, fldate, carrid || ' - ' || connid as flight_info}🔹 Explanation:
✅ Joins carrid and connid with " - " in between.
✅ The result will be a single text field (e.g., LH - 400).
🔹 Using CONCATENATION with CAST
🔹 If the data types differ, use CAST to avoid errors.
define view ZFLIGHT_CONCAT as select from sflight { key carrid, key connid, cast(fldate as abap.char(10)) || ' : ' || carrid as flight_schedule}✅ Ensures fldate (date) is treated as CHAR(10) before concatenation.
🔹 Using CONCATENATION in CASE WHEN
define view ZFLIGHT_CATEGORY as select from sflight { key carrid, key connid, case when price > 500 then 'Expensive: ' || carrid else 'Affordable: ' || carrid end as price_category}✅ Creates a dynamic label (Expensive: LH or Affordable: AA).
🔹 Key Benefits of CONCATENATION in CDS
✅ Combines fields dynamically for better readability. ✅ Useful in UI annotations (e.g., Fiori List Reports). ✅ Avoids performance overhead of joining text at runtime.