"
Supported by

SELECT with CASE

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.

Um comentário a “SELECT with CASE”

  1. Ruthiel Trevisan Diz:

    EIIIII! Altamente!!!
    Não conhecia isto!!

Deixe um comentário


About Abapinho
Abapinho runs on WordPress
Articles (RSS) e Comments (RSS).