• 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
Comments