In SAP ABAP CDS Views, you can use several string functions to manipulate and process string data. These functions allow you to perform common tasks like concatenation, trimming, substring extraction, and more.

Below are some common string functions you can use in CDS views:

1. CONCATENATE

The CONCATENATE function is used to combine two or more strings into one.

Example:

define view ZCONCATENATE_EXAMPLE as select from sflight {
key carrid,
key connid,
fldate,
price,
concat(carrid, connid) as flight_info
}

Explanation:

2. SUBSTRING

The substring function extracts a portion of a string, based on the starting position and length.

Example:

define view ZSUBSTRING_EXAMPLE as select from sflight {
key carrid,
key connid,
fldate,
price,
substring(carrid, 1, 2) as short_carrid
}

Explanation:

3. TRIM

The trim function removes leading and trailing spaces from a string.

Example:

define view ZTRIM_EXAMPLE as select from sflight {
key carrid,
key connid,
fldate,
price,
trim(carrid) as trimmed_carrid
}

Explanation:

4. UPPERCASE / LOWERCASE

The uppercase and lowercase functions are used to convert strings to uppercase or lowercase.

Example:

define view ZUPPERCASE_EXAMPLE as select from sflight {
key carrid,
key connid,
fldate,
price,
uppercase(carrid) as upper_carrid
}

Explanation:

Similarly, you can use lowercase() to convert the string to lowercase.

5. REPLACE

The replace function allows you to replace all occurrences of a substring within a string.

Example:

define view ZREPLACE_EXAMPLE as select from sflight {
key carrid,
key connid,
fldate,
price,
replace(carrid, 'LH', 'LU') as updated_carrid
}

Explanation:

6. LENGTH

The length function returns the length of a string (the number of characters).

Example:

define view ZLENGTH_EXAMPLE as select from sflight {
key carrid,
key connid,
fldate,
price,
length(carrid) as carrid_length
}

Explanation:

7. LEFT / RIGHT

The left and right functions extract a specified number of characters from the left or right side of a string.

Example:

define view ZLEFT_RIGHT_EXAMPLE as select from sflight {
key carrid,
key connid,
fldate,
price,
left(carrid, 3) as left_carrid,
right(carrid, 3) as right_carrid
}

Explanation:

8. CONTAINS

The contains function checks if a string contains a particular substring.

Example:

define view ZCONTAINS_EXAMPLE as select from sflight {
key carrid,
key connid,
fldate,
price,
contains(carrid, 'LH') as has_LH
}

Explanation:

9. POSITION

The position function returns the starting position of a substring within a string. It returns 0 if the substring is not found.

Example:

define view ZPOSITION_EXAMPLE as select from sflight {
key carrid,
key connid,
fldate,
price,
position(carrid, 'LH') as position_of_LH
}

Explanation:


Conclusion:

In SAP ABAP CDS Views, the following string functions are available to manipulate string data:

These functions are useful when you need to format or manipulate data directly within the CDS view before consuming it in your ABAP programs or reports.