Supported by
Supported by Inetum

CASE inside a SELECT (available soon)

images/thumbnail.jpg - Thumbnail

Get ready because you’ll soon be running into a lot of surprises. ABAP is learning new tricks. Look at this one:

CONSTANTS:
  lc_menina TYPE STRING VALUE GIRL',
  lc_menino TYPE STRING VALUE ‘BOY’,
  lc_senhor TYPE STRING VALUE ’GENTLEMAN’,
  lc_senhora TYPE STRING VALUE ‘LADY’.

SELECT nome,
 CASE
   WHEN sexo_id = ‘M' AND idade < 18 THEN @lc_menino
   WHEN sexo_id = F AND idade < 18 THEN @lc_menina
   WHEN sexo_id = M' AND idade >=18 THEN @lc_senhor
   WHEN sexo_id = F AND idade >=18 THEN @lc_senhora
 END AS titulo
FROM zpessoa
WHERE pessoa_id = @pessoa_id
INTO CORRESPONDING FIELDS OF @lt_pessoas.

You just have to wait for version 7.40.

Thank you Sérgio Fraga for the tip.

Greetings from Abapinho.