Supported by
Supported by Inetum

SELECT with CASE

images/thumbnail.jpg - Thumbnail

ABAP SQL is becoming more and more interesting and powerful. My latest discovery is the ability to use CASE in SELECT.

Here’s how it goes:

SELECT
  CASE
    WHEN temperature <= 5 THEN 'FREEZING'
    WHEN temperature <= 15 THEN 'COLD'
    WHEN temperature <= 25 THEN 'MILD'
    ELSE 'HOT'
  END AS weather
FROM zweather
WHERE date = sy-datum
INTO @DATA(weather_today).

It avoids unnecessary auxiliary code and makes things it simpler to read and understand.

Greetings from Abapinho.