Sap La S4D430 en 24 Ex
Sap La S4D430 en 24 Ex
.
.
EXERCISES AND SOLUTIONS
.
Course Version: 24
Exercise Duration: 7 Hours 30 Minutes
Material Number: 50165753
SAP Copyrights, Trademarks and
Disclaimers
No part of this publication may be reproduced or transmitted in any form or for any purpose without the
express permission of SAP SE or an SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their respective logos are
trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other
countries. Please see https://www.sap.com/corporate/en/legal/copyright.html for additional
trademark information and notices.
Some software products marketed by SAP SE and its distributors contain proprietary software
components of other software vendors.
National product specifications may vary.
These materials may have been machine translated and may contain grammatical errors or
inaccuracies.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only,
without representation or warranty of any kind, and SAP SE or its affiliated companies shall not be liable
for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate
company products and services are those that are set forth in the express warranty statements
accompanying such products and services, if any. Nothing herein should be construed as constituting an
additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business
outlined in this document or any related presentation, or to develop or release any functionality
mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’
strategy and possible future developments, products, and/or platform directions and functionality are
all subject to change and may be changed by SAP SE or its affiliated companies at any time for any
reason without notice. The information in this document is not a commitment, promise, or legal
obligation to deliver any material, code, or functionality. All forward-looking statements are subject to
various risks and uncertainties that could cause actual results to differ materially from expectations.
Readers are cautioned not to place undue reliance on these forward-looking statements, which speak
only as of their dates, and they should not be relied upon in making purchasing decisions.
Demonstration
Procedure
Warning or Caution
Hint
Facilitated Discussion
Unit 7: Defining Meta Objects for Dictionary Objects and CDS Views
You want to learn how to define objects in ABAP Dictionary and ABAP Core Data Services. In
the first step, you prepare the ABAP development environment, create a new package, and
analyze some existing objects.
1. Open Eclipse, switch to the ABAP perspective and create an ABAP Cloud Project.
3. In your ABAP Cloud project, create a new package with the attributes listed in the table.
When prompted for a transport, choose the transport request in which you are involved. If
no transport request is listed, create a new request.
Field Value
Name ZS4D430_##, where ## is your group
number
Description Modeling in ABAP
Note:
Package /LRN/S4D430_INTRO is a subpackage of package /LNR/
S4D430_EXERCISE.
Which types of development objects do you find in the Core Data Services node?
Do any of the objects under Core Data Services have identical names?
1. In your package, create a new ABAP class (suggested name: ZCL_##_INTRO, where ##
stands for your group number).
3. Replace type string with an object from package /LRN/S4D430_INTRO. Use code-
completion to find out which of the objects you can use as data types.
Note:
All objects in package /LRN/S4D430_INTRO have a name that starts
with /LRN/S4D430_IND.
How does this relate to the fact that the dictionary objects have different names?
Which CDS objects from package /LRN/S4D430_IND are offered as data types?
How does this relate to the fact that the CDS objects in this package have identical
names?
Hint:
To keep it simple, read all fields (FIELDS *), all rows (no WHERE clause), and
use an inline declaration in the INTO TABLE clause.
5. Replace /lrn/S4D430_ind in the FROM clause with another object from package /LRN/
S4D430_INTRO. Use code-completion to find out which of the objects you can use as data
source.
Note:
All objects in the /LRN/S4D430_INTRO package have a name that starts
with /LRN/S4D430_IND.
Which dictionary object(s) from the /LRN/S4D430_INTRO package are offered as data
sources in ABAP SQL?
You want to learn how to define objects in ABAP Dictionary and ABAP Core Data Services. In
the first step, you prepare the ABAP development environment, create a new package, and
analyze some existing objects.
1. Open Eclipse, switch to the ABAP perspective and create an ABAP Cloud Project.
a) Open Eclipse and close all tabs.
f) Choose Import and select the file containing the service key that you have been given.
i) When you see the message, You have been successfully logged on, close the browser
window and return to Eclipse.
d) From the list of matching items, select /LRN/S4D430_EXERCISE, then choose OK.
3. In your ABAP Cloud project, create a new package with the attributes listed in the table.
When prompted for a transport, choose the transport request in which you are involved. If
no transport request is listed, create a new request.
Field Value
Name ZS4D430_##, where ## is your group
number
Description Modeling in ABAP
a) In the Project Explorer, right-click on your ABAP Cloud Project and choose New →
ABAP Package .
g) Choose Next.
k) Choose Next.
l) Check if there is a transport request listed under option Choose from requests in which
I am involved. If this is the case, choose this option. If the list is empty, choose the
option Create a new request and enter a request description, for example ABAP
Exercises.
m) Choose Finish.
Note:
Package /LRN/S4D430_INTRO is a subpackage of package /LNR/
S4D430_EXERCISE.
Data Elements, Database Tables, Domains, Structure Types, and Table Types.
Which types of development objects do you find in the Core Data Services node?
Do any of the objects under Core Data Services have identical names?
1. In your package, create a new ABAP class (suggested name: ZCL_##_INTRO, where ##
stands for your group number).
a) In the Project Explorer view, right-click your package Z##_S4D430 to open the context
menu.
c) Confirm that the Package field contains the name of your package. Enter the name of
the new class in the Name field and Analyze dictionary and CDS in the
Description field.
d) Choose Add....
METHOD if_oo_adt_classrun~main.
ENDMETHOD.
3. Replace type string with an object from package /LRN/S4D430_INTRO. Use code-
completion to find out which of the objects you can use as data types.
Note:
All objects in package /LRN/S4D430_INTRO have a name that starts
with /LRN/S4D430_IND.
a) Remove string.
All dictionary objects are available as data types except for the domain /LRN/
S4D430_IND_DOMAIN. Domains are not supported as ABAP data types.
How does this relate to the fact that the dictionary objects have different names?
Dictionary objects that are available as data types need to be distinguishable from each
other. Therefore it is not possible that data elements, structures, table types, and
database tables have identical names.
Which CDS objects from package /LRN/S4D430_IND are offered as data types?
Only CDS view entity /LRN/S4D430_IND_CDS_VIEW. All other CDS objects are not
supported as ABAP data types.
How does this relate to the fact that the CDS objects in this package have identical
names?
Identical names are allowed because the CDS objects are not used in the same places. In
particular, access controls, behavior definitions, and metadata extensions are not used as
data types.
Hint:
To keep it simple, read all fields (FIELDS *), all rows (no WHERE clause), and
use an inline declaration in the INTO TABLE clause.
5. Replace /lrn/S4D430_ind in the FROM clause with another object from package /LRN/
S4D430_INTRO. Use code-completion to find out which of the objects you can use as data
source.
Note:
All objects in the /LRN/S4D430_INTRO package have a name that starts
with /LRN/S4D430_IND.
Which dictionary object(s) from the /LRN/S4D430_INTRO package are offered as data
sources in ABAP SQL?
Only database tables, dictionary views (deprecated), and CDS entities are supported as
data sources. The only CDS entity in package /LRN/S4D430_INTRO is CDS view
entity /LRN/S4D430_IND_CDS_View.
You want to create your own data model. In this exercise, you start by defining domains and
data elements for employee numbers and annual salary data.
Template:
n.a.
Solution:
/LRN/AMOUNT (Domain)
/LRN/EMPLOYEE_ID (Domain)
/LRN/ANNUAL_SALARY (Data Element)
/LRN/EMPLOYEE_ID (Data Elements)
2. Set the data type of the domain to CURR with a length of 15 and 2 decimals.
2. Use forward navigation to create a new domain for this data element. Use the same name
as for the data element.
5. Maintain the field labels for data element Z##_EMPLOYEE_ID and activate the data
element.
You want to create your own data model. In this exercise, you start by defining domains and
data elements for employee numbers and annual salary data.
Template:
n.a.
Solution:
/LRN/AMOUNT (Domain)
/LRN/EMPLOYEE_ID (Domain)
/LRN/ANNUAL_SALARY (Data Element)
/LRN/EMPLOYEE_ID (Data Elements)
c) On the dialog window that displays, enter doma in the search field.
e) Confirm the package, enter the name Z##_AMOUNT and the description Amount, and
choose Next.
2. Set the data type of the domain to CURR with a length of 15 and 2 decimals.
a) Place the cursor in the Data Type field and press Ctrl + Space.
c) Confirm the package, enter the name Z##_ANNUAL_SALARY, the description Annual
Salary, and choose Next.
b) Under Type Name, enter Z##, where ## is your group number, and press Ctrl +
Space.
Field Value
Short Salary
Medium Annual salary
Long Annual salary
Heading Annual salary
c) Confirm the package, enter the name Z##_EMPLOYEE_ID, the description Employee
Number, and choose Next.
2. Use forward navigation to create a new domain for this data element. Use the same name
as for the data element.
a) In the Category field, keep the suggested value Domain.
e) On the dialog window, enter your package, confirm the name of the domain, and enter
a description ( suggest value: Employee Number) . Then choose Next.
5. Maintain the field labels for data element Z##_EMPLOYEE_ID and activate the data
element.
a) In section Field Labels, enter the following data:
Field Value
Short Employee
Medium Employee No.
Long Employee Number
Heading Employee Number
You want to create your own data model. In this exercise, you define a database table for
employee data.
Template:
n.a.
Solution:
Hint:
If you have not completed the previous exercise, you can use data
elements /LRN/EMPLOYEE_ID and /LRN/ANNUAL_SALARY instead of your own
data elements.
1. Create a new development object of type Database Table (suggested name: Z##EMPLOY).
2. After the client field, add a second key field employee_id, and type it with the your data
element Z##_EMPLOYEE_ID. Use code completion to insert the name of the data element.
Note:
If you have not completed the previous exercise, use data element /LRN/
EMPLOYEE_ID, instead.
3. Add the following non-key fields. Use code completion to insert the names of the existing
data elements.
Field Name Data Element
first_name /DMO/FIRST_NAME
last_name /DMO/LAST_NAME
4. Add the following fields and use a quick fix to create the new data elements:
Field Name Data Element
birth_date Z##_BIRTH_DATE
entry_date Z##_ENTRY_DATE
For both data elements, use existing domain /DMO/DATE as data type.
5. Add the following amount and currency code fields, and use a quick fix to add the
@Semantics.amount.currencyCode: annotation for the reference to the currency code
field.
Field Name Data Element
annual_salary Z##_ANNUAL_SALARY
currency_code WAERS
6. Maintain the technical table settings. Use the value help to choose appropriate values for
the data class and the size category.
Note:
We expect the table to contain between 50 thousand and 60 thousand data
sets.
7. Activate the technical table settings and the database table definition.
Hint:
The administrative fields in this structure play an important role in the ABAP
RESTful application programming model. See the corresponding unit of the Basic
ABAP Programming course for more information.
2. Analyze the component list of the structure and the referenced data types.
3. Edit the field list in database table definition Z##_EMPLOYEE. Use code completion to
include structure /LRN/S_ADMIN at the end of the field list.
4. Display the Code Element Info for your database table and analyze the field list.
2. Change the value of the c_employ_table constant to the name of your database table.
3. Activate the ABAP class and execute it as a console app. If the console output contains
errors, adjust the definition of your database table until it is compatible with database
table definition /LRN/EMPLOY.
You want to create your own data model. In this exercise, you define a database table for
employee data.
Template:
n.a.
Solution:
Hint:
If you have not completed the previous exercise, you can use data
elements /LRN/EMPLOYEE_ID and /LRN/ANNUAL_SALARY instead of your own
data elements.
1. Create a new development object of type Database Table (suggested name: Z##EMPLOY).
a) In the Project Explorer, expand your package and open the context menu on subnode
Dictionary.
c) Confirm the package, enter the name Z##EMPLOY and the description Employee, then
choose Next.
e) The code of the database table definition should look like this:
@EndUserText.label : 'Employee'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table z##employ {
2. After the client field, add a second key field employee_id, and type it with the your data
element Z##_EMPLOYEE_ID. Use code completion to insert the name of the data element.
Note:
If you have not completed the previous exercise, use data element /LRN/
EMPLOYEE_ID, instead.
3. Add the following non-key fields. Use code completion to insert the names of the existing
data elements.
Field Name Data Element
first_name /DMO/FIRST_NAME
last_name /DMO/LAST_NAME
4. Add the following fields and use a quick fix to create the new data elements:
entry_date Z##_ENTRY_DATE
For both data elements, use existing domain /DMO/DATE as data type.
a) At the end of the element list, add birth_date : z##_birth_date; (with ## being
your group number).
b) Open the Problems view. You should see an error Field BIRTH_DATE: Component type
or domain used not active or does not exist.
c) place the cursor onz##_birth_date, and press Ctrl + 1 to open the quick fix
menu.
d) From the quick fix menu, double-click Create data element ....
e) Confirm the package and the name, enter a description, for example, Date of
birth, and choose Next.
g) Under Type Name, enter /DMO/DATE and enter the following field labels:
Field Value
Short Born
Medium Born on
Long Date of Birth
Heading Date of Birth
h) Activate the new data element and return to database table Z##EMPLOY.
i) In a new code line, addentry_date : z##_entry_date; and use the quick fix again
to create data element Z##_ENTRY_DATE using the same domain, but with the
following field labels:
Field Value
Short Entry date
Medium Company entry date
Long Works for the company since
Heading Works for the company since
5. Add the following amount and currency code fields, and use a quick fix to add the
@Semantics.amount.currencyCode: annotation for the reference to the currency code
field.
currency_code WAERS
b) Place the cursor over the error icon next to annual_salary to see error message
Annotation with reference to currency code for field ANNUAL_SALARY is missing.
6. Maintain the technical table settings. Use the value help to choose appropriate values for
the data class and the size category.
Note:
We expect the table to contain between 50 thousand and 60 thousand data
sets.
a) Right-click anywhere in the editor and choose Open Others → Technical Settings.
b) Place the cursor at the beginning of the Data Class field and press Ctrl + Space to
display the value help.
d) Repeat with the Size Category field and choose 3 Expected records 43.000 - 170.000.
7. Activate the technical table settings and the database table definition.
a) While still on the Technical Table Setttings dialog, press Ctrl + F3 to activate the
technical table settings.
b) Return to the editor with the source code of the database table definition and press
Ctrl + F3 to activate the database table definition.
Hint:
The administrative fields in this structure play an important role in the ABAP
RESTful application programming model. See the corresponding unit of the Basic
ABAP Programming course for more information.
2. Analyze the component list of the structure and the referenced data types.
The two components ending with _BY are of type CHAR(12). The other three components
are of type DEC(21,7).
a) In the row starting with define structure, place the cursor on /lrn/s_admin and
press F2 to display the Code Element Information.
3. Edit the field list in database table definition Z##_EMPLOYEE. Use code completion to
include structure /LRN/S_ADMIN at the end of the field list.
a) Before the closing curly bracket, enter in and press Ctrl + Space to invoke code
completion.
currency_code : waers;
include /lrn/s_admin;
}
4. Display the Code Element Info for your database table and analyze the field list.
a) In the code row starting with define table, place the cursor in the table name and
press F2.
b) Confirm that the five components of structure /LRN/S_ADMIN are now fields of your
database table.
c) Enter the name of your package, the name for the copy and a description. Then choose
Next.
2. Change the value of the c_employ_table constant to the name of your database table.
a) Scroll down to the code row starting with CONSTANTS c_employ_table.
3. Activate the ABAP class and execute it as a console app. If the console output contains
errors, adjust the definition of your database table until it is compatible with database
table definition /LRN/EMPLOY.
a) Press Ctrl + F3 to activate the development object.
c) Make sure the console output contains the text Filled table ... for your database table.
You need to make changes to the field list of a database table that already contains data.
Depending on the nature of the change, the system request you to adjust the table.
Template:
Solution:
1. Copy database table definition /LRN/EMPLOY to your own package (suggested name:
Z##EMPLOY, where ## stands for your group number).
1. Before theANNUAL_SALARY field, add a new field (suggested name: DEPARTMENT_ID) and
type it with built in type CHAR and length 40.
7. Use the quick fix to convert the content of your database table.
2. Save the data element. Then use forward navigation to create the domain with technical
type CHAR and a length of 20.
3. Save the domain. Then activate the domain, the data element, and the database table
definition.
4. In your domain for the department ID, reduce the technical length and the display length
from 20 to 10.
5. Try to activate the domain and analyze the messages on the Problems view.
6. Use the quick fix for the error message Domain ... cannot be activated due to dependent
tables.
7. Use a quick fix to adjust and convert the dependent database table, that is, your database
table Z##EMPLOY.
You need to make changes to the field list of a database table that already contains data.
Depending on the nature of the change, the system request you to adjust the table.
Template:
Solution:
1. Copy database table definition /LRN/EMPLOY to your own package (suggested name:
Z##EMPLOY, where ## stands for your group number).
a) In the Project Explorer view, right-click database table definition /LRN/EMPLOY to open
the context menu.
c) Enter the name of your package in the Package field. In the Name field, enter the name
Z##EMPLOY, where ## stands for your group number.
1. Before theANNUAL_SALARY field, add a new field (suggested name: DEPARTMENT_ID) and
type it with built in type CHAR and length 40.
a) Adjust the code as follows:
birth_date : z##birth_date;
entry_date : z##entry_date;
department_id : abap.char(40);
@Semantics.amount.currencyCode : 'z##employ.currency_code'
annual_salary : z##annual_salary;
currency_code : waers;
a) Right-click anywhere in the source code and choose Open With → Dictionary Log.
b) Navigate to the Dictionary Log tab that appears below the editor.
c) Hold down the Ctrl key and click on the row starting with See log.
d) From the toolbar on the Dictionary Log tab, choose Show Search Toolbar.
e) Enter the name of your database table in the Find: field and press Enter.
f) The update strategy is mentioned after the row Adjust table in DB >>>.
birth_date : z##birth_date;
entry_date : z##entry_date;
department_id : abap.char(20);
@Semantics.amount.currencyCode : 'z##employ.currency_code'
annual_salary : z##annual_salary;
currency_code : waers;
The dictionary tool is not able to handle the field length reduction with ALTER TABLE. An
explicit conversion of the database table is required.
b) On the Dictionary Log tab, hold down the Ctrl key and click on the row starting with
See log.
c) From the toolbar on the Dictionary Log tab, choose Show Search Toolbar.
d) Enter the name of your database table in the Find: field and press Enter.
e) The update strategy is mentioned after the row Adjust table in DB >>>.
7. Use the quick fix to convert the content of your database table.
a) Navigate to the source code of your database table definition.
b) In the code row that starts with define table, place the cursor on the table name
and press Ctrl + 1 to invoke the quick fix.
c) From the list of available quick fixes, choose Adjust and activate database table,
convert data.
birth_date : z##_birth_date;
entry_date : z##_entry_date;
department_id : z##_department_id;
@Semantics.amount.currencyCode : 'z##employ_dep.currency_code'
annual_salary : z##_annual_salary;
currency_code : waers;
b) Click on z##_department_id, and press Ctrl + 1 to open the quick fix menu.
c) From the quick fix menu, double-click Create data element ....
d) Confirm the package and the name, enter a description, for example, Department
Identification, and choose Next.
f) Under Type Name, enter Z##_DEPARTMENT_ID and enter the following field labels:
Field Value
Short Dep.
Medium Department
Long Department ID
Heading Department ID
2. Save the data element. Then use forward navigation to create the domain with technical
type CHAR and a length of 20.
a) Press Ctrl + S to save the data element.
c) Confirm the package and the name, enter a description, for example, Department
Identification, and choose Next.
3. Save the domain. Then activate the domain, the data element, and the database table
definition.
a) Press Ctrl + S to save the domain.
4. In your domain for the department ID, reduce the technical length and the display length
from 20 to 10.
a) Navigate to your domain Z##_DEPARTMENT_ID.
c) Remove the value in the Output Length field (this will be filled automatically during
activation).
5. Try to activate the domain and analyze the messages on the Problems view.
The domain cannot be activated due to dependent tables and the table must be
converted.
b) Open the Problems view below the editor to display the error messages.
6. Use the quick fix for the error message Domain ... cannot be activated due to dependent
tables.
It is not possible to adjust the dependent table with ALTER TABLE. A conversion of the
table content is required.
a) In the Problems view, place the cursor on the error message that starts with Domain ...
and press Ctrl + 1 to invoke the quick fix.
b) Choose Finish.
c) From the Previous Result section on the lower right, choose Activation Log to analyze
the activation log.
7. Use a quick fix to adjust and convert the dependent database table, that is, your database
table Z##EMPLOY.
a) Navigate to the source code of your database table definition.
b) In the code row that starts with define table, place the cursor on the table name
and press Ctrl + 1 to invoke the quick fix.
c) From the list of available quick fixes, choose Adjust and activate database table,
convert data.
You need some structure types that you can access in several global classes. You decide to
define structure types in the ABAP Dictionary.
Hint:
Before you define structure types in the ABAP Dictionary, you should investigate
the option to define public structure types in one of the global classes or in a
global interface.
Template:
Solution:
2. In the PUBLIC SECTION of the class definition, analyze the definition of type st_address.
5. Add components for the postal code, the city, and the country. Use the same component
names and data elements as in the st_address type in your global class.
7. Return to the source code of your global class. In the implementation of the
IF_OO_ADT_CLASSRUN~MAIN method, replace st_address with your new dictionary
structure type. Make sure there are no syntax errors.
structure type you already created. For the name, use a quick fix to create a second simple
structure with two components (suggested name: Z##S_NAME).
3. Add another component for the name of the person (suggested name: Name). Enter
Z##S_NAME as the name of the component type.
Note:
This structure type does not yet exist. You create it in the next step.
4. Save the structure type. Then use a quick fix to create structure type Z##S_NAME.
6. Save the structure type. Then activate all inactive development objects.
7. Return to the source code of your global class. In the PUBLIC SECTION of the class
definition, remove or comment the definition of the types st_name and st_person.
5. Return to the source code of your global class. In the PUBLIC SECTION of the class
definition, remove or comment the definition of type st_person_inc.
7. Activate and debug the class as a console app. Analyze the content of the data objects
address, person, and person2.
You need some structure types that you can access in several global classes. You decide to
define structure types in the ABAP Dictionary.
Hint:
Before you define structure types in the ABAP Dictionary, you should investigate
the option to define public structure types in one of the global classes or in a
global interface.
Template:
Solution:
c) Enter the name of your package in the Package field. In the Name field, enter the name
ZCL_##_STRUCTURE, where ## stands for your group number.
2. In the PUBLIC SECTION of the class definition, analyze the definition of type st_address.
a) Perform this step as you have done earlier.
c) Confirm the package, enter the name Z##S_ADDRESS and the description Address,
then choose Next.
5. Add components for the postal code, the city, and the country. Use the same component
names and data elements as in the st_address type in your global class.
a) Adjust the code as follows:
7. Return to the source code of your global class. In the implementation of the
IF_OO_ADT_CLASSRUN~MAIN method, replace st_address with your new dictionary
structure type. Make sure there are no syntax errors.
a) Adjust the code as follows:
* Task 1
*****************************************************************
* DATA address TYPE st_address.
DATA address TYPE z##s_address.
c) Confirm the package, enter the name Z##S_PERSON and the description Person
(Name and Address), then choose Next.
3. Add another component for the name of the person (suggested name: Name). Enter
Z##S_NAME as the name of the component type.
Note:
This structure type does not yet exist. You create it in the next step.
4. Save the structure type. Then use a quick fix to create structure type Z##S_NAME.
a) Press Ctrl + S to save the development object.
b) Left-click on the error icon next to the code line you just added and choose Create
Dictionary Structure ....
6. Save the structure type. Then activate all inactive development objects.
b) From the eclipse toolbar, choose Activate inactive ABAP development objects.
Alternatively, press Ctrl + Shift + F3.
7. Return to the source code of your global class. In the PUBLIC SECTION of the class
definition, remove or comment the definition of the types st_name and st_person.
a) Perform this step as before.
* Task 2
***********************************************************
* DATA person TYPE st_person.
DATA person TYPE z##s_person.
person-name-first_name = 'Dictionary'.
person-name-last_name = 'ABAP'.
person-address-street = 'Dietmar-Hopp-Allee 16'.
person-address-postal_code = '69190'.
person-address-city = 'Walldorf'.
person-address-country = 'DE'.
b) Open the context menu on structure type Z##S_PERSON and choose Duplicate.
d) Assign the new development object to a transport request and choose Finish.
5. Return to the source code of your global class. In the PUBLIC SECTION of the class
definition, remove or comment the definition of type st_person_inc.
a) Perform this step as before.
* Task 3
**********************************************************************
* DATA person2 TYPE st_person_inc.
DATA person2 TYPE z##s_person_inc.
person2-name-first_name = 'Dictionary'.
person2-name-last_name = 'ABAP'.
person2-address-street = 'Dietmar-Hopp-Allee 16'.
person2-address-postal_code = '69190'.
person2-address-city = 'Walldorf'.
person2-address-country = 'DE'.
* or -------------------------------------------------------
person2-first_name = 'Dictionary'.
person2-last_name = 'ABAP'.
person2-street = 'Dietmar-Hopp-Allee 16'.
person2-postal_code = '69190'.
person2-city = 'Walldorf'.
person2-country = 'DE'.
7. Activate and debug the class as a console app. Analyze the content of the data objects
address, person, and person2.
a) Press Ctrl + F3 to activate the development object.
You need some table types that you can access in several global classes. You decide to define
table types in the ABAP Dictionary.
Hint:
Before you define table types in the ABAP Dictionary, you should investigate the
option to define public table types in one of the global classes or in a global
interface.
Template:
Solution:
2. In the PUBLIC SECTION of the class definition, analyze the definition of type
tt_addresses.
3. Create a new dictionary object of type Table Type (suggested name: Z##T_ADDRESSES).
Note:
If you have not finished the previous exercise, you can use the structure
type /LRN/S_ADDRESS, instead.
5. Specify the same table kind and key definition as in table type tt_addresses.
7. Return to the source ode of your global class. In the implementation of the
IF_OO_ADT_CLASSRUN~MAIN method, replace tt_addresses with your new dictionary
structure type. Make sure there are no syntax errors.
3. Add another component for the addresses of the person (suggested name: addresses).
As type, use the table type you created in the previous task.
5. Return to the source code of your global class. In the PUBLIC SECTION of the class
definition, remove or comment the definition of type st_person_deep.
3. Specify the same table kind and key definition as in table type tt_persons.
5. Return to the source ode of your global class. In the PUBLIC SECTION of the class
definition, remove or comment the definition of type tt_persons .
7. Activate and debug the class as a console app. Analyze the content of the data objects
addresses, person, and persons.
You need some table types that you can access in several global classes. You decide to define
table types in the ABAP Dictionary.
Hint:
Before you define table types in the ABAP Dictionary, you should investigate the
option to define public table types in one of the global classes or in a global
interface.
Template:
Solution:
c) Enter the name of your package in the Package field. In the Name field, enter the name
ZCL_##_TABLE_TYPE, where ## stands for your group number.
2. In the PUBLIC SECTION of the class definition, analyze the definition of type
tt_addresses.
a) Perform this step as before.
3. Create a new dictionary object of type Table Type (suggested name: Z##T_ADDRESSES).
a) In the Project Explorer view, expand your package and open the context menu on
subnode Dictionary.
c) Confirm the package, enter the name Z##T_ADDRESSES and the description
Addresses, then choose Next.
Note:
If you have not finished the previous exercise, you can use the structure
type /LRN/S_ADDRESS, instead.
a) In the Row Type section, change the Category from Predefined Type to Dictionary.
5. Specify the same table kind and key definition as in table type tt_addresses.
a) In the Initialization and Access section, change the table kind from Standard Table to
Sorted Table.
c) In the Primary Key Details section, change the Key Definition from Standard Key to
Key Components.
d) In the Key Components section, use code completion to enter COUNTRY and CITY as
key fields.
7. Return to the source ode of your global class. In the implementation of the
IF_OO_ADT_CLASSRUN~MAIN method, replace tt_addresses with your new dictionary
structure type. Make sure there are no syntax errors.
a) Adjust the code as follows:
* Task 1
**********************************************************************
* DATA addresses TYPE tt_addresses.
DATA addresses TYPE z##t_addresses.
addresses =
VALUE #(
( street = 'Dietmar-Hopp-Allee 16'
postal_code = '69190'
city = 'Walldorf'
country = 'DE'
)
( street = '3999 West Chester Pike'
postal_code = '19073'
city = 'Newtown Square, PA'
country = 'US'
)
).
c) Confirm the package, enter the name Z##S_PERSON_DEEP and the description
Person (Name and Several Addresses), then choose Next.
3. Add another component for the addresses of the person (suggested name: addresses).
As type, use the table type you created in the previous task.
a) Adjust the code as follows:
5. Return to the source code of your global class. In the PUBLIC SECTION of the class
definition, remove or comment the definition of type st_person_deep.
a) Perform this step as before.
* Task 2
**********************************************************************
* DATA person TYPE st_person_deep.
DATA person TYPE /lrn/s_person_deep.
person-first_name = 'Dictionary'.
person-last_name = 'ABAP'.
person-addresses = addresses.
c) Confirm the package, enter the name Z##T_PERSONS and the description Persons
(With Name and Addresses), then choose Next.
3. Specify the same table kind and key definition as in table type tt_persons.
a) In the Initialization and Access section, change the table kind from Standard table
to Hashed Table.
c) In the Primary Key Details section, change the Key Definition from Standard Key to
Key Components and the Key Category from Non-Unique to Unique.
d) In the Key Components section, specify the key fields LAST_NAME and FIRST_NAME.
5. Return to the source ode of your global class. In the PUBLIC SECTION of the class
definition, remove or comment the definition of type tt_persons .
a) Perform this step as before.
* Task 3
**********************************************************************
* DATA persons TYPE tt_persons.
DATA persons TYPE /lrn/t_persons.
persons =
VALUE #(
( person )
(
first_name = 'CDS'
last_name = 'ABAP'
addresses =
VALUE #(
( street = 'SAP-Allee 29'
postal_code = '68789'
city = 'St.Leon-Rot'
country = 'DE'
)
( street = '35 rue d''Alsace'
postal_code = '92300'
city = 'Levallois-Perret'
country = 'FR'
)
( street = 'Bedfont Road'
postal_code = 'TW14 8HD'
city = 'Feltham'
country = 'GB'
)
)
)
).
7. Activate and debug the class as a console app. Analyze the content of the data objects
addresses, person, and persons.
a) Press Ctrl + F3 to activate the development object.
You want to decouple the data access and the table definition. To do so, you define a CDS
view entity that read
Template:
n.a.
Solution:
For this exercise, you need the database table for employee data that you created and filled in
a previous exercise (suggested name was: Z##EMPLOY, where ## is your group number). If
you have not finished that exercise, create a copy of the database table /LRN/EMPLOY_DEP .
1. In your own package, create a new data definition (suggested name: Z##_R_EMPLOYEE,
where ## is your group number). Specify your database table as Referenced Object and
choose the Define View Entity template to generate the definition statement, some
standard annotations and the element list.
1. Display the SQL statement with which the technical representation of the view entity is
created in the database.
Do the CDS view entity and the representation in the database have the same fields?
You want to decouple the data access and the table definition. To do so, you define a CDS
view entity that read
Template:
n.a.
Solution:
For this exercise, you need the database table for employee data that you created and filled in
a previous exercise (suggested name was: Z##EMPLOY, where ## is your group number). If
you have not finished that exercise, create a copy of the database table /LRN/EMPLOY_DEP .
1. In your own package, create a new data definition (suggested name: Z##_R_EMPLOYEE,
where ## is your group number). Specify your database table as Referenced Object and
choose the Define View Entity template to generate the definition statement, some
standard annotations and the element list.
a) In the Project Explorer view, right-click your database table definition Z##EMPLOY to
open the context menu.
c) Confirm that the Package field contains the name of your package and that the
Referenced Object field contains the name of your database table definition.
d) In the Name field, enter the name for the CDS view entity (Z##_R_Employee, where
## is your group number).
Caution:
Make sure you don't choose Finish yet. If you do, you are not able to
choose the template that you want to use.
g) From the list of Templates, choose Define View Entity, then choose Finish.
a) Select both code rows and press Ctrl + < to add two slash signs (/) at the beginning
of each row.
1. Display the SQL statement with which the technical representation of the view entity is
created in the database.
Do the CDS view entity and the representation in the database have the same fields?
No, the representation in the database also contains the client field that is not required in
the CDS view entity.
a) Right-click anywhere in the source code of the data definition and choose Show SQL
CREATE Statement.
You want to enrich your CDS view entity with metadata. In a first step, you define and
maintain ABAP annotations for both, the entire view and individual view elements.
Template:
Solution:
1. Copy the /LRN/R_EMPLOYEE data definition to a data definition in your own package
(suggested name: Z##_EMPLOYEE, where ## stands for your group number).
Hint:
You can use the syntax of the @ObjectModel.usageType annotation group as
a blueprint.
Note:
You should make sure that the annotation values fit the technical table settings
of your database table for employee data.
1. In the element list, un-comment the AnnualSalary element and the CurrencyCode
element.
2. Add the mandatory element annotation that identifies the AnnualSalary element as an
amount and links it to theCurrencyCode element.
Note:
You might need to add this annotation manually with the support of code
completion. At the time of writing, the editor for data definitions does not offer
a quick fix for this error. (The editor for database table definitions does.)
3. Open the Active Annotations View and analyze the values of the EndUserText.Label
annotation for the different view elements.
4. Return to the source code of your data definition and add element annotation
EndUSerText.label for view element CurrencyCode. Change the label from Currency to
Currency Key.
6. Return to the Active Annotations view, refresh the display, and confirm that now the new
label is active.
Hint:
To find a specific annotation more easily, you can first collapse the entire tree
and then expand the element and main annotation you are interested in.
You want to enrich your CDS view entity with metadata. In a first step, you define and
maintain ABAP annotations for both, the entire view and individual view elements.
Template:
Solution:
1. Copy the /LRN/R_EMPLOYEE data definition to a data definition in your own package
(suggested name: Z##_EMPLOYEE, where ## stands for your group number).
a) In the Project Explorer view, right-click the /LRN/R_EMPLOYEE data definition to open
the context menu.
c) Enter the name of your package in the Package field. In the Name field, enter the name
for the CDS view entity (Z##_Employee, where ## stands for your group number).
b) In the empty row, enter @A and press Ctrl + Space to invoke code-completion.
Hint:
You can use the syntax of the @ObjectModel.usageType annotation group as
a blueprint.
// @AbapCatalog.dataMaintenance: #RESTRICTED
// @AbapCatalog.viewEnhancementCategory: [#NONE]
@AbapCatalog: {
dataMaintenance: #RESTRICTED,
viewEnhancementCategory: [#NONE]
}
@AccessControl.authorizationCheck: #NOT_REQUIRED
Note:
You should make sure that the annotation values fit the technical table settings
of your database table for employee data.
a) Place the cursor on @ObjectModeland press F1 to open the ABAP language help.
b) On the ABAP Language Help view that opens below the editor, choose@ObjectModel,
CDS View annotations, View Entity.
c) For the serviceQuality annotation, choose #D because the view does not support
transactional processing.
d) For the sizeCategory annotation, choose #M because we expect less than 100,000 data
sets.
e) For the dataClass annotation, choose #MASTER because employee data are maser
data.
1. In the element list, un-comment the AnnualSalary element and the CurrencyCode
element.
a) Select both code rows and press Ctrl + Shift + < to remove the comment signs
from the beginning of each row.
2. Add the mandatory element annotation that identifies the AnnualSalary element as an
amount and links it to theCurrencyCode element.
Note:
You might need to add this annotation manually with the support of code
completion. At the time of writing, the editor for data definitions does not offer
a quick fix for this error. (The editor for database table definitions does.)
department_id as DepartmentId,
@Semantics.amount.currencyCode: 'CurrencyCode'
annual_salary as AnnualSalary,
currency_code as CurrencyCode,
3. Open the Active Annotations View and analyze the values of the EndUserText.Label
annotation for the different view elements.
The end user texts are derived from the data elements that are used as types for the
corresponding database table fields.
a) Right-click anywhere in the source code of the data definition and choose Open With
→ Active Annotations.
Result
The Active Annotations view appears as a new tab below the editor view. The source of
the end user texts is listed in the Origin Data Type column.
4. Return to the source code of your data definition and add element annotation
EndUSerText.label for view element CurrencyCode. Change the label from Currency to
Currency Key.
a) Adjust the code as folows:
@Semantics.amount.currencyCode: 'CurrencyCode'
annual_salary as AnnualSalary,
@EndUserText.label: 'Currency Key'
currency_code as CurrencyCode,
6. Return to the Active Annotations view, refresh the display, and confirm that now the new
label is active.
Hint:
To find a specific annotation more easily, you can first collapse the entire tree
and then expand the element and main annotation you are interested in.
a) From the toolbar on the Active Annotations view, choose Refresh (F5). Alternatively,
place the cursor anywhere on the view and press F5.
b) From the toolbar on the Active Annotations view, choose Collapse All.
You want to separate the basic definition of your data model from its specific usage
(consumption). To do so, you build a new CDS view entity on top of your existing data model
entity.
Template:
n.a.
Solution:
For this exercise, you need the view entity for employee data that you created and annotated
in previous exercises (suggested name was: Z##_R_Employee, where ## is your group
number). If you have not finished the previous exercise, create a copy of data definition /LRN/
R_EMPLOYEE_ANN.
1. In your own package, create a new data definition (suggested name: Z##_C_EMPLOYEE,
where ## is your group number). Specify your existing view entity as Referenced Object
and choose the Define View Entity template to generate the definition statement, some
standard annotations and the element list.
2. Adjust the @ObjectModel.usageType annotations. Use the same values as in the base
view.
3. Open the Active Annotations View and analyze the element annotation values for view
elements AnnualSalary and CurrencyCode .
Where does the value for the @Semantics.amount.CurrencyCode annotation come from?
4. In your new data definition, disable the propagation of element annotations again.
5. Solve the syntax error by adding the mandatory element annotation directly to the
AnnualSalary view element.
You want to separate the basic definition of your data model from its specific usage
(consumption). To do so, you build a new CDS view entity on top of your existing data model
entity.
Template:
n.a.
Solution:
For this exercise, you need the view entity for employee data that you created and annotated
in previous exercises (suggested name was: Z##_R_Employee, where ## is your group
number). If you have not finished the previous exercise, create a copy of data definition /LRN/
R_EMPLOYEE_ANN.
1. In your own package, create a new data definition (suggested name: Z##_C_EMPLOYEE,
where ## is your group number). Specify your existing view entity as Referenced Object
and choose the Define View Entity template to generate the definition statement, some
standard annotations and the element list.
a) In the Project Explorer view, right-click your existing data definition Z##_R_EMPLOYEE
to open the context menu.
c) Confirm that the Package field contains the name of your package and that the
Referenced Object field contains the name of your data definition.
d) In the Name field, enter the name for the CDS view entity (Z##_C_Employee, where
## is your group number).
Caution:
Make sure you don't choose Finish yet. If you do, you are not able to
choose the template that you want to use.
g) From the list of Templates, choose Define View Entity, then choose Finish.
2. Adjust the @ObjectModel.usageType annotations. Use the same values as in the base
view.
a) Adjust the code as follows:
@ObjectModel.usageType:{
serviceQuality: #D,
sizeCategory: #M,
dataClass: #MASTER
}
3. Open the Active Annotations View and analyze the element annotation values for view
elements AnnualSalary and CurrencyCode .
Where does the value for the @Semantics.amount.CurrencyCode annotation come from?
a) Right-click anywhere in the source code of the data definition and choose Open With
→ Active Annotations.
b) The Active Annotations view appears as a new tab below the editor view.
c) From the toolbar on the Active Annotations view, choose Collapse All.
4. In your new data definition, disable the propagation of element annotations again.
a) Change the value of annotation @Metadata.ignorePropagatedAnnotations back to
true.
5. Solve the syntax error by adding the mandatory element annotation directly to the
AnnualSalary view element.
a) Adjust the code as follows:
DepartmentId,
@Semantics.amount.currencyCode: 'CurrencyCode'
AnnualSalary,
CurrencyCode,
You define a second database table for departments and define the foreign key relationship
between departments and employees.
Template:
Solution:
For this exercise, you need the database table for employee data that you created and filled in
a previous exercise (suggested name was: Z##EMPLOY, where ## is your group number). If
you have not finished that exercise, create a copy of database table /LRN/EMPLOY_DEP.
Add the id field to the table key and include the /LRN/S_ADMIN structure for administrative
data into the field list.
2. After the client field, add a second key field id, and type it with the your data element
Z##_DEPARTMENT_ID.
Note:
If you have not completed the corresponding exercise, use data
element /LRN/DEPARTMENT_ID, instead.
5. Maintain the technical table settings. Use the value help to choose appropriate values for
the data class and the size category.
Note:
We expect the table to contain less than 100 entries.
6. Activate the technical table settings and the database table definition.
1. Identify the foreign key table and navigate to the check field.
Which table is the check table and which table is the foreign key table?
Which fields in the foreign key table form the foreign key?
Hint:
Use code-completion where possible.
Note:
When saving the definition, the editor also adds annotation
@AbapCatalog.foreignKey.screenCheck.
4. Add a cardinality to document that a single department ID can be used in any number of
employee data sets, and that on the other hand, every employee should be assigned to an
existing department.
1. Edit the field list of your database table for department data. Before the INCLUDE
statement, add the following fields and use a quick fix to create the new data elements:
Field Name Data Element
department_head Z##_DEPMENT_HEAD
department_assistant Z##_DEPMENT_ASSISTANT
For both data elements, use your domain Z##_EMPLOYEE_IDas the data type.
Note:
Only If you did not create a Z##_EMPLOYEE_ID domain, you can use the /LRN/
EMPLOYEE_ID domain, instead. Make sure the key field ID of your database
table for employee data (suggested name was Z##EMPLOY) is based on the
same domain.
2. For both new fields, add a foreign key relationship with table Z##EMPLOY as check table.
Then save the database table definition to invoke auto-formatting.
Hint:
Use code-completion where possible.
3. Add a cardinality to both foreign key relationships. Choose the cardinality based on the
following information:
Note:
Skip this step if you created a copy of /LRN/CL_S4D430_CHECK_AND_FILL in
an earlier exercise.
Hint:
You can add a comment sign in front of the current definition and remove the
comment sign from the second definition alternative.
4. Activate the ABAP class and execute it as a console app. If the console output contains
errors, adjust the definition of your database tables until they are compatible with
database table definitions /LRN/EMPLOY_REL and LRN/DEPMENT_REL.
You define a second database table for departments and define the foreign key relationship
between departments and employees.
Template:
Solution:
For this exercise, you need the database table for employee data that you created and filled in
a previous exercise (suggested name was: Z##EMPLOY, where ## is your group number). If
you have not finished that exercise, create a copy of database table /LRN/EMPLOY_DEP.
Add the id field to the table key and include the /LRN/S_ADMIN structure for administrative
data into the field list.
c) Confirm the package, enter the name Z##DEPMENT and the description Department,
then choose Next.
e) The code of the database table definition should look like this:
@EndUserText.label : 'Department'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table z##depment {
2. After the client field, add a second key field id, and type it with the your data element
Z##_DEPARTMENT_ID.
Note:
If you have not completed the corresponding exercise, use data
element /LRN/DEPARTMENT_ID, instead.
5. Maintain the technical table settings. Use the value help to choose appropriate values for
the data class and the size category.
Note:
We expect the table to contain less than 100 entries.
a) Right-click anywhere in the editor and choose Open Others → Technical Settings.
6. Activate the technical table settings and the database table definition.
a) While still on the Technical Table Setttings dialog, press Ctrl + F3 to activate the
technical table settings.
b) Return to the editor with the source code of the database table definition and press
Ctrl + F3 to activate the database table definition.
1. Identify the foreign key table and navigate to the check field.
Which table is the check table and which table is the foreign key table?
The database table for department data is the check table, the database table for
employee data is the foreign key table.
Which fields in the foreign key table form the foreign key?
The foreign key consists of the client field and the department_id field.
The department_id field is the last field of the foreign key and therefore the check field.
a) Open the definition of your database table for employee data (suggested name was
Z##EMPLOY) .
Hint:
Use code-completion where possible.
a) In the definition of the department_id field, place the cursor before the closing semi-
colon (;) and press Enter to insert a new code row.
b) Place the cursor at the beginning of the new row and press Ctrl + Space to invoke
code-completion.
d) Enter a blank space and press Ctrl + Space to invoke code completion again.
e) From the suggestion list, choose your database table for department data, that is entry
z##depment - table.
f) Enter a blank space and use code-completion to enter the WHERE keyword.
g) Keep using code completion to add the assignment of key fields (on the left-hand side)
and foreign key fields (on the right-had side).
Note:
When saving the definition, the editor also adds annotation
@AbapCatalog.foreignKey.screenCheck.
entry_date : z##_entry_date;
@AbapCatalog.foreignKey.screenCheck : false
department_id : z##_department_id
with foreign key z##depment
where client = z##employ.client
and id = z##employ.department_id;
4. Add a cardinality to document that a single department ID can be used in any number of
employee data sets, and that on the other hand, every employee should be assigned to an
existing department.
a) Adjust the code as follows:
entry_date : z##_entry_date;
@AbapCatalog.foreignKey.screenCheck : false
department_id : z##_department_id
with foreign key [0..*,1] z##depment
where client = z##employ.client
and id = z##employ.department_id;
1. Edit the field list of your database table for department data. Before the INCLUDE
statement, add the following fields and use a quick fix to create the new data elements:
Field Name Data Element
department_head Z##_DEPMENT_HEAD
department_assistant Z##_DEPMENT_ASSISTANT
For both data elements, use your domain Z##_EMPLOYEE_IDas the data type.
Note:
Only If you did not create a Z##_EMPLOYEE_ID domain, you can use the /LRN/
EMPLOYEE_ID domain, instead. Make sure the key field ID of your database
table for employee data (suggested name was Z##EMPLOY) is based on the
same domain.
b) Open the Problems view. You should see an error Field DEPARTMENT_HEAD:
Component type or domain used not active or does not exist.
c) Place the cursor onz##_depment_head, and press Ctrl + 1 to open the quick fix
menu.
d) From the quick fix menu, double-click Create data element ....
e) Confirm the package and the name, enter a description, for example, Department
Head, and choose Next.
g) Under Type Name, enter Z##_EMPLOYEE_ID and enter the following field labels:
Field Value
Short Dep. Head
h) Activate the new data element and return to database table Z##DEPMENT.
Field Value
Short Assistant
2. For both new fields, add a foreign key relationship with table Z##EMPLOY as check table.
Then save the database table definition to invoke auto-formatting.
Hint:
Use code-completion where possible.
a) After applying the auto-formatting, the code should look like this:
@AbapCatalog.foreignKey.screenCheck : false
head_id : z##_depment_head
with foreign key z##employ
where client = z##depment.client
and employee_id = z##depment.head_id;
@AbapCatalog.foreignKey.screenCheck : false
assistant_id : z##_depment_assistant
with foreign key z##employ
where client = z##depment.client
and employee_id = z##depment.assistant_id;
include /lrn/s_admin;
}
3. Add a cardinality to both foreign key relationships. Choose the cardinality based on the
following information:
@AbapCatalog.foreignKey.screenCheck : false
head_id : z##_depment_head
with foreign key [0..1,0..1] z##employ
where client = z##depment.client
and employee_id = z##depment.head_id;
@AbapCatalog.foreignKey.screenCheck : false
assistant_id : z##_depment_assistant
with foreign key [0..1,1] z##employ
where client = z##depment.client
and employee_id = z##depment.assistant_id;
Note:
Skip this step if you created a copy of /LRN/CL_S4D430_CHECK_AND_FILL in
an earlier exercise.
a) In the Project Explorer view, locate the ABAP class in package /LRN/
S4D430_EXERCISE and right-click on it to open the context menu.
c) Enter the name of your package, the name for the copy and a description. Then choose
Next.
Hint:
You can add a comment sign in front of the current definition and remove the
comment sign from the second definition alternative.
b) If the literal after VALUE still contains ##, replace it with your group number.
4. Activate the ABAP class and execute it as a console app. If the console output contains
errors, adjust the definition of your database tables until they are compatible with
database table definitions /LRN/EMPLOY_REL and LRN/DEPMENT_REL.
a) Press Ctrl + F3 to activate the development object.
c) Make sure the console output contains the text Filled table ... for both database tables.
You define a basic CDS view entity for departments and the associations between
departments and employees.
Template:
Solution:
For this exercise, you need the CDS view entity for employee data which you created in a
previous exercise (suggested name was: Z##_R_Employee, where ## is your group number).
If you have not finished that exercise, create a copy of data definition /LRN/
R_EMPLOYEE_ANN.
Note:
If you have not finished the previous exercise, you can let your CDS view entity
read the database table /LRN/DEPMENT_REL.
1. In your own package, create a new data definition (suggested name: Z##_R_DEPARTMENT,
where ## is your group number). Specify your database table as Referenced Object and
choose the Define View Entity template to generate the definition statement, some
standard annotations and the element list.
1. Open the basic data definition for employee data (suggested name was:
Z##_R_EMPLOYEE).
2. Define an association to your CDS view entity for department data with association name
_Department.
3. Define the ON-condition, using the department ID field in both view entities.
Hint:
Make use of the $projection. prefix to address the element of the source
view entity and the_Department. prefix to address the element of the target
view entity.
4. Add a cardinality that matches the cardinality of the foreign key relationship for the
DEPARTMENT_ID table field.
Note:
The cardinality of the foreign key relationship is 0..*,1. The first part specifies
the number employees per department. The second part expresses the
number of departments per employee.
1. Return to the data definition for department data. Define association _Employee to
address all employees that are assigned to this department.
Note:
Take into account that a department can have any number of employees,
including zero.
2. Define an association to address the details of the department head. Set the cardinality
based on the cardinality of the foreign key relationship between the underlying database
tables.
Note:
In our model, it is NOT necessary that a department has a department head.
3. Define an association to address the details of the department assistant. Set the
cardinality based on the cardinality of the foreign key relationship between the underlying
database tables.
Note:
In our model, a department cannot exist without a department assistant.
1. Display the SQL statement with which the technical representation of the view entity is
created in the database.
2. Open the Data Preview for your CDS view for department data.
3. Display all employees that work for the Sales and Distribution department.
4. Return to the department list and display the assistant of the Administration department.
5. Without returning to the list of departments, navigate to the department, this person
works for and from there to the department head.
You define a basic CDS view entity for departments and the associations between
departments and employees.
Template:
Solution:
For this exercise, you need the CDS view entity for employee data which you created in a
previous exercise (suggested name was: Z##_R_Employee, where ## is your group number).
If you have not finished that exercise, create a copy of data definition /LRN/
R_EMPLOYEE_ANN.
Note:
If you have not finished the previous exercise, you can let your CDS view entity
read the database table /LRN/DEPMENT_REL.
1. In your own package, create a new data definition (suggested name: Z##_R_DEPARTMENT,
where ## is your group number). Specify your database table as Referenced Object and
choose the Define View Entity template to generate the definition statement, some
standard annotations and the element list.
a) In the Project Explorer view, right-click your database table definition Z##DEPMENT to
open the context menu.
c) Confirm that the Package field contains the name of your package and that the
Referenced Object field contains the name of your database table definition.
d) In the Name field, enter the name for the CDS view entity (Z##_R_Department, where
## is your group number).
Caution:
Make sure you don't choose Finish yet. If you do, you are not able to
choose the template that you want to use.
g) From the list of Templates, choose Define View Entity, then choose Finish.
1. Open the basic data definition for employee data (suggested name was:
Z##_R_EMPLOYEE).
a) Press Ctrl + Shift + A.
b) Enter Z##_R_.
2. Define an association to your CDS view entity for department data with association name
_Department.
a) Adjust the code as follows:
3. Define the ON-condition, using the department ID field in both view entities.
Hint:
Make use of the $projection. prefix to address the element of the source
view entity and the_Department. prefix to address the element of the target
view entity.
4. Add a cardinality that matches the cardinality of the foreign key relationship for the
DEPARTMENT_ID table field.
Note:
The cardinality of the foreign key relationship is 0..*,1. The first part specifies
the number employees per department. The second part expresses the
number of departments per employee.
last_changed_at as LastChangedAt,
_Department
}
1. Return to the data definition for department data. Define association _Employee to
address all employees that are assigned to this department.
Note:
Take into account that a department can have any number of employees,
including zero.
2. Define an association to address the details of the department head. Set the cardinality
based on the cardinality of the foreign key relationship between the underlying database
tables.
Note:
In our model, it is NOT necessary that a department has a department head.
3. Define an association to address the details of the department assistant. Set the
cardinality based on the cardinality of the foreign key relationship between the underlying
database tables.
Note:
In our model, a department cannot exist without a department assistant.
last_changed_at as LastChangedAt,
_Employee,
_Head,
_Assistant
}
1. Display the SQL statement with which the technical representation of the view entity is
created in the database.
No, as long as the associations are only exposed and not used in path expressions, they
have no effect on database layer.
a) Right-click anywhere in the source code of the data definition and choose Show SQL
CREATE Statement.
2. Open the Data Preview for your CDS view for department data.
a) Right-click anywhere in the source code of the data definition and choose Open
With → Data Preview. Alternatively, place the cursor anywhere in the source code of
the data definition and press F8.
3. Display all employees that work for the Sales and Distribution department.
a) Right-click anywhere in the row with value SALE in the Id column and choose Follow
Association. Alternatively, place the cursor anywhere in the row and press Ctrl + G.
4. Return to the department list and display the assistant of the Administration department.
a) On the navigation path that is displayed above the Data Preview tab (sometimes
referred to as “Breadcrumb naviation”), choose Z##_R_DEPARTMENT to return to the
list of departments.
b) Right-click anywhere in the row with value ADMIN in the Id column and choose Follow
Association. Alternatively, place the cursor anywhere in the row and press Ctrl + G.
5. Without returning to the list of departments, navigate to the department, this person
works for and from there to the department head.
a) Right-click anywhere in the single row that is displayed and choose Follow Association.
c) Right-click anywhere in the single row that is displayed and choose Follow Association.
You defined CDS view entities with exposed associations. You want to make use of the
exposed associations. First you do so in a CDS view, then in a SELECT statement in ABAP
SQL.
Template:
Solution:
Note:
If you have not finished the previous exercise, you can let your new view entity
read from the /LRN/R_Employee_Rel view entity.
3. Edit the element list of the new data definition. Remove all elements except for
EmployeeID, FirstName, LastName, DepartmentID, and the exposed association
_Department.
4. After the DepartmentID element, add a path expression to read the description of the
department, to which the employee is assigned (suggested element name:
DepartmentDescription).
5. Save the data definition and display the SQL CREATE statement.
Note:
If you don't save the data definition, your changes will not appear in the SQL
CREATE statement.
6. Add a path expression to read the last name of the department assistant (suggested
element name: AssistantName).
7. Activate the data definition and display the SQL CREATE statement again.
How many JOIN statements does the FROM clause contain now?
3. At the end of the field list, also read the new view elements DepartmentDescription
and AssistantName.
4. After the department assistant's name, implement a path expression that reads the last
name of the department head (suggested field name: HEADNAME).
Hint:
Use code-completion where possible. Remember that in ABAP SQL,
association names require a backslash sign (\) as a prefix and that a dash
sign (-) is used between the association name and the element name.
You defined CDS view entities with exposed associations. You want to make use of the
exposed associations. First you do so in a CDS view, then in a SELECT statement in ABAP
SQL.
Template:
Solution:
Note:
If you have not finished the previous exercise, you can let your new view entity
read from the /LRN/R_Employee_Rel view entity.
c) Confirm that the Package field contains the name of your package and that the
Referenced Object field contains the name of your database table definition.
d) In the Name field, enter the name for the CDS view entity (Z##_C_EmployeeQuery,
where ## is your group number).
Caution:
Make sure you don't choose Finish yet. If you do, you are not able to
choose the template that you want to use.
g) From the list of Templates, choose Define View Entity, then choose Finish.
3. Edit the element list of the new data definition. Remove all elements except for
EmployeeID, FirstName, LastName, DepartmentID, and the exposed association
_Department.
a) Adjust the code as follows:
/* Associations */
_Department
4. After the DepartmentID element, add a path expression to read the description of the
department, to which the employee is assigned (suggested element name:
DepartmentDescription).
a) Adjust the code as follows:
_Department.Description as DepartmentDescription,
/* Associations */
_Department
5. Save the data definition and display the SQL CREATE statement.
Note:
If you don't save the data definition, your changes will not appear in the SQL
CREATE statement.
Yes, the association is translated into a JOIN expression and the department description is
read from the joined data source.
b) Right-click anywhere in the source code of the data definition and choose Show SQL
CREATE Statement.
6. Add a path expression to read the last name of the department assistant (suggested
element name: AssistantName).
a) Adjust the code as follows:
_Department.Description as DepartmentDescription,
_Department._Assistant.LastName as AssistantName,
/* Associations */
_Department
7. Activate the data definition and display the SQL CREATE statement again.
How many JOIN statements does the FROM clause contain now?
The FROM clause contains two JOIN statements (one to read the department description,
the other to read the department assistant's name).
b) Right-click anywhere in the source code of the data definition and choose Show SQL
CREATE Statement.
c) Enter the name of your package in the Package field. In the Name field, enter the name
ZCL_##_PATH_EXP, where ## is your group number.
SELECT
FROM Z##_C_EmployeeQuery
FIELDS employeeid,
3. At the end of the field list, also read the new view elements DepartmentDescription
and AssistantName.
a) Adjust the code as follows:
SELECT
FROM Z##_C_EmployeeQuery
FIELDS employeeid,
firstname,
lastname,
departmentid,
departmentdescription,
assistantname
INTO TABLE @DATA(result).
4. After the department assistant's name, implement a path expression that reads the last
name of the department head (suggested field name: HEADNAME).
Hint:
Use code-completion where possible. Remember that in ABAP SQL,
association names require a backslash sign (\) as a prefix and that a dash
sign (-) is used between the association name and the element name.
SELECT
FROM Z##_C_EmployeeQuery
FIELDS employeeid,
firstname,
lastname,
departmentid,
departmentdescription,
assistantname,
\_department\_head-lastname AS headname
INTO TABLE @DATA(result).
You want to extend your CDS view entity with SQL logic. In a first step, you tag employees as
department heads and assistants and calculate the monthly salary.
Template:
Solution:
For this exercise, you need the CDS view entity you created in a previous exercise (suggested
name was: Z##_C_EmployeeQuery, where ## is your group number). If you have not finished
that exercise, create a copy of the data definition /LRN/C_EMPLOYEE_QRY.
1. In the element list of your view entity, before the exposed association, add a case
distinction that compares the value of EmployeeID to the value of element HeadID in the
target of association _Department. If the values are identical, return value 'H'.
2. Add a second branch that compares the value of EmployeeID to the value of element
AssistantID in the target of association _Department. If the values are identical, return
value 'A'.
4. Close the CASE expression and specify an element name (suggested element name:
EmployeeRole).
5. Add the required annotation to define a label for the calculated field (suggested value:
Employee Role).
1. Use an arithmetic expression with the / operator to divide the content of AnnualSalary
by 12.
Why do you have to cast the annual salary value to another data type?
2. Add the required annotation to define a label for the calculated field (suggested value:
Monthly Salary).
3. Add the CurrencyCode element to the element list and use the
@Semantics.amount.currencyCode annotation to link it to the MonthlySalary element.
Why does the syntax check not enforce the currency code annotation?
You want to extend your CDS view entity with SQL logic. In a first step, you tag employees as
department heads and assistants and calculate the monthly salary.
Template:
Solution:
For this exercise, you need the CDS view entity you created in a previous exercise (suggested
name was: Z##_C_EmployeeQuery, where ## is your group number). If you have not finished
that exercise, create a copy of the data definition /LRN/C_EMPLOYEE_QRY.
1. In the element list of your view entity, before the exposed association, add a case
distinction that compares the value of EmployeeID to the value of element HeadID in the
target of association _Department. If the values are identical, return value 'H'.
This is a simple case because it directly compares fields and values for equality.
_Department.Description as DepartmentDescription,
_Department._Assistant.LastName as AssistantName,
case EmployeeId
when _Department.HeadId then 'H'
2. Add a second branch that compares the value of EmployeeID to the value of element
AssistantID in the target of association _Department. If the values are identical, return
value 'A'.
a) Adjust the code as follows:
case EmployeeId
when _Department.HeadId then 'H'
when _Department.AssistantId then 'A'
case EmployeeId
when _Department.HeadId then 'H'
when _Department.AssistantId then 'A'
else ' '
4. Close the CASE expression and specify an element name (suggested element name:
EmployeeRole).
a) Adjust the code as follows:
case EmployeeId
when _Department.HeadId then 'H'
when _Department.AssistantId then 'A'
else ' '
end as EmployeeRole,
5. Add the required annotation to define a label for the calculated field (suggested value:
Employee Role).
a) Adjust the code as follows:
1. Use an arithmetic expression with the / operator to divide the content of AnnualSalary
by 12.
Why do you have to cast the annual salary value to another data type?
2. Add the required annotation to define a label for the calculated field (suggested value:
Monthly Salary).
a) Adjust the code as follows:
3. Add the CurrencyCode element to the element list and use the
@Semantics.amount.currencyCode annotation to link it to the MonthlySalary element.
Why does the syntax check not enforce the currency code annotation?
The annotation is only enforced for elements of type abap.cuky but the expression result
is of type abap.fltp.
CurrencyCode,
You want to extend your CDS view entity with SQL logic. You use SQL functions to
concatenate first name and last name of the department assistant, convert the monthly
salary to a unique currency and calculate the company affiliation, that is, the number of days
an employee works for the company.
Template:
Solution:
For this exercise, you need the CDS view entity that you worked on in the previous exercise
(suggested name was: Z##_C_EmployeeQuery, where ## is your group number). If you have
not finished the previous exercise, create a copy of data definition /LRN/C_EMPLOYEE_EXP.
1. Edit the element list of your view entity. Comment the view element that derives the last
name of the department assistant.
2. After the old view element, use code completion to add a call of SQL function
CONCATENATE_WITH_SPACE as a new view element.
4. Provide the same view element name that was used for the removed view element
(suggested name was: AssistantName).
Hint:
The current date is available in session variables $session.user_date and
$session.system_date. For this exercise, use the current system date.
For simplicity, disregard the existence of leap years and assume a year has 365
days.
1. Edit the element list of your view entity. Before the exposed association, use code
completion to add a call of SQL function DATS_DAYS_BETWEEN as a new view element.
2. Replace the placeholders with suitable view elements and session variables and specify a
view element name (suggested name: CompanyAffiliation).
3. Use the SQL function division to calculate the company affiliation in years, with a
precision of one decimal place.
Hint:
You can re-use calculated view elements of the same view entity by using the
$projection prefix.
2. In the next code row, define a new view element (suggested name: CurrencyCodeUSD) in
which you convert literal 'USD' to predefined type abap.cuky.
3. Before the MonthlySalary view element, use code completion to insert a call of the SQL
function currency_conversion.
4. Replace the placeholders with values for the parameters. As input, use the annual salary
and the currency code from the source view, own view element CurrencyCodeUSD, and
system variable system_date .
7. Adjust the view element name (suggested name: MonthlySalaryConverted) and adjust
the mandatory Semantics.amount.CurrencyCode annotation.
You want to extend your CDS view entity with SQL logic. You use SQL functions to
concatenate first name and last name of the department assistant, convert the monthly
salary to a unique currency and calculate the company affiliation, that is, the number of days
an employee works for the company.
Template:
Solution:
For this exercise, you need the CDS view entity that you worked on in the previous exercise
(suggested name was: Z##_C_EmployeeQuery, where ## is your group number). If you have
not finished the previous exercise, create a copy of data definition /LRN/C_EMPLOYEE_EXP.
1. Edit the element list of your view entity. Comment the view element that derives the last
name of the department assistant.
a) Place the cursor anywhere in the respective code row and press Ctrl + < to add a
comment sign (//) at the beginning of the row.
2. After the old view element, use code completion to add a call of SQL function
CONCATENATE_WITH_SPACE as a new view element.
a) In the code row // _Department._Assistant.LastName as AssistantName,,
place the cursor after the colon and press Enter to insert a new row.
concat_with_space( _Department._Assistant.FirstName,
_Department._Assistant.LastName,
1 )
Note:
We inserted additional line breaks to increase readability in the printed
course material.
4. Provide the same view element name that was used for the removed view element
(suggested name was: AssistantName).
a) Adjust the code as follows:
concat_with_space( _Department._Assistant.FirstName,
_Department._Assistant.LastName,
1 ) as AssistantName,
b) Press F8 to test the CDS view entity in the Data Preview tool.
Hint:
The current date is available in session variables $session.user_date and
$session.system_date. For this exercise, use the current system date.
For simplicity, disregard the existence of leap years and assume a year has 365
days.
1. Edit the element list of your view entity. Before the exposed association, use code
completion to add a call of SQL function DATS_DAYS_BETWEEN as a new view element.
a) Place the cursor at the beginning of code row /* Associations */ and press Enter
to insert a new row.
b) In the new code row, enter dats and press Ctrl + Space to invoke code-completion.
c) From the suggestion list, choose dats_days_between( date1, date2 ) (function) and
press Shift + Enter to insert the full signature.
Result
This should insert the following code:
2. Replace the placeholders with suitable view elements and session variables and specify a
view element name (suggested name: CompanyAffiliation).
a) Adjust the code as follows:
dats_days_between( EntryDate,
$session.system_date ) as CompanyAffiliation,
Note:
Again, we inserted additional line breaks to increase readability in printed
course material.
3. Use the SQL function division to calculate the company affiliation in years, with a
precision of one decimal place.
a) Adjust the code as follows:
b) Press F8 to test the CDS view entity in the Data Preview tool.
Hint:
You can re-use calculated view elements of the same view entity by using the
$projection prefix.
2. In the next code row, define a new view element (suggested name: CurrencyCodeUSD) in
which you convert literal 'USD' to predefined type abap.cuky.
a) Adjust the code as follows:
// CurrencyCode,
cast( 'USD' as /dmo/currency_code ) as CurrencyCodeUSD,
3. Before the MonthlySalary view element, use code completion to insert a call of the SQL
function currency_conversion.
a) In a new code row, enter curr and press Ctrl + Space to invoke code-completion.
b) From the suggestion list, choose the entry starting with currency_conversion( amount
=> amount, ... and press Shift + Enter to insert the full signature.
Note:
We inserted additional line breaks, again.
4. Replace the placeholders with values for the parameters. As input, use the annual salary
and the currency code from the source view, own view element CurrencyCodeUSD, and
system variable system_date .
a) Adjust the code as follows:
7. Adjust the view element name (suggested name: MonthlySalaryConverted) and adjust
the mandatory Semantics.amount.CurrencyCode annotation.
a) Adjust the code as follows:
b) Press F8 to test the CDS view entity in the Data Preview tool.
You extended your CDS view entity with SQL functions and used literals and session variables
as input. Now you replace some literals and session variables with input parameters.
Template:
Solution:
Note:
If you have not finished the previous exercise, create a copy of CDS data
definition /LRN/C_EMPLOYEE_FNC, instead.
In the new data definition, replace the hard-coded target currency with an input parameter
(suggested name: p_target_curr) and session variable $session.system_field with a
second input parameter (suggested name: p_date).
1. Create a copy of your data definition with SQL functions (suggested name was:
Z##_C_EmployeeQuery, where ## is your group number). Alternatively , copy from data
definition /LRN/C_EMPLOYEE_FNC (suggested name for the new view entity:
Z##_C_EmployeeQueryP).
2. Edit the definition of your view entity. Define an input parameter to replace the hard-coded
currency code for the currency conversion (suggested name: p_target_curr). Use the
same type that is used in the CurrencyCodeUSD view element.
4. Annotate the second parameter with a label (suggested value: Date of evaluation).
Note:
This is not necessary for the first parameter because that parameter is typed
with a data element.
5. In the definition of the CurrencyCodeUSD view element, replace the CAST expression
with the input parameter.
Hint:
Use code-completion to access the parameter.
Note:
Do not forget to also adjust the value of the two
@Semantics.amount.currencyCode annotations.
3. Supply the input parameters of the view entity with values. Use a literal for the currency
code (for example, 'JPY') and system field sy-datum for the date parameter.
Hint:
Remember that sy-datum is a host variable and that you have to escape it
with @.
1. Return to the CDS data definition and annotate the p_date parameter to link it to the
system date. Use code completion to choose the annotation value.
3. Return to your ABAP class and remove or comment the date parameter in the FROM
clause.
You extended your CDS view entity with SQL functions and used literals and session variables
as input. Now you replace some literals and session variables with input parameters.
Template:
Solution:
Note:
If you have not finished the previous exercise, create a copy of CDS data
definition /LRN/C_EMPLOYEE_FNC, instead.
In the new data definition, replace the hard-coded target currency with an input parameter
(suggested name: p_target_curr) and session variable $session.system_field with a
second input parameter (suggested name: p_date).
1. Create a copy of your data definition with SQL functions (suggested name was:
Z##_C_EmployeeQuery, where ## is your group number). Alternatively , copy from data
definition /LRN/C_EMPLOYEE_FNC (suggested name for the new view entity:
Z##_C_EmployeeQueryP).
a) In the Project Explorer view, right-click the Z##_C_EMPLOYEE_QUERY data definition or
the /LRN/C_EMPLOYEE_FUNC data definition to open the context menu.
c) Enter the name of your package in the Package field. In the Name field, enter the name
Z##_C_EmployeeQueryP, where ## stands for your group number.
2. Edit the definition of your view entity. Define an input parameter to replace the hard-coded
currency code for the currency conversion (suggested name: p_target_curr). Use the
same type that is used in the CurrencyCodeUSD view element.
4. Annotate the second parameter with a label (suggested value: Date of evaluation).
Note:
This is not necessary for the first parameter because that parameter is typed
with a data element.
5. In the definition of the CurrencyCodeUSD view element, replace the CAST expression
with the input parameter.
Hint:
Use code-completion to access the parameter.
Note:
Do not forget to also adjust the value of the two
@Semantics.amount.currencyCode annotations.
// CurrencyCode,
// cast( 'USD' as /dmo/currency_code ) as CurrencyCodeUSD,
$parameters.p_target_curr as CurrencyCode,
b) Press F8 to test the CDS view entity in the Data Preview tool.
c) Enter values for the two parameters and choose Open Data Preview.
Hint:
Mandatory parameters have an asterisk symbol (*) next to the parameter
name.
c) Enter the name of your package in the Package field. In the Name field, enter the name
ZCL_##_PARAMETER, where ## is your group number.
SELECT
FROM Z##C_EmployeeQueryP
FIELDS employeeid,
3. Supply the input parameters of the view entity with values. Use a literal for the currency
code (for example, 'JPY') and system field sy-datum for the date parameter.
Hint:
Remember that sy-datum is a host variable and that you have to escape it
with @.
SELECT
FROM Z##C_EmployeeQueryP(
p_target_curr = 'JPY',
p_date = @sy-datum )
FIELDS employeeid,
SELECT
FROM Z##C_EmployeeQueryP(
p_target_curr = 'JPY',
p_date = @sy-datum )
FIELDS employeeid,
firstname,
lastname,
departmentid,
departmentdescription,
assistantname,
\_department\_head-lastname AS headname,
MonthlySalaryConverted,
CurrencyCode,
CompanyAffiliation
1. Return to the CDS data definition and annotate the p_date parameter to link it to the
system date. Use code completion to choose the annotation value.
a) Adjust the code as follows:
b) Press F8 to test the CDS view entity in the Data Preview tool.
c) Enter a value for the currency code parameter and choose Open Data Preview.
Hint:
Mandatory parameters have an asterisk symbol (*) next to the parameter
name.
3. Return to your ABAP class and remove or comment the date parameter in the FROM
clause.
a) Adjust the code as follows:
SELECT
FROM /LRN/C_Employee_Par(
p_target_curr = 'JPY'
* , p_date = @sy-datum
)
FIELDS employeeid,
You want to further analyze employee and department data. To do so, you use the DISTINCT
addition, aggregations, grouping, and joins in a CDS view entity.
Template:
n.a.
Solution:
Note:
If you have not finished the previous exercise, you can let your new view entity
read from view entity /LRN/C_Employee_Fnc.
3. Edit the element list of the new data definition. Remove all elements except for
DepartmentID and DepartmentDescription.
4. Activate the data definition and display the query result in the Data Preview tool.
5. Edit the data definition and add the DISTINCT addition to the SELECT statement.
6. Activate the data definition and display the query result again.
2. At the end of the element list, add a new view element (suggested name:
AverageAffiliation). Use aggregate function AVG with argument
CompanyAffiliation.
3. Make sure the result has the same type as the CompanyAffiliation element of the
source view entity.
4. Add a new view element (suggested name: TotalSalary). Use aggregate function SUM
with argument AnnualSalaryConverted.
5. Add the currency code to the element list and annotate the amount field with
@Semantics.amount.currencyCode.
7. Activate the data definition and display the query result again.
Note:
If you have not finished the previous exercise, read from CDS view entity /LRN/
C_Employee_Par, instead.
1. In the FROM clause, replace the data source and use your view entity with parameters.
Use code completion to insert the full signature of the data source, that is, the CDS view
entity with its parameters.
2. Define two input parameters for your view. Use the same parameter names, types, and
annotations that are used in the data source.
Hint:
It is easiest if you copy the parameter definitions from the data source.
4. In the element list, adjust the name of the currency code element, that is, remove the USD
suffix.
Note:
If you have not finished the exercise on associations, use CDS view entity /LRN/
C_Department_Rel, instead.
1. In your view entity Z##_C_DepartmentQuery, adjust the FROM clause. At the end of the
clause, add a right outer join of your CDS view entity for department data.
2. Define alias names for the two data sources (suggested names: e for employee and d for
department) and add the ON condition.
3. In the element list, read the department ID and the department description from the
department view entity rather than from the employee view entity and make the
department ID a key element.
4. Remove the GROUP BY clause and regenerate it using the quick fix.
5. Add the table alias as a prefix where requested by the syntax check.
You want to further analyze employee and department data. To do so, you use the DISTINCT
addition, aggregations, grouping, and joins in a CDS view entity.
Template:
n.a.
Solution:
Note:
If you have not finished the previous exercise, you can let your new view entity
read from view entity /LRN/C_Employee_Fnc.
c) Confirm that the Package field contains the name of your package and that the
Referenced Object field contains the name of your database table definition.
d) In the Name field, enter the name for the CDS view entity (Z##_C_DepartmentQuery,
where ## is your group number).
Caution:
Make sure you don't choose Finish, yet. If you do, you are not able to
choose the template that you want to use.
g) From the list of Templates, choose Define View Entity, then choose Finish.
3. Edit the element list of the new data definition. Remove all elements except for
DepartmentID and DepartmentDescription.
a) Adjust the code as follows:
4. Activate the data definition and display the query result in the Data Preview tool.
5. Edit the data definition and add the DISTINCT addition to the SELECT statement.
a) Adjust the code as follows:
6. Activate the data definition and display the query result again.
2. At the end of the element list, add a new view element (suggested name:
AverageAffiliation). Use aggregate function AVG with argument
CompanyAffiliation.
a) Adjust the code as follows:
3. Make sure the result has the same type as the CompanyAffiliation element of the
source view entity.
a) Place the cursor on CompanyAffiliation and press F2 to display the code element
information. The type of CompanyAffiliation is abap.dec(11,1).
4. Add a new view element (suggested name: TotalSalary). Use aggregate function SUM
with argument AnnualSalaryConverted.
a) Adjust the code as follows:
5. Add the currency code to the element list and annotate the amount field with
@Semantics.amount.currencyCode.
a) Adjust the code as follows:
b) From the list of available quick fixes, choose Add GROUP BY clause.
c) After applying the quick fix, the code should look as follows:
7. Activate the data definition and display the query result again.
a) Press Ctrl + F3 to activate the development object.
Note:
If you have not finished the previous exercise, read from CDS view entity /LRN/
C_Employee_Par, instead.
1. In the FROM clause, replace the data source and use your view entity with parameters.
Use code completion to insert the full signature of the data source, that is, the CDS view
entity with its parameters.
b) Place the cursor immediately after the entity name and press Ctrl + Space to
invoke code-completion.
c) Press Shift + Enter to insert the view entity with full signature.
2. Define two input parameters for your view. Use the same parameter names, types, and
annotations that are used in the data source.
Hint:
It is easiest if you copy the parameter definitions from the data source.
a) Hold down the Strg key and choose the view name after FROM to navigate into the
data source.
b) Select the code before as select, including the WITH PARAMETERS addition and
press Ctrl + C to copy the parameter definition to the clipboard.
c) Return to your data definition and insert the parameter definition before as select.
4. In the element list, adjust the name of the currency code element, that is, remove the USD
suffix.
{
DepartmentId,
DepartmentDescription,
avg( CompanyAffiliation as abap.dec(11,1) ) as AverageAffiliation,
@Semantics.amount.currencyCode: 'CurrencyCode'
sum( AnnualSalaryConverted ) as TotalSalary,
CurrencyCode
}
group by
DepartmentId,
DepartmentDescription,
CurrencyCode
Note:
If you have not finished the exercise on associations, use CDS view entity /LRN/
C_Department_Rel, instead.
1. In your view entity Z##_C_DepartmentQuery, adjust the FROM clause. At the end of the
clause, add a right outer join of your CDS view entity for department data.
as select
from Z##_C_EmployeeQueryP(
p_target_curr: $parameters.p_target_curr,
p_date: $parameters.p_date )
right outer join Z##_R_Department
2. Define alias names for the two data sources (suggested names: e for employee and d for
department) and add the ON condition.
as select
from Z##_C_EmployeeQueryP(
p_target_curr: $parameters.p_target_curr,
p_date: $parameters.p_date ) as e
right outer join Z##_R_Department as d
on e.DepartmentId = d.Id
3. In the element list, read the department ID and the department description from the
department view entity rather than from the employee view entity and make the
department ID a key element.
a) Adjust the code as follows:
{
d.Id,
d.Description,
avg( CompanyAffiliation as abap.dec(11,1) ) as AverageAffiliation,
@Semantics.amount.currencyCode: 'CurrencyCode'
sum( AnnualSalaryConverted ) as TotalSalary,
CurrencyCode
}
4. Remove the GROUP BY clause and regenerate it using the quick fix.
a) Adjust the code as follows:
group by
d.Id,
d.Description,
CurrencyCode
5. Add the table alias as a prefix where requested by the syntax check.
a) Adjust the code as follows:
{
d.Id,
d.Description,
avg( e.CompanyAffiliation as abap.dec(11,1) ) as
AverageAffiliation,
@Semantics.amount.currencyCode: 'CurrencyCode'
sum( e.AnnualSalaryConverted ) as TotalSalary,
e.CurrencyCode
}
group by
d.Id,
d.Description,
e.CurrencyCode
You developed a data model with database tables and CDS view entities. To protect the data
against unauthorized access, you define an authorization field and an authorization object.
Then you create CDS access controls for your CDS view entities.
Template:
n.a.
Solution:
For this exercise, you need the CDS view entities which you have created in previous
exercises (suggested names were: Z##_R_Department, Z##_R_Employee,
Z##_C_DepartmentQuery, and Z##_C_EmployeeQuery, where ## is your group number). If
you have not finished those exercises, create copies of the four data definitions from
package /LRN/S4D430_EXERCISE, that are ending with _AUT.
Note:
If you have not created a data element for the department ID, use the /LRN/
DEPARTMENT_ID data element, instead.
1. Create an authorization field based on the data element for the department ID (suggested
name: Z##DEPMENT).
2. Set your database table for department data as check table (suggested name was:
Z##DEPMENT) and save the authorization field.
Note:
If your authorization field is based on the /LRN/DEPARTMENT_ID data
element, you have to use the database table /LRN/DEPMENT_REL.
3. Create a new authorization object and assign the authorization field to it.
4. Confirm that the new authorization object contains the standard authorization field ACTVT
and the default permitted activities.
Note:
Following a general recommendation, name the access controls after the view
entity they protect.
1. Open your base view entity for department data in the Data Preview tool.
2. For this view entity create a CDS access control that defines a CDS role with a PFCG
condition.
4. Replace the first placeholder for authorization fields with the name of your authorization
field. Then remove the second placeholder.
5. Use the ACTVT authorization field as a filter field and supply it with the filter value for
activity Display.
6. Reference a suitable entity element to supply the first authorization field. Then remove the
placeholder for a second view element.
7. Activate the access control and refresh the display in the Data Preview tool.
8. To see at least some data, edit the CDS access control again and replace your own
authorization object Z##DPMNT with the solution object /LRN/DPMNT and your own
authorization field Z##DPMNT with the authorization field /LRN/DPMNT. For this
authorization object your user already has some authorizations.
9. In the same way, create a CDS access control for your base view entity for employee data.
Note:
Following a general recommendation, name the access controls after the view
entity they protect.
1. Open the definition of your CDS view entity that queries employee data based on two input
parameters.
From which other CDS view entity does the view entity read its data?
2. For the view entity with parameters, create a CDS access control that defines a CDS role
with inherited conditions.
3. In the generated code, reference the view entity the protected entity uses as data source,
that is, Z##_R_Employee.
5. Open the definition of your CDS view entity that aggregates employee data per
department.
6. Define an access control that inherits the access conditions from the primary data source.
You developed a data model with database tables and CDS view entities. To protect the data
against unauthorized access, you define an authorization field and an authorization object.
Then you create CDS access controls for your CDS view entities.
Template:
n.a.
Solution:
For this exercise, you need the CDS view entities which you have created in previous
exercises (suggested names were: Z##_R_Department, Z##_R_Employee,
Z##_C_DepartmentQuery, and Z##_C_EmployeeQuery, where ## is your group number). If
you have not finished those exercises, create copies of the four data definitions from
package /LRN/S4D430_EXERCISE, that are ending with _AUT.
Note:
If you have not created a data element for the department ID, use the /LRN/
DEPARTMENT_ID data element, instead.
1. Create an authorization field based on the data element for the department ID (suggested
name: Z##DEPMENT).
a) In the Project Explorer, right-click your package to open the context menu and choose
New → Other ABAP Repository Object.
b) In the filter field, enter au and choose Authorization Field from the suggestion list.
2. Set your database table for department data as check table (suggested name was:
Z##DEPMENT) and save the authorization field.
Note:
If your authorization field is based on the /LRN/DEPARTMENT_ID data
element, you have to use the database table /LRN/DEPMENT_REL.
a) Place the cursor in theCheck Table field, enter Z## and press Ctrl + Space to open a
value help.
3. Create a new authorization object and assign the authorization field to it.
a) In the definition of the authorization field, scroll down to the What's next? section and
choose Create a new Authorization Object and assign the Authorization Field to it.
4. Confirm that the new authorization object contains the standard authorization field ACTVT
and the default permitted activities.
a) Inspect the Authorization Fields section which should contain your own authorization
field and the default authorization field ACTVT.
b) Inspect the Permitted Activities section which should contain the four default activities.
Note:
Following a general recommendation, name the access controls after the view
entity they protect.
1. Open your base view entity for department data in the Data Preview tool.
a) Open the definition of the view entity and press F8 to open the Data Preview tool.
2. For this view entity create a CDS access control that defines a CDS role with a PFCG
condition.
a) In the Project Explorer, locate your CDS data definition Z##_R_DEPARTMENT.
b) Right-click the data definition to open the context menu and choose New Access
Control.
c) Copy the name from the Protected Entity field to the Name field.
d) In the Description field, enter Department (Access Control), then choose Next.
f) From the list of Templates, choose Define Role with PFCG Aspect, and choose Finish.
Note:
We introduced additional line-breaks to increase readability in printed
training material.
4. Replace the first placeholder for authorization fields with the name of your authorization
field. Then remove the second placeholder.
a) Adjust the code as follows:
5. Use the ACTVT authorization field as a filter field and supply it with the filter value for
activity Display.
a) Adjust the code as follows:
6. Reference a suitable entity element to supply the first authorization field. Then remove the
placeholder for a second view element.
a) Adjust the code as follows:
7. Activate the access control and refresh the display in the Data Preview tool.
The authorization object is new. Therefore, your user does not have any authorizations for
departments, yet.
b) Return to the Data Preview for the protected entity and choose Refresh.
8. To see at least some data, edit the CDS access control again and replace your own
authorization object Z##DPMNT with the solution object /LRN/DPMNT and your own
authorization field Z##DPMNT with the authorization field /LRN/DPMNT. For this
authorization object your user already has some authorizations.
c) Activate the access control and refresh the display in the Data Preview tool.
9. In the same way, create a CDS access control for your base view entity for employee data.
a) In the project explorer, locate your CDS data definition Z##_R_EMPLOYEE.
b) Right-click the data definition to open the context menu and choose New Access
Control.
c) Copy the name from the Protected Entity field to the Name field.
d) In the Description field, enter Employee (Access Control), then choose Next.
f) From the list of Templates, choose Define Role with PFCG Aspect, and choose Finish.
Note:
Following a general recommendation, name the access controls after the view
entity they protect.
1. Open the definition of your CDS view entity that queries employee data based on two input
parameters.
From which other CDS view entity does the view entity read its data?
It reads from the base view entity for employee data, that is, from view entity
Z##_R_Employee.
b) Enter the name of the CDS data definition that you want to open, that is
Z##_C_EMPLOYEEQUERYP, and choose OK.
2. For the view entity with parameters, create a CDS access control that defines a CDS role
with inherited conditions.
a) In the Project Explorer, locate your CDS data definition Z##_C_EMPLOYEEQUERYP.
b) Right-click the data definition to open the context menu and choose New Access
Control.
c) Copy the name from the Protected Entity field to the Name field.
d) In the Description field, enter Employee Query (Access Control), then choose
Next.
f) From the list of Templates, choose Define Role with Inherited Conditions, and choose
Finish.
3. In the generated code, reference the view entity the protected entity uses as data source,
that is, Z##_R_Employee.
a) Adjust the code as follows:
5. Open the definition of your CDS view entity that aggregates employee data per
department.
In a right outer join, the main data source is on the right-hand side. Therefore, the primary
data source is the base view entity for department data, that is, view entity
Z##_R_Department.
b) Enter the name of the CDS data definition that you want to open, that is
Z##_C_DEPARTMENTQUERY, and choose OK.
6. Define an access control that inherits the access conditions from the primary data source.
a) In the Project Explorer, locate your CDS data definition Z##_C_DEPARTMENTQUERY.
b) Right-click the data definition to open the context menu and choose New Access
Control.
c) Copy the name from the Protected Entity field to the Name field.
d) In the Description field, enter Department Query (Access Control), then choose
Next.
f) From the list of Templates, choose Define Role with Inherited Conditions, and choose
Finish.
You want to extend a database table with additional fields. Instead of editing the database
table definition directly, you create an APPEND structure.
Note:
In this exercise, you extend your own database table for employee data
(suggested name was: Z##EMPLOY, where ## is your group number). This is done
for simplicity. To motivate the use of the append technique, you have to pretend
that the database table lies in a different name space and that you are not
authorized to make direct changes to it.
Template:
n.a.
Solution:
For this exercise, you need the database table definition for employee data that you created in
a previous exercise (suggested name was: Z##EMPLOY, where ## is your group number). If
you have not created that database table, create it now as a copy of database table
definition /LRN/EMPLOY_REL.
2. Adjust the extension category to allow the extension with char-like and numeric fields.
3. Define a mandatory suffix for the additional fields (suggested value: ZEM).
1. Use a quick fix to create an append structure for this table (suggested name:
Z##_S_EXT_EMPLOYEE, where ## is your group number) .
2. In the component list of the append structure, define a new component (suggested name:
zztitle) with data element /DMO/TITLE as component type.
5. Display the Tooltip Description for the extended database table to confirm that the table
contains the new fields.
Note:
Skip this step if you created a copy of /LRN/CL_S4D430_CHECK_AND_FILL in
an earlier exercise.
Hint:
You can add a comment sign in front of the current definition and remove the
comment sign from the second definition alternative.
3. If necessary, change the value of the c_employ_table constant to the name of your
database table.
Note:
The c_depment_table constant is not needed in this version of the code.
4. Activate the ABAP class and execute it as a console app. If the console output contains
errors, adjust the definition of your database table for employees until it is compatible with
the database table definition /LRN/EMPLOY_EXT.
You want to extend a database table with additional fields. Instead of editing the database
table definition directly, you create an APPEND structure.
Note:
In this exercise, you extend your own database table for employee data
(suggested name was: Z##EMPLOY, where ## is your group number). This is done
for simplicity. To motivate the use of the append technique, you have to pretend
that the database table lies in a different name space and that you are not
authorized to make direct changes to it.
Template:
n.a.
Solution:
For this exercise, you need the database table definition for employee data that you created in
a previous exercise (suggested name was: Z##EMPLOY, where ## is your group number). If
you have not created that database table, create it now as a copy of database table
definition /LRN/EMPLOY_REL.
2. Adjust the extension category to allow the extension with char-like and numeric fields.
a) Change the value of annotation @ABAPCatalog.enhancement.category from
#NOT_EXTENSIBLE to #EXTENSIBLE_CHARACTER_NUMERIC.
3. Define a mandatory suffix for the additional fields (suggested value: ZEM).
a) Add annotation @ABAPCatalog.enhancement.fieldSuffix.
@AbapCatalog.enhancement.category : #EXTENSIBLE_CHARACTER_NUMERIC
@AbapCatalog.enhancement.fieldSuffix : 'ZEM'
1. Use a quick fix to create an append structure for this table (suggested name:
Z##_S_EXT_EMPLOYEE, where ## is your group number) .
a) Place the cursor on the name of the database table and press Ctrl + 1 to invoke the
quick fix.
b) From the list of available quick fixes, choose Create append structure for ....
2. In the component list of the append structure, define a new component (suggested name:
zztitle) with data element /DMO/TITLE as component type.
No. The database table definition specifies the mandatory field suffix ZEM.
No. The append structure lies in the customer name space (because its name starts with
Z* or Y*). As a consequence, all components in the append structure have to start with
ZZ* or YY*.
5. Display the Tooltip Description for the extended database table to confirm that the table
contains the new fields.
a) In the code row that begins with extend type, place the cursor on z##employ and
press F2.
Note:
Skip this step if you created a copy of /LRN/CL_S4D430_CHECK_AND_FILL in
an earlier exercise.
a) In the Project Explorer view, locate the ABAP class in the /LRN/S4D430_EXERCISE
package and right-click it to open the context menu.
c) Enter the name of your package, the name for the copy and a description. Then choose
Next.
Hint:
You can add a comment sign in front of the current definition and remove the
comment sign from the second definition alternative.
3. If necessary, change the value of the c_employ_table constant to the name of your
database table.
Note:
The c_depment_table constant is not needed in this version of the code.
b) If the literal after VALUE still contains ##, replace it with your group number.
4. Activate the ABAP class and execute it as a console app. If the console output contains
errors, adjust the definition of your database table for employees until it is compatible with
the database table definition /LRN/EMPLOY_EXT.
a) Press Ctrl + F3 to activate the development object.
c) Make sure the console output contains the text Filled table ... for the database table.
You want to extend CDS view entities with additional elements and associations. Instead of
editing the data definitions directly, you create CDS view extensions.
Note:
In this exercise, you extend your own CDS view entities Z##_R_Employee and
Z##_C_EmployeeQueryP, where ## is your group number. This is done for
simplicity. To motivate the use of extensions, you have to pretend that the view
entities lie in a different name space and that you are not authorized to make
direct changes to them.
Template:
n.a.
Solution:
For this exercise, you need the base view entity for employee data (suggested name was:
Z##_R_Employee) that developed in previous exercises. If you have not finished those
exercises, create a copy of data definition /LRN/R_EMPLOYEE_AUT.
In addition, you need the view entity with parameters for employee data (suggested name
was: Z##_C_EmployeeQueryP) . If you have not finished the related exercises, create a copy
of data definition /LRN/C_EMPLOYEE_AUT and let it read from your base view entity.
1. Open the definition of your base view entity for employee data.
2. Adjust the view extension category to allow the extension of the element list.
3. Maintain the list of allowed data sources for the extension. Add the database table from
which the view entity reads to this list.
Note:
To add the database table to the list, you need to define an alias name for it
(suggested alias name: Employee).
4. Define a mandatory suffix for the additional fields (suggested value: ZEM).
6. Open the definition of your view entity with parameters for employee data.
7. As before, adjust the view extension category, maintain the allowed data sources, and
define the element suffix.
Note:
Use the same data source alias and element suffix as before.
1. Create a CDS view extension for your CDS view entity Z##_R_Employee.
2. Edit the element list of the view extension. Remove the placeholder and use code-
completion to add the employee's title and country.
3. Define alias names for the new view elements (suggested names: ZZTitleZem and
ZZCoutryZem).
5. Display the Tooltip Description for the extended view entity to confirm that it contains the
new elements.
Hint:
The country master data contain a flag IsEuropeanUnionMember. To access
this element, you first have to extend the view with an association to CDS view
entity I_Country (suggested association name: _ZZCountryZem). Then add a
path expression to the element list of the view extension.
1. Create a CDS view extension for your CDS view entity Z##_C_EmployeeQueryP.
2. Edit the element list of the view extension. Remove the placeholder and use code-
completion to add the employee's title and country.
3. Use the concat_with_space function to concatenate the employee's first name and last
name, separated by a single blank.
4. Add a name for this new element (suggested name: ZZFullNameZem) and use the
relevant annotation to provide a label.
5. Extend the view with an association to CDS view entity I_Country (suggested name:
_ZZCountryZem).
Hint:
In the ON condition, use the country code from the element list and the key
element of view entity I_Country.
6. In the element list, add the IsEuropeanUnionMember element of the association target
(suggested name: ZZEUBasedZem).
7. Activate the view extension and display the Tooltip Description for the extended view
entity to confirm that it contains the new elements.
You want to extend CDS view entities with additional elements and associations. Instead of
editing the data definitions directly, you create CDS view extensions.
Note:
In this exercise, you extend your own CDS view entities Z##_R_Employee and
Z##_C_EmployeeQueryP, where ## is your group number. This is done for
simplicity. To motivate the use of extensions, you have to pretend that the view
entities lie in a different name space and that you are not authorized to make
direct changes to them.
Template:
n.a.
Solution:
For this exercise, you need the base view entity for employee data (suggested name was:
Z##_R_Employee) that developed in previous exercises. If you have not finished those
exercises, create a copy of data definition /LRN/R_EMPLOYEE_AUT.
In addition, you need the view entity with parameters for employee data (suggested name
was: Z##_C_EmployeeQueryP) . If you have not finished the related exercises, create a copy
of data definition /LRN/C_EMPLOYEE_AUT and let it read from your base view entity.
1. Open the definition of your base view entity for employee data.
a) Press Ctrl + Shift + A, enter the name of the data definition and choose OK.
2. Adjust the view extension category to allow the extension of the element list.
a) Change the value of annotation @ABAPCatalog.viewEnhancementCategory from
#NONE to #PROJECTION_LIST.
3. Maintain the list of allowed data sources for the extension. Add the database table from
which the view entity reads to this list.
Note:
To add the database table to the list, you need to define an alias name for it
(suggested alias name: Employee).
@AbapCatalog: {
dataMaintenance: #RESTRICTED,
viewEnhancementCategory: [#PROJECTION_LIST],
extensibility.dataSources: [ 'Employee' ]
}
4. Define a mandatory suffix for the additional fields (suggested value: ZEM).
a) Add annotation @ABAPCatalog.extensibility.elementSuffix as follows:
@AbapCatalog: {
dataMaintenance: #RESTRICTED,
viewEnhancementCategory: [#PROJECTION_LIST],
extensibility.dataSources: [ 'Employee' ],
extensibility.elementSuffix: 'ZEM'
}
6. Open the definition of your view entity with parameters for employee data.
a) Press Ctrl + Shift + A, enter the name of the data definition and choose OK.
7. As before, adjust the view extension category, maintain the allowed data sources, and
define the element suffix.
Note:
Use the same data source alias and element suffix as before.
@AbapCatalog: {
dataMaintenance: #RESTRICTED,
viewEnhancementCategory: [#PROJECTION_LIST],
extensibility.dataSources: [ 'Employee' ],
extensibility.elementSuffix: 'ZEM'
}
1. Create a CDS view extension for your CDS view entity Z##_R_Employee.
a) In the Project Explorer, locate data definition Z##_R_EMPLOYEE, right-click it and
choose New Data Definition.
b) Ensure that the Package field contains the name of your own package.
Note:
Do not choose Finish yet or you will not be able to choose the correct
template.
e) From the list of Templates, choose Extend View Entity and choose Finish.
2. Edit the element list of the view extension. Remove the placeholder and use code-
completion to add the employee's title and country.
a) In the source code, replace base_data_source_code.element_name. with zz and
press Ctrl + Space to invoke code-completion.
b) From the suggestion list, choose zztitle_zem- z##employ as employee (column) to add
the append field to the element list of the CDS view extension.
3. Define alias names for the new view elements (suggested names: ZZTitleZem and
ZZCoutryZem).
5. Display the Tooltip Description for the extended view entity to confirm that it contains the
new elements.
a) In the code row that begins with extend view entity, place the cursor on
z##_R_Employee and press F2.
Hint:
The country master data contain a flag IsEuropeanUnionMember. To access
this element, you first have to extend the view with an association to CDS view
entity I_Country (suggested association name: _ZZCountryZem). Then add a
path expression to the element list of the view extension.
1. Create a CDS view extension for your CDS view entity Z##_C_EmployeeQueryP.
a) In the Project Explorer, locate data definition Z##_C_EMPLOYEEQUERYP, right-click it
and choose New Data Definition.
b) Ensure that the Package field contains the name of your own package.
Note:
Do not choose Finish yet or you will not be able to choose the correct
template.
e) From the list of Templates, choose Extend View Entity and choose Finish.
2. Edit the element list of the view extension. Remove the placeholder and use code-
completion to add the employee's title and country.
3. Use the concat_with_space function to concatenate the employee's first name and last
name, separated by a single blank.
a) Adjust the code as follows:
4. Add a name for this new element (suggested name: ZZFullNameZem) and use the
relevant annotation to provide a label.
a) Adjust the code as follows:
@
concat_with_space( Employee.FirstName, Employee.LastName, 1 ) as
ZZFullNameZem
}
5. Extend the view with an association to CDS view entity I_Country (suggested name:
_ZZCountryZem).
Hint:
In the ON condition, use the country code from the element list and the key
element of view entity I_Country.
concat_with_space( Employee.FirstName,
Employee.LastName,
1 ) as ZZFullNameZem
}
6. In the element list, add the IsEuropeanUnionMember element of the association target
(suggested name: ZZEUBasedZem).
a) Adjust the code as follows:
concat_with_space( Employee.FirstName,
Employee.LastName,
1 ) as ZZFullNameZem,
_ZZCountryZem.IsEuropeanUnionMember as ZZEUBasedZem
}
7. Activate the view extension and display the Tooltip Description for the extended view
entity to confirm that it contains the new elements.
a) Press Ctrl + F3 to activate the development object.
b) In the code row that begins with extend view entity, place the cursor on
z##_C_EmployeeQueryP and press F2.
You want to extend the metadata of one of your view entities. In a first step, you outsource
existing annotations into a CDS metadata extension. You then create a second metadata
extension to add more annotations and overwrite existing ones.
Template:
n.a.
Solution:
For this exercise, you need the view entity with parameters for employee data (suggested
name was: Z##_C_EmployeeQueryP) . If you have not finished the related exercises, create a
copy of data definition /LRN/C_EMPLOYEE_EXT.
1. Open the definition of your view entity with parameters for employee data and make sure
it is active.
2. Using a refactoring tool, extract all available annotations into a new metadata extension.
3. Use code-completion to set the layer of your metadata extension to the value with the
lowest priority.
4. Use a quick fix to adjust the annotated view entity so that it allows metadata extensions.
6. Open the annotated view entity in the Active Annotations tool and verify that some of the
annotations now come from the metadata extension.
1. In the Project Explorer, locate the definition of the view entity that you extended in the
previous task.
2. For this view entity, create a new CDS metadata extension based on the Annotate View
with Parameters template.
3. Use code-completion to set the layer of your metadata extension to the value with the
highest priority.
4. Replace placeholder parameter_name with p_date and add a new label for this
parameter, for example, Currency Conversion Date.
5. Replace the placeholder element_name with AssistantName and add a label for this
view element, for example, Department Assistant.
7. Open the annotated view entity in the Active Annotations tool and verify that the label for
the p_date parameter comes from the new metadata extension.
You want to extend the metadata of one of your view entities. In a first step, you outsource
existing annotations into a CDS metadata extension. You then create a second metadata
extension to add more annotations and overwrite existing ones.
Template:
n.a.
Solution:
For this exercise, you need the view entity with parameters for employee data (suggested
name was: Z##_C_EmployeeQueryP) . If you have not finished the related exercises, create a
copy of data definition /LRN/C_EMPLOYEE_EXT.
1. Open the definition of your view entity with parameters for employee data and make sure
it is active.
a) Press Ctrl + Shift + A.
c) From the list of matching items, select entry Z##_C_EmployeeQueryP and choose OK.
2. Using a refactoring tool, extract all available annotations into a new metadata extension.
a) From the Eclipse menu, choose Source Code → Extract Metadata Extension.
b) In the Extended Entity field, enter Z##_C, press Ctrl + Space and choose the name
of the CDS view entity that you want to extend (Z##_C_EmployeeQueryP).
c) Copy that name from the Extended Entity field to the Name field.
d) Enter a description (for example Employee Query (Metadata)) and choose Next.
f) Choose Expand All on the right-hand side and analyze the annotations that can be
extracted.
g) Choose Select All on the right-hand side and Finish on the bottom.
3. Use code-completion to set the layer of your metadata extension to the value with the
lowest priority.
a) In the @Metadata.layer annotation, remove placeholder layer.
c) From the suggestion list, choose value #CORE as this layer has the lowest priority.
4. Use a quick fix to adjust the annotated view entity so that it allows metadata extensions.
a) Place the cursor in the code row starting with annotate view and press Ctrl + 1 to
invoke the quickfix. Alternatively, you can choose the error icon with light bulb next to
this code row.
6. Open the annotated view entity in the Active Annotations tool and verify that some of the
annotations now come from the metadata extension.
a) Right-click anywhere in the source code and choose Open With → Active Annotations.
Result
For some of the annotations, column Origin Data Source should contain your metadata
extension.
1. In the Project Explorer, locate the definition of the view entity that you extended in the
previous task.
a) For example, expand the Core Data Services → Data Definitions subnode of your
package ZS4D430_##.
2. For this view entity, create a new CDS metadata extension based on the Annotate View
with Parameters template.
a) Right-click the data definition name to open the context menu and choose New
Metadata Extension.
b) Copy the value from the Extended Entity field to the Name field and add character 2 to
distinguish it from the already existing metadata extension.
c) Enter a description (for example Employee Query (Final Metadata)) and choose
Next.
e) From the list of available templates select Annotate View with Parameters and choose
Finish.
3. Use code-completion to set the layer of your metadata extension to the value with the
highest priority.
a) In the @Metadata.layer annotation, remove placeholder layer.
c) From the suggestion list, choose value #CUSTOMER as this layer has the highest
priority.
4. Replace placeholder parameter_name with p_date and add a new label for this
parameter, for example, Currency Conversion Date.
a) Adjust the code as follows:
@Metadata.layer: #CUSTOMER
annotate view Z##_C_EmployeeQueryP
with parameters
@EndUserText.label: 'Currency Conversion Date'
p_date
{
element_name;
5. Replace the placeholder element_name with AssistantName and add a label for this
view element, for example, Department Assistant.
a) Adjust the code as follows:
@Metadata.layer: #CUSTOMER
annotate view Z##_C_EmployeeQueryP
with parameters
@EndUserText.label: 'Currency Conversion Date'
p_date
{
@EndUserText.label: 'Department Assistant'
AssistantName;
}
7. Open the annotated view entity in the Active Annotations tool and verify that the label for
the p_date parameter comes from the new metadata extension.
a) Right-click anywhere in the source code and choose Open With → Active Annotations.