User-defined functions are not supported in the SEARCHED CASE WHEN clause. What your are options?

If you worked on complex S/4HANA ABAP CDS views, you probably run into “User-defined functions are not supported in the SEARCHED CASE WHEN clause” error message. You can workaround this problem either splitting complex view into 2 more simple nested views or implementing AMDP table function. But what if you are too lazy to do that, then smart solution described in this blog is for you.

According to documentation, indeed user-defined functions are not supported in the SEARCHED CASE WHEN clause. Like in my example, LEFT and SUBSTRING functions are not supported. But the same documentation  provides you a solution as well – LIKE pattern comparisons.

All it takes in my case, is to think out the box and replace string functions with LIKE pattern comparisons