top of page
blank.png
Search
Writer's pictureSmart Logic Academy

ABAP tricks #29/100: 😀 COMMON TABLE EXPRESSIONS (CTE)

• CTE – Common Table Expression is one of the revolutionary concepts in ABAP SQL where it is very simple to push down multiple chained SQL queries into one and hit Database only once. 

• CTE is an extension of Open SQL and Subquery mechanism where multiple queries can be joined using the WITH keyword along with + and last part of Query works for result consolidation.

• ENDWITH is optional.

• Can be used to replace FOR ALL ENTRIES and sub-queries in the WHERE clause.


Example:


WITH +flight_from AS ( SELECT FROM spfli

  FIELDS carrid, connid, cityfrom

  WHERE cityfrom = 'FRANKFURT' )


SELECT DISTINCT sbook~carrid,

 sbook~connid,

  sbook~fldate

  FROM sbook

 I NNER JOIN +flight_from

  ON sbook~carrid = +flight_from~carrid AND

  sbook~connid = +flight_from~connid

 WHERE sbook~fldate EQ '20220916'

  INTO TABLE @DATA(lt_sbook_2).



Please share with your ABAP friends and follow us.

If you want to dive deeper, visit our course https://lnkd.in/d42HfjDh



13 views0 comments

Comments


bottom of page