Skip to content
IT Canvass
SAP examples · Lesson

SQL examples

Quick answer

Write set-based SQL that filters (WHERE), joins and aggregates in the database, returning only what you need.

Key takeaways

  • Watch out: SELECT * / no WHERE, reading too much.
  • Worked examples: open sql in abap (modern syntax), joins and aggregation, what it teaches.
  • How SQL examples fits into SAP development and the wider SAP landscape

Open SQL in ABAP (modern syntax)

SELECT ebeln, SUM( netwr ) AS total
  FROM ekpo
  WHERE werks = @lv_plant
  GROUP BY ebeln
  INTO TABLE @DATA(lt_po_totals).

Joins and aggregation

SELECT k~ebeln, k~lifnr, SUM( p~netwr ) AS total
  FROM ekko AS k INNER JOIN ekpo AS p ON k~ebeln = p~ebeln
  WHERE k~bsart = 'NB'
  GROUP BY k~ebeln, k~lifnr
  INTO TABLE @DATA(lt).

What it teaches

Write set-based SQL that filters (WHERE), joins and aggregates in the database, returning only what you need. This is efficient on any database and essential on HANA (code-to-data). Avoid SELECT *, always use a WHERE, and never loop the database.

Common pitfalls

  • SELECT * / no WHERE, reading too much.
  • Aggregating in ABAP instead of SQL.
  • SELECT in a loop.

Want to learn this properly?

Our live, instructor-led SAP Training covers this hands-on, with real projects and a certification path.

Check your understanding

  1. Which statement is true of SQL examples?

    • A. This is efficient on any database and essential on HANA (code-to-data).
    • B. S/4HANA release notes cover the current-generation suite, which receives frequent feature releases (cloud)…
    • C. ERP, enterprise resource planning, is software that integrates the core processes of a business onto one…
    Show answer

    A. This is efficient on any database and essential on HANA (code-to-data).

    Covered in the “What it teaches” section of this lesson.

  2. Which of these also applies to SQL examples?

    • A. Using the wrong variant (e.g. create vs change vs display).
    • B. Guessing instead of using the reference tools.
    • C. Avoid SELECT *, always use a WHERE, and never loop the database.
    Show answer

    C. Avoid SELECT *, always use a WHERE, and never loop the database.

    Covered in the “What it teaches” section of this lesson.

  3. Which part of the Learn SAP curriculum covers SQL examples?

    • A. SAP downloads
    • B. SAP how-to guides
    • C. SAP examples
    Show answer

    C. SAP examples

    This lesson sits in the SAP examples section of the Learn SAP course.

Frequently asked questions

What does the term SQL examples refer to in SAP?

These SQL examples show querying SAP data effectively, whether Open SQL in ABAP or native HANA SQL, with an emphasis on efficient, set-based access.

What is worth remembering about SQL examples in practice?

Write set-based SQL that filters (WHERE), joins and aggregates in the database, returning only what you need.

What tends to go wrong with SQL examples?

SELECT * / no WHERE, reading too much. Aggregating in ABAP instead of SQL. SELECT in a loop.
CallWhatsAppEnquire