SAP examples · LessonReviewed by Anitha M, SAP Trainer, 13 yrs · Updated · Published · SAP S/4HANA 2023 · all levels
SAP HANA examples
These HANA examples show data modeling and SQL on the in-memory database, a calculation/CDS view and set-based SQL, illustrating the code-to-data approach.
Quick answer
Two HANA code-to-data examples: a CDS view entity over I_SalesOrderItem that sums NetAmount per SoldToParty with group by, and the equivalent set-based SQL with SUM, GROUP BY and ORDER BY. Both aggregate and filter in the database rather than pulling rows into ABAP and looping, which on HANA is dramatically faster. Layer views and push work down.
Key takeaways
- Watch out: an example that works on a hundred rows can be the statement that exhausts memory on a million.
- Worked examples: a cds view (application modeling), set-based sql (push logic down), what it teaches.
- How HANA examples fits into SAP development and the wider SAP landscape
A CDS view (application modeling)
define view entity Z_Sales_By_Cust as select from I_SalesOrderItem {
key SoldToParty,
sum( NetAmount ) as TotalNet
} group by SoldToPartySet-based SQL (push logic down)
SELECT sold_to, SUM(net_amount) AS total
FROM sales_items
GROUP BY sold_to
ORDER BY total DESC;What it teaches
The examples embody code-to-data: aggregate and filter in the database (via CDS or SQL) rather than pulling rows into ABAP and looping. On HANA this is dramatically faster. Layer views for reuse, and push filtering/aggregation as low as possible.
Common pitfalls
- Row-by-row processing instead of set-based SQL.
- Pulling data out to aggregate in ABAP.
- Monolithic views instead of layered/reusable.