Skip to content

Commit d810bd4

Browse files
authored
Merge pull request #72 from abap2UI5/claude/add-hana-cds-section-gYLIr
Split HANA, CDS, SQL into its own sidebar section and add ABAP SQL page
2 parents 17f3aaf + 55eac0a commit d810bd4

2 files changed

Lines changed: 124 additions & 3 deletions

File tree

docs/.vitepress/config.mjs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,21 @@ export default defineConfig({
234234
],
235235
},
236236
{
237-
text: "RAP, EML, HANA",
238-
link: "/development/specific/cds",
237+
text: "RAP, EML",
238+
link: "/development/specific/eml",
239239
collapsed: true,
240240
items: [
241-
{ text: "CDS", link: "/development/specific/cds" },
242241
{ text: "EML", link: "/development/specific/eml" },
243242
{ text: "Draft Handling", link: "/development/specific/draft" },
243+
],
244+
},
245+
{
246+
text: "HANA, CDS, SQL",
247+
link: "/development/specific/cds",
248+
collapsed: true,
249+
items: [
250+
{ text: "CDS", link: "/development/specific/cds" },
251+
{ text: "ABAP SQL", link: "/development/specific/abap_sql" },
244252
{ text: "Fuzzy Search", link: "/development/specific/fuzzy_search" },
245253
],
246254
},
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
outline: [2, 4]
3+
---
4+
# ABAP SQL
5+
6+
ABAP SQL is the standard way to read and change data in the database directly from ABAP. In an abap2UI5 controller you can issue `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and `MODIFY` statements the same way as in any ABAP program, and bind the result straight to a UI5 view.
7+
8+
### Read Data
9+
10+
The example below selects flights from the `sflight` table and shows them in a UI5 table:
11+
```abap
12+
CLASS z2ui5_cl_sample_sql DEFINITION PUBLIC.
13+
14+
PUBLIC SECTION.
15+
INTERFACES z2ui5_if_app.
16+
DATA mt_flights TYPE STANDARD TABLE OF sflight WITH EMPTY KEY.
17+
18+
ENDCLASS.
19+
20+
CLASS z2ui5_cl_sample_sql IMPLEMENTATION.
21+
METHOD z2ui5_if_app~main.
22+
23+
IF client->check_on_init( ).
24+
25+
SELECT FROM sflight
26+
FIELDS carrid, connid, fldate, price, currency
27+
ORDER BY carrid, connid, fldate
28+
INTO TABLE @mt_flights
29+
UP TO 50 ROWS.
30+
31+
DATA(view) = z2ui5_cl_xml_view=>factory( )->page( ).
32+
DATA(table) = view->table( client->_bind( mt_flights ) ).
33+
34+
table->columns(
35+
)->column( )->text( `Carrier` )->get_parent(
36+
)->column( )->text( `Connection` )->get_parent(
37+
)->column( )->text( `Date` )->get_parent(
38+
)->column( )->text( `Price` ).
39+
40+
table->items( )->column_list_item( )->cells(
41+
)->text( `{CARRID}`
42+
)->text( `{CONNID}`
43+
)->text( `{FLDATE}`
44+
)->text( `{PRICE} {CURRENCY}` ).
45+
46+
client->view_display( view->stringify( ) ).
47+
48+
ENDIF.
49+
50+
ENDMETHOD.
51+
ENDCLASS.
52+
```
53+
54+
### Filter with a Search Field
55+
56+
Bind the search term with `_bind_edit( )` and re-run the `SELECT` on every `SEARCH` event:
57+
```abap
58+
CASE abap_true.
59+
60+
WHEN client->check_on_init( ).
61+
load_data( ).
62+
render( ).
63+
64+
WHEN client->check_on_event( `SEARCH` ).
65+
load_data( ).
66+
client->view_model_update( ).
67+
68+
ENDCASE.
69+
```
70+
71+
```abap
72+
METHOD load_data.
73+
74+
SELECT FROM scarr
75+
FIELDS carrid, carrname, url
76+
WHERE @mv_search = ''
77+
OR carrname LIKE @( |%{ mv_search }%| )
78+
INTO TABLE @mt_carriers
79+
UP TO 100 ROWS.
80+
81+
ENDMETHOD.
82+
```
83+
84+
### Aggregations and Joins
85+
86+
Aggregations and joins work like in any ABAP report — the result table is then bound to the view:
87+
```abap
88+
SELECT FROM sflight AS f
89+
INNER JOIN scarr AS c ON c~carrid = f~carrid
90+
FIELDS f~carrid, c~carrname, SUM( f~seatsocc ) AS total_seats
91+
GROUP BY f~carrid, c~carrname
92+
ORDER BY total_seats DESCENDING
93+
INTO TABLE @DATA(lt_stats)
94+
UP TO 20 ROWS.
95+
```
96+
97+
### Change Data
98+
99+
`INSERT`, `UPDATE`, `DELETE`, and `MODIFY` are issued from event handlers — wrap them in a transaction and commit explicitly:
100+
```abap
101+
WHEN client->check_on_event( `SAVE` ).
102+
103+
MODIFY zorders FROM TABLE @mt_orders.
104+
IF sy-subrc = 0.
105+
COMMIT WORK.
106+
ELSE.
107+
ROLLBACK WORK.
108+
ENDIF.
109+
```
110+
111+
::: tip
112+
For data sourced from the Virtual Data Model, prefer reading from a [CDS view](./cds.md) instead of base tables — you get business semantics, associations, and authorization checks out of the box.
113+
:::

0 commit comments

Comments
 (0)