CASE Statement



ABAP HANA 7.51: CASE Statement

Newly introduced CASE statement comes as a longtime prayer of ABAPers heard by SAP. Case inside SELECT simplifies application logic and make code easy to understand. To name a few, some of the most important advantages of the CASE statement is as below:

  • No need to do a separate loop on Internal table generated by SQL query just for CASE-based filtering data fetched from the database.
  • This reduces overall effort and number of lines of code to be written
  • It is possible to Code push down a complex business logic to the database layer which practically makes execution faster on HANA database

CASE keyword works with WHEN, THEN and ELSE keywords and entire CASE statement have to be given an alias with AS.

Sample Source Code: CASE keyword in New Open SQL



The output of above SQL query will create Internal table LT_MARA with two fields viz. MATNR and MATERIAL_TYPE. The second column MATERIAL_TYPE is calculated by taking a CASE of Material Type available in Material Master and classify a Material into three categories.




Leave a Reply