Skip to content

Commit 6fbfbb5

Browse files
authored
Add files via upload
Week 2 upload
1 parent 97c6370 commit 6fbfbb5

File tree

7 files changed

+1634
-4
lines changed

7 files changed

+1634
-4
lines changed

week2/README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
# READme file for WEEK 2: DEVELOPING A READ-ONLY LIST REPORT APP
2-
In week 2, you are going to build a UI service for a read-only SAP Fiori elements-based Travel List Report app using the _managed_ implementation from scratch (i.e. greenfield implementation).
2+
In week 2, you are going to build a read-only SAP Fiori elements based Travel List Report app.
33

44
# HANDS-ON EXERCISES
5-
The information on the hands-on exercises for week 2 will be made available in a timely manner.
5+
Find the links to the different hands-on exercises below.
6+
7+
## Week 2 Unit 1: The Business Scenario
8+
There is no hands-on exercise provided for this unit, but you can watch the [corresponding video](https://open.sap.com/courses/cp13/items/2ZIu1QOORpyLl8PkiFOgJq) on openSAP.com.
9+
10+
## Week 2 Unit 2: Creating the Database Tables
11+
[Link to the hands-on exercise.](unit2.md)
12+
13+
## Week 2 Unit 3: Creating the Core Data Services (CDS) Data Model
14+
[Link to the hands-on exercise.](unit3.md)
15+
16+
## Week 2 Unit 4: Defining the CDS Data Model Projection
17+
[Link to the hands-on exercise.](unit4.md)
18+
19+
## Week 2 Unit 5: Enriching the Projected Data Model with UI Metadata
20+
[Link to the hands-on exercise.](unit5.md)
21+
22+
## Week 2 Unit 6: Creating and Previewing the OData UI Service
23+
[Link to the hands-on exercise.](unit6.md)
24+
25+
## Week 2 Unit 7: Implementing Basic Authorizations
26+
[Link to the hands-on exercise.](unit7.md)
27+
628

7-
## License
8-
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSES/Apache-2.0.txt) file.

