CASE Statement

Index

 

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

SQL_CASE_Var1_source

Output:

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.

Index

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s