week2/unit2.md

Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
# HANDS-ON EXERCISE FOR WEEK 2 UNIT 2: CREATING THE DATABASE TABLES
2+
3+
4+
## Introduction
5+
In this hands-on exercise, you will create the database for storing the travel and booking data and fill them with demo data.
6+
7+
You can watch [week 2 unit 2: Creating the Database Tables](https://open.sap.com/courses/cp13/items/2hlNxSdQ9JJZClJcxQOQb6) on the openSAP platform.
8+
9+
> **Hints and Tips**
10+
> Speed up the typing by making use of the Code Completion feature (shortcut *Ctrl+Space*) and the prepared code snippets provided.
11+
> You can easily open an object with the shortcut *Ctrl+Shift+A*, format your source code using the Pretty Printer feature *Ctrl+1* and toggle the fullscreen of the editor using the shortcut *Ctrl+M*.
12+
>
13+
> A great overview of ADT shortcuts can be found here: [Useful ADT Shortcuts](https://blogs.sap.com/2013/11/21/useful-keyboard-shortcuts-for-abap-in-eclipse/)
14+
>
15+
> Please note that the placeholder **`####`** used in object names in the exercise description must be replaced with the suffix of your choice during the exercises. The suffix can contain a maximum of 4 characters (numbers and letters).
16+
> The screenshots in this document have been taken with the suffix `1234` and system `D20`. Your system id will be `TRL`.
17+
18+
> Please note that the ADT dialogs and views may change in the future due to software updates.
19+
20+
Follow the instructions below.
21+
22+
## Step 1. Create the ABAP Package
23+
First create the new ABAP package **`ZRAP_TRAVEL_####`** (where `####` is your chosen suffix) to group the various development artefacts that you’re going to create during the greenfield implementation of our Travel App. It will be a sub-package of package **`ZRAP_####`** (where `####` is your chosen suffix) created in week 1 unit 6.
24+
25+
1. Go to the Project explorer, right-click on your package **`ZRAP_####`** (where `####` is your chosen suffix) you created in week 1 unit 6 and choose the context menu entry **_New > ABAP Package_**.
26+
27+
![Create ABAP Package](images/w2u2_01_01.png)
28+
29+
2. Maintain **`ZRAP_TRAVEL_####`** as name (where `####` is your chosen suffix) and a meaningful description (e.g. _**Greenfield Implementation - Travel List Report App**_) and choose **Next** to continue.
30+
The Project and the Superpackage fields are automatically assigned.
31+
32+
33+
![Create ABAP Package](images/w2u2_01_02.png)
34+
35+
36+
4. Select an existing transport request or create a new one and then choose **Finish** to create the new package.
37+
38+
39+
![Create ABAP Package](images/w2u2_01_03.png)
40+
41+
42+
The package is now created.
43+
44+
45+
![Create ABAP Package](images/w2u2_01_04.png)
46+
47+
5. Right-click on the new created package and choose **Add to Favorites Packages** to add it to your favorites.
48+
49+
50+
![Create ABAP Package](images/w2u2_01_05.png)
51+
52+
53+
## Step 2. Create the Travel Database Table
54+
You will now create the database table **`ZRAP_ATRAV_####`** (where `####` is your chosen suffix), to store the travel data.
55+
A Travel entity defines general travel data, such as the agency ID or customer ID, the status of the travel booking, and the price of travel.
56+
1. Right click on your package **`ZRAP_TRAVEL_####`**, choose **_New > Other ABAP Repository Object_** from the context menu.
57+
58+
59+
![Create Database Table](images/w2u2_02_01.png)
60+
61+
2. Enter `database` in the search field, choose **Database table** in the list and then choose **Next**.
62+
63+
64+
![Create Database Table](images/w2u2_02_02.png)
65+
66+
3. Maintain **`ZRAP_ATRAV_####`** as name and a meaningful description (e.g. _**Travel data**_) in the appearing dialog and choose **Next**.
67+
68+
69+
![Create Database Table](images/w2u2_02_03.png)
70+
71+
4. Assign a transport request and choose **Finish**.
72+
73+
74+
![Create Database Table](images/w2u2_02_04.png)
75+
76+
The table is created, and the default code displayed in the new editor.
77+
The default table-specific technical settings are specified using annotations at the top.
78+
79+
80+
![Create Database Table](images/w2u2_02_05.png)
81+
82+
5. Replace the default source code with the code snippet provided below and replace all occurrences of `####` with your chosen suffix.
83+
You can make use of the Replace All feature (**Ctrl+F**) in ADT for the purpose.
84+
85+
<pre>
86+
@EndUserText.label : 'Travel data'
87+
@AbapCatalog.enhancementCategory : #NOT_EXTENSIBLE
88+
@AbapCatalog.tableCategory : #TRANSPARENT
89+
@AbapCatalog.deliveryClass : #C
90+
@AbapCatalog.dataMaintenance : #RESTRICTED
91+
define table zrap_atrav_#### {
92+
key client : mandt not null;
93+
key travel_uuid : sysuuid_x16 not null;
94+
travel_id : /dmo/travel_id;
95+
agency_id : /dmo/agency_id;
96+
customer_id : /dmo/customer_id;
97+
begin_date : /dmo/begin_date;
98+
end_date : /dmo/end_date;
99+
@Semantics.amount.currencyCode : 'zrap_atrav_####.currency_code'
100+
booking_fee : /dmo/booking_fee;
101+
@Semantics.amount.currencyCode : 'zrap_atrav_####.currency_code'
102+
total_price : /dmo/total_price;
103+
currency_code : /dmo/currency_code;
104+
description : /dmo/description;
105+
overall_status : /dmo/overall_status;
106+
created_by : syuname;
107+
created_at : timestampl;
108+
last_changed_by : syuname;
109+
last_changed_at : timestampl;
110+
local_last_changed_at : timestampl;
111+
}
112+
</pre>
113+
114+
115+
![Create Database Table](images/w2u2_02_06.png)
116+
117+
118+
**Short explanations:**
119+
- Some data elements from the ABAP Flight Reference Scenario (namespace `/DMO/`) are used.
120+
- The table key consists of the `CLIENT` field and the `TRAVEL_UUID` field which is a technical key (16 Byte UUID).
121+
- A human-readable travel identifier: `TRAVEL_ID`
122+
- The field CURRENCY_CODE is specified as currency key for the amount fields `BOOKING_FEE` and `TOTAL_PRICE` using the semantic annotation `@Semantics.amount.currencyCode`
123+
- Some standard administrative fields are defined: `CREATED_BY`, `CREATED_AT`, `LAST_CHANGED_BY`, `LAST_CHANGED_AT` and `LOCAL_LAST_CHANGED_AT`.
124+
125+
6. Save ![save icon](images/adt_save.png) and activate ![activate icon](images/adt_activate.png) the changes.
126+
127+
7. Press **F8** to start the data preview.
128+
Well, the database table is empty for now, so no data is displayed.
129+
130+
131+
![Create Database Table](images/w2u2_02_07.png)
132+
133+
## Step 3. Create the Booking Database Table
134+
You will now create the database table **`ZRAP_ABOOK_####`** (where `####` is your chosen suffix), to store the booking data.
135+
A Booking entity comprises general flight and booking data, the customer ID for whom the flight is booked as well as the travel ID to which the booking belongs – and some admin fields.
136+
137+
1. Right click on the **Database Tables** folder, choose **New Database Table** from the context menu.
138+
139+
![Create Database Table](images/w2u2_03_01.png)
140+
141+
3. Maintain **`ZRAP_ABOOK_####`** as name and a meaningful description (e.g. _**Booking data**_) in the appearing dialog and choose **Next**.
142+
143+
![Create Database Table](images/w2u2_03_02.png)
144+
145+
4. Assign a transport request and choose **Finish**.
146+
147+
![Create Database Table](images/w2u2_03_03.png)
148+
149+
The table is created, and the default code displayed in the new editor.
150+
The default table-specific technical settings are specified using annotations at the top – before the **`DEFINE TABLE`** statement.
151+
152+
![Create Database Table](images/w2u2_03_04.png)
153+
154+
5. Replace the default source code with the code snippet provided below and replace all occurrences of `####` with your chosen suffix.
155+
You can make use of the Replace All feature (shortcut **Ctrl+F**) in ADT for the purpose.
156+
157+
<pre>
158+
@EndUserText.label : 'Booking data'
159+
@AbapCatalog.enhancementCategory : #NOT_EXTENSIBLE
160+
@AbapCatalog.tableCategory : #TRANSPARENT
161+
@AbapCatalog.deliveryClass : #C
162+
@AbapCatalog.dataMaintenance : #RESTRICTED
163+
define table zrap_abook_#### {
164+
key client : mandt not null;
165+
key booking_uuid : sysuuid_x16 not null;
166+
travel_uuid : sysuuid_x16 not null;
167+
booking_id : /dmo/booking_id;
168+
booking_date : /dmo/booking_date;
169+
customer_id : /dmo/customer_id;
170+
carrier_id : /dmo/carrier_id;
171+
connection_id : /dmo/connection_id;
172+
flight_date : /dmo/flight_date;
173+
@Semantics.amount.currencyCode : 'zrap_abook_####.currency_code'
174+
flight_price : /dmo/flight_price;
175+
currency_code : /dmo/currency_code;
176+
created_by : syuname;
177+
last_changed_by : syuname;
178+
local_last_changed_at : timestampl;
179+
}
180+
</pre>
181+
182+
![Create Database Table](images/w2u2_03_05.png)
183+
184+
**Short explanations:**
185+
- Some data elements from the ABAP Flight Reference Scenario (namespace /DMO/) are used.
186+
- The table key consists of the `CLIENT` field and the `BOOKING_UUID` field which is a technical key (16 Byte UUID).
187+
- A human-readable travel identifier: `BOOKING_ID`
188+
- The field CURRENCY_CODE is specified as currency key for the amount field FLIGHT_PRICE using the semantic annotation `@Semantics.amount.currencyCode`.
189+
- Some standard administrative fields are defined: `CREATED_BY`, `LAST_CHANGED_BY`, and `LOCAL_LAST_CHANGED_AT`.
190+
191+
6. Save ![save icon](images/adt_save.png) and activate ![activate icon](images/adt_activate.png) the changes.
192+
193+
7. Press **F8** to start the data preview.
194+
Well, the database table is empty for now, so no data is displayed.
195+
196+
197+
![Create Database Table](images/w2u2_03_06.png)
198+
199+
## Step 4. Fill in the Database Tables with Demo Data
200+
You will now fill in the created travel and booking database tables with some demo data to ease the test. Demo data provided by the ABAP Flight Reference Scenario (main package: `/DMO/FLIGHT`) will be used for the purpose.
201+
202+
1. Right click on your package **_ZRAP_TRAVEL_####** and choose **_New > ABAP Class_** from the context menu.
203+
204+
![Generate Demo Data](images/w2u2_04_01.png)
205+
206+
2. Maintain **`ZCL_GENERATE_DEMO_DATA_####`** as name and a meaningful description (e.g. _**Generate Travel and Booking demo data**_) in the creation wizard for the new ABAP class.
207+
Add the ABAP interface **`IF_OO_ADT_CLASSRUN`** which needs to be implemented to write outputs to the ABAP Console and continue with **Next**.
208+
209+
![Generate Demo Data](images/w2u2_04_02.png)
210+
211+
3. Assign a transport request and choose **Finish**.
212+
213+
![Generate Demo Data](images/w2u2_04_03.png)
214+
215+
The ABAP class is created and opened in the source-based class editor area, ready for you to implement.
216+
217+
4. Insert the implementation of method **`if_oo_adt_classrun~main`** with the code snippet provided below (after **CLASS zcl_generate_demo_data_#### IMPLEMENTATION.** and before **ENDCLASS.**) as shown on the screenshot below, and replace all occurrences of `####` with your chosen suffix.
218+
You can make use of the Replace All feature (**Ctrl+F**) in ADT for the purpose.
219+
220+
<pre>
221+
METHOD if_oo_adt_classrun~main.
222+
223+
" delete existing entries in the database table
224+
DELETE FROM zrap_atrav_####.
225+
DELETE FROM zrap_abook_####.
226+
227+
" insert travel demo data
228+
INSERT zrap_atrav_#### FROM (
229+
SELECT
230+
FROM /dmo/travel
231+
FIELDS
232+
uuid( ) AS travel_uuid ,
233+
travel_id AS travel_id ,
234+
agency_id AS agency_id ,
235+
customer_id AS customer_id ,
236+
begin_date AS begin_date ,
237+
end_date AS end_date ,
238+
booking_fee AS booking_fee ,
239+
total_price AS total_price ,
240+
currency_code AS currency_code ,
241+
description AS description ,
242+
CASE status
243+
WHEN 'B' THEN 'A' " accepted
244+
WHEN 'X' THEN 'X' " cancelled
245+
ELSE 'O' " open
246+
END AS overall_status ,
247+
createdby AS created_by ,
248+
createdat AS created_at ,
249+
lastchangedby AS last_changed_by ,
250+
lastchangedat AS last_changed_at ,
251+
lastchangedat AS local_last_changed_at
252+
ORDER BY travel_id UP TO 200 ROWS
253+
).
254+
COMMIT WORK.
255+
256+
" insert booking demo data
257+
INSERT zrap_abook_#### FROM (
258+
SELECT
259+
FROM /dmo/booking AS booking
260+
JOIN zrap_atrav_#### AS z
261+
ON booking~travel_id = z~travel_id
262+
FIELDS
263+
uuid( ) AS booking_uuid ,
264+
z~travel_uuid AS travel_uuid ,
265+
booking~booking_id AS booking_id ,
266+
booking~booking_date AS booking_date ,
267+
booking~customer_id AS customer_id ,
268+
booking~carrier_id AS carrier_id ,
269+
booking~connection_id AS connection_id ,
270+
booking~flight_date AS flight_date ,
271+
booking~flight_price AS flight_price ,
272+
booking~currency_code AS currency_code ,
273+
z~created_by AS created_by ,
274+
z~last_changed_by AS last_changed_by ,
275+
z~last_changed_at AS local_last_changed_by
276+
).
277+
COMMIT WORK.
278+
279+
out->write( 'Travel and booking demo data inserted.').
280+
ENDMETHOD.
281+
</pre>
282+
283+
![Generate Demo Data](images/w2u2_04_04.png)
284+
285+
**Short explanations:**
286+
- First, any existing entries in both database tables are deleted.
287+
- Then the data is selected from the tables `/DMO/TRAVEL` and `/DMO/BOOKING` and inserted into your tables `ZRAP_ATRAV_####` and `ZRAP_ABOOK_####` respectively.
288+
- The SQL function `UUID( )` is used to set the value of the key fields `TRAVEL_UUID` and `BOOKING_UUID`.
289+
- The `COMMIT WORK` statement is then executed to persist the data. The data selection has been limited to up to 200 travel records, but you can change this if desired.
290+
- A success message is written to the Console at the end.
291+
292+
5. Save ![save icon](images/adt_save.png) and activate ![activate icon](images/adt_activate.png) the changes.
293+
294+
6. Press **F9** to run the ABAP class as a console application to generate the demo data and and fill your tables.
295+
296+
![Generate Demo Data](images/w2u2_04_05.png)
297+
298+
7. Now you can preview the data from the Travel and Booking database tables.
299+
Choose the relevant database table (`ZRAP_ATRAV_####` or `ZRAP_ABOOK_####` where #### is your chosen suffix) in the Project Explorer and press **F8**.
300+
301+
The Data Preview will open in the editor area.
302+
You can play around with the data preview - e.g. choose the **Number of Entries** or **SQL Console**, or filter the entries with **Add filter**.
303+
304+
![Generate Demo Data](images/w2u2_04_06.png)
305+
306+
## Summary
307+
You have completed the exercise!
308+
In this unit, you have learned how to use the ABAP Development Tools (ADT) to create database tables for your demo Travel app.
309+
310+
## Solution
311+
Find the source code for the created database tables and class in the **[/week2/sources](/week2/sources)** folder:
312+
- [W2U2_TABL_ZRAP_ATRAV_####](/week2/sources/W2U2_TABL_ZRAP_ATRAV.txt)
313+
- [W2U2_TABL_ZRAP_ABOOK_####](/week2/sources/W2U2_TABL_ZRAP_ABOOK.txt)
314+
- [W2U2_CLAS_ZCL_GENERATE_DEMO_DATA_####](/week2/sources/W2U2_CLAS_ZCL_GENERATE_DEMO_DATA.txt)
315+
316+
Do not forget to replace all the occurrences of `####` with your chosen suffix in the copied source code.
317+
318+
## Next exercise
319+
[Week 2 Unit 3: Creating the Core Data Services (CDS) Data Model](unit3.md)

0 commit comments

Comments
 (0)