You are on page 1of 53

5Steps2FIORI

Gain hands-on experience in FIORI activation and


configuration
PARTNER
TABLE OF CONTENTS
INTRODUCTION .................................................................................................................................................. 3
EXTENSIBILITY AND DEVELOPMENT ............................................................................................................. 4
UI Adaptation ...................................................................................................................................................... 5
Introduction to ABAP in Eclipse ..................................................................................................................... 19
1. Developing with ABAP in Eclipse ................................................................................................... 19
Open ABAP in Eclipse ........................................................................................................................................ 20
Use the Data Preview & the SQL Console ......................................................................................................... 25
Create and run an ABAP Program ..................................................................................................................... 29
Create a global ABAP Class for data retrieval ................................................................................................... 32
5. Using Core Data Services ................................................................................................................ 42
Create a CDS View ............................................................................................................................................ 42
Use the CDS View in ALV with IDA ................................................................................................................... 47

2
INTRODUCTION
This document has the scope to explain you the steps required to complete all the activities planned for the
current work-package.

By executing the steps described in this document you will be able to understand the main procedures
required to select and activate Fiori Applications in your implementation project.
Note that the steps described in this document refer only to the technical activation steps, additional functional
activation steps may be needed depending on the application scope. The required functional steps are
described in the Fiori Apps Library.

3
EXTENSIBILITY AND DEVELOPMENT
For this topic, you can select the exercises you are most interested in and may use the available installation of
ABAP Developer Tools in Eclipse and WebIDE in the system image.

The description of the exercises is the following:

UI Adaptation
In this exercise you will learn how to modify the screens of a standard SAP Fiori application along with the
addition of custom fields with no need of creating custom code.

You can find the step-by-step exercise in this document in the next chapter.

Estimated execution time: 1 hour

Introduction to ABAP in Eclipse


In this exercise you will learn the basics to jumpstart the use of ADT in Eclipse, you will start by creating
simple reports and end in creating a custom CDS view that is consumed by an ABAP report.

You can find the step-by-step exercise in this document in the third chapter.

Estimated execution time: 2 hours

ABAP Programming Model for Fiori


In this exercise you will learn how to develop and create a Fiori application from scratch by implementing CDS
views.

You can find the step-by-step exercise description in the file: ABAP ProgrammingModel Fiori.docx

Estimated execution time: 3 hours

4
UI Adaptation
In this exercise we will explain how to modify a standard SAP Fiori application with In-App
extensibility features available in S/4HANA.

5
Comment Screenshot

1. Add the custom role ZFIO_999 to your


FIORIADM and FIORIUSR roles.

2. Implement SAP Note 2840685 NOTE 2840685 HINTS:


Implement automatic corrections. Once done you do not need to
perform additional activities as SAPUI5 libraries were updated to
1.65.14 on the exercises for WP04.

3. Login to the system with FIORIADM user to


activate additional apps for In-App
Extensibility using role
SAP_BR_ADMINISTRATOR and Task List
SAP_FIORI_CONTENT_ACTIVATION.

4. Assign the auto-generated role


Z_BR_ADMINISTRATOR to user to
FIORIADM and FIORIUSR

https://fioriappslibrary.hana.ondemand.com/sap/fix/externalViewer/
#/multiSelect/?appId=%252FAIF%252FCUST,%252FAIF%252FE
DCHANGES,%252FAIF%252FIFB,%252FAIF%252FIFMON,%252
FAIF%252FIFTEST,%252FAIF%252FLFA_UPLOAD_FILE,%252F
AIF%252FMYRECIPIENTS,%252FAIF%252FOD_MYRECIPIENT
S,%252FAIF%252FOD_RECIPIENTS,%252FAIF%252FRECIPIEN
TS,%252FAIF%252FVMAP,%252FAIFX%252FWDA_MSG_MONI
TOR%2520(%252FAIFX%252FWDAC_MSG_MONITOR),APOC_
WD_BRF_DEC_TAB_MAINTAIN%2520(),F0510,F0510A,F0617,F
0617A,F0618,F0618A,F0627,F0627A,F0756A,F1240,F1259,F1306
,F1434,F1474,F1481,F1487,F1561,F1561A,F1589,F1590,F1712,F
1866,F1939,F1994,F2057,F2058,F2102,F2131,F2220,F2279,F228
8,F2392,F2569,F2587,F2705,F2761,F2894,F3248,F3438,F3505,F
3814,F3815,F4016,F4158,FDT_WD_WORKBENCH_SIMPLIFIED
%2520(FDT_WD_WB_SIMPLIFIED_EXT_AC),ILM_AUDIT_AREA
%2520(ILM_AUDIT_AREA),SP01_SIMPLE,SRALCONFIG%2520(
SRALCONFIG),SWF_FLEX_I18N_TR_WEB,SWI2_ADM1_CLOU
D,SWI_ADM_CLOUD,SWI_HC_CLOUD,SWI_PR_CLOUD&releas
eId=S15OP

6
Comment Screenshot

5. Deactivate virus scan features by going


through the SAP Reference Image in
transaction SPRO.

6. In transaction VSCANPROFILE deactivate


virus scan profile
/UI5/UI5_INFRA_APP/REP_DT_PUT

**You will be prompted for a customizing request

7. Open Launchpad Designer (transaction:


/UI2/FLPD_CUST) and create a new
reference for the target mapping
CustomField-develop on catalog
SAP_BASIS_TCR_T to custom catalog
ZFIO_999

7
Comment Screenshot

8. You now need to generate the standard role


SAP_UI_FLEX_KEY_USER and assign it to
FIORIADM and FIORIUSR

9. Logon to Fiori Launchpad with FIORIUSR


and navigate to the “Purchase Requisition
Processing” group

10. In the Settings Area, set “USD” as default


value for the “Display Currency” field

11. Open “Monitor Purchase Requisition


Items” app and click on “Go” to retrieve data

8
Comment Screenshot

12. By now you should have noticed that it may


be a good idea to have the app retrieve
information automatically at startup. To do
this you can setup a default variant.
13. Fill in the filters with the following values:

Plant: Plant 1 (1000)


Delivery Status: Overdue

14. Change the graph type to Line Chart.

15. Change the view type to Purchase


Requisition Item

9
Comment Screenshot

16. Click on the variant manager on the upper


left side of the screen and click on the “Save
As” button.

17. Define a name for your variant and activate


the checkboxes “Set as Default” and
“Apply Automatically”

18. Go back to the Launchpad Home and


navigate to the “Monitor Purchase
Requisition Items” app and you should
automatically see the app loading your
variant.

**NOTE – The steps you have performed so far


correspond to personalization options of the Fiori
Launchpad, each user can individually make their
own modifications to the application depending on
their usage requirements

10
Comment Screenshot

19. Without leaving the app, navigate to the Me-


Area and you will now notice an additional
option called “Adapt UI”. Click on this
button.

20. Accept the pop-up message.

21. You will notice a new toolbar is displayed in


the Fiori Launchpad. With this new toolbar
you will be able to modify the behavior of the
apps without needing additional
development efforts.

11
Comment Screenshot

22. For a simple example, in the Purchase


Requisition Items section click on any
material and open the Settings section.
23. In this section you will be able to define to
which Fiori, Web dynpro or WebGUI app will
the user navigate to when they click on the
object.

24. Only maintain “Monitor Materials without


Purchase Contract” active

25. Once all the changes have been made, click


on “Save As” button and enter the
requested fields. You will be prompted for a
transport request, select Local Object

12
Comment Screenshot

26. Take note of the custom id generated by the


app.

27. In Fiori Apps Library, find the configuration


details of the “Monitor Purchase
Requisition Items” app and navigate to the
standard Catalog in Launchpad Designer
with FIORIADM.

https://fioriappslibrary.hana.ondemand.com/sap/fix/ex
ternalViewer/ - /detail/Apps('F2424')/S15OP

28. Once you have identified standard catalog


SAP_PRC_BC_PURCHASER_PR copy the
tile and target mapping configuration to
custom role ZFIO_999 via a reference

13
Comment Screenshot

29. Open custom role ZFIO_999 and edit the


target mapping PurchaseRequisitionItem-
Monitor to add the ID generated by the tool
and save your changes.

**When saving you will notice a prompt stating


that the reference to the original object will be
broken. Confirm this exception

30. Change the name of the semantic action to


“zmonitor” on both tile and target
mapping.

31. Use app finder to display the new custom


app.

14
Comment Screenshot

32. Open your newly customized app. You will Custom version:
notice no variants are available and the
simple change you have performed is visible
in the app.

**NOTE – The steps you have performed so far


correspond to adaptation options available for
each SAP Fiori application, as a key user, you can
define which navigation options should be
available for each user group.

Standard version:

33. You will now continue to modify the detail


page of the “Monitor Purchase Requisition
Items” app. Use your custom version of the
app and navigate to the detail of an item

15
Comment Screenshot

34. Once the detail page is loaded, open UI


Adaptation mode and right click on the
lower right corner of the Information section
to “Create a new Group”.

35. Name this new group “Additional Fields”.


Right click on the border surrounding the
group name and select the “Add field”
option

**You may observe a prompt suggesting


synchronization. If this occurs, confirm the
warning so synchronization occurs, and you will
need to recreate the custom group.

36. Add fields:

Created by
Creation Indicator

16
Comment Screenshot

37. Once created, you will notice one of the


fields does not contain any data. Remove
this field by right clicking on it and selecting
the option “Remove”

38. Remove the following fields:

Account Assignment Category


Desired Vendor
Batch
Revision Level

39. Move the Additional Fields group to the left


and click on Publish, you will be prompted
for a transport request, select Local Object.

40. Click on Save & Exit.

**By clicking on “Publish” the changes will


become available for both the standard and the
customized apps

17
Comment Screenshot

41. Try running the same app with a different


user, you will notice the modifications are
visible to any user.

**NOTE – The steps you have performed so far


correspond to adaptation options available for
each SAP Fiori application, as a key user, you can
define which fields or data is displayed in the
application.

18
Introduction to ABAP in Eclipse

The ABAP Development Tools (ADT) for SAP NetWeaver, also known as "ABAP in Eclipse", is the
recommended IDE for developing ABAP applications. It is available from SAP NetWeaver 7.31 SP4
onwards and it integrates seamlessly into your existing ABAP development systems.

In this series of exercises, you will get an introduction to the powerful tools delivered with ADT and
experience the advantages of using ABAP in Eclipse for your ABAP developments.

All the solutions to the exercises are provided as a reference - this way you can also see the solutions
for the exercises you did not finish. Feel free to experiment with the IDE yourself. These exercises are
only a guideline.

The exercises are based on the demo tables of the SAP NetWeaver EPM Model (you can find details
in the SCN http://scn.sap.com/docs/DOC-31458 ). So you can reiterate the exercises on any SAP
NetWeaver 7.40 or later systems.

1. Developing with ABAP in Eclipse


Overview
Estimated time: 60 minutes

Objective
In this exercise you will learn how to use ABAP in Eclipse. You will create an ABAP Project, use the Data
Preview and SQL Console and implement and run an ABAP Application. You will also learn how to use Quick
Assists to speed up your development.

Exercise Description

• Open ABAP in Eclipse


• Create an ABAP Project
• Use the Data Preview and the SQL Console
• Create and run an ABAP Program
• Create a global ABAP Class for data retrieval

19
Open ABAP in Eclipse

Explanation Screenshot
1. Start Eclipse

2. Accept the proposed


workspace / choose your
own workspace.

3. Close the Welcome page.

20
Explanation Screenshot

4. Click the Window


menu item.
Then click on Perspective →
Open Perspective → Other

6. Select the entry


ABAP to
open the ABAP perspective
with the ABAP development
tools.

21
Project Explorer View
Provides a hierarchical view of your ABAP Projects. From here you can
After starting the IDE and browse the ABAP Development Objects in the ABAP system (similar to
opening the ABAP perspective, the Repository Browser in the Object Navigator (SE80)) and open your
the ABAP tools are ideally ABAP Development Objects in the corresponding editor.
Editors Area
positioned in the IDE to The editors for the ABAP Development Objects are opened in the area
facilitate your development reserved in the centre of the IDE.
tasks. Nevertheless you are Outline View
free to rearrange all views and This view displays a structured overview of the ABAP Development
editors to your personel needs. Object that is currently open in the editor area. The contents of the
outline view are editor-specific.
Feature Explorer View
Project Explorer View This view provides you with an interactive tutorial to help you get familiar
with the basic features in ABAP in Eclipse.
Provides a hierarchical view of your Other Views
ABAP Projects. From here you can Several other useful views are stacked underneath the editor area in a
browse the ABAP Development tabbed container. Two of the most commonly used views are the:
Objects in the ABAP system (similar to
the Repository Browser in the Object
• Problems View: This view displays the syntax errors, warnings
or other information associated with an ABAP Development
Navigator (SE80)) and open your
Object (typically opened in the editor area)
ABAP Development Objects in the
corresponding editor. • Properties View: This view displays the basic properties of the
ABAP Development Object that is currently open in the editor
Editors Area area, e.g.: "Last changed by", "Created on", etc.
The editors for the ABAP
Development Objects are opened in
the area reserved in the centre of the
IDE.
Outline View
This view displays a structured
overview of the ABAP Development
Object that is currently open in the
editor area. The contents of the outline
view are editor-specific.
Feature Explorer View
This view provides you with an
interactive tutorial to help you get
familiar with the basic features in
ABAP in Eclipse.
Other Views
Several other useful views are stacked
underneath the editor area in a tabbed
container like transport organizer,
bookmarks, tasks and so on.

22
Explanation Screenshot

After starting the IDE, you have to


create an ABAP Project
(essentially a user connection to
the ABAP system).

7. Click the File menu


item.

8. Click New
9. Click the ABAP
Project
10. Select the
system
connection from
the list or define
a new
connection (by
clicking on „new
system
connection“) if
your system is
not in the list.

23
Explanation Screenshot
12. Enter 5STEPS2FIORI in
the User: * box.

Confirm your entry by pressing


the Tab key.

13. Enter your password.

14. Your ABAP Project has


been created and you have
successfully logged on to the
ABAP system. Your ABAP
Project is visible in the Project
Explorer.

24
Use the Data Preview & the SQL Console

Explanation Screenshot

1. Click or use the shortcut


Alt+F8 to execute an ABAP
Development Object. We will
"execute" the database table
snwd_so_inv_item. This will
open the Data Preview which
will allow us to explore the
invoice items in the EPM
model.

2. Enter snwd_so_inv_item in
the search field.

3. Once the search has


delivered a result or if the table
is already in the history
list, click on the
entry SNWD_SO_INV_ITEM.

4. Press to open
the Data Preview.

5. In the Data Preview Click


to change
which fields are retrieved from
the database.

25
Explanation Screenshot
6. First click Deselect All.

7. Only select the fields


GROSS_AMOUNT...

8. and CURRENCY_CODE.

9. Press to confirm
your selection.

The Data Preview is refreshed


accordingly.

10. Press Add filter and...

11. choose
CURRENCY_CODE.

12. Enter EUR in the text field


to filter the items that are in
Euro and press the Enter key.

The Data Preview is refreshed


accordingly.

26
Explanation Screenshot

13. to open
the SQL Console.

The SQL Console shows the


select statement which was used
to retrieve the data for the Data
Preview.
In the following steps you will
adjust the select statement to
read the payment status of the
order and the company name from
the buyer.

Adjust the select statement in SQL


Console in order to get the
payment status from the order
header by doing the following:

14. Add a JOIN condition for


the table snwd_so_inv_head

15. Correct the WHERE clause

16. Add the


field payment_status from
the table snwd_so_inv_head
to the SELECT list

17. Click Run to execute the


current query or press F8.

27
Explanation Screenshot
18. Check that the output on
the right hand side contains the
payment status.

Adjust the select statement


again in order to retrieve the
company name from the table
snwd_bpa by doing the following:

19. Add a join condition for


the table snwd_bpa

20. Add the field


company_name from the table
snwd_bpa to the select list.

21. Add an order by clause to


sort the result by the company
name of the buyer.

22. Click .

23. Check that the output on


the right hand side contains the
company name.

You will reuse this select


statement later for data retrieval
in an ABAP class. So just leave
the SQL Console open.

28
Create and run an ABAP Program

Explanation Screenshot
1. Right click on Logical
Objects ($TMP)

2. Search and select


ABAP Program

menu item.

3. Enter
Z_INVOICE_ITMES_EURO_<
NN> in the Name: * box.
Please refer to the Setup-
Information and exchange
_<NN> with your user number.

Confirm your entry by pressing


the Tab key.

4. Enter Euro Invoices in the


Description: * box.

5. Click Finish .

6. Type lcl and press


Ctrl+Space to get code
completion proposals.

7. Select the code template for


the insertion of a local class by
double-clicking on lcl - Local
class or press Enter when the
right entry is selected.

29
Explanation Screenshot
8. Adjust the name of the local
class to lcl_main using inline
editing.

9. Position the cursor in the


class definition statement and
press Ctrl+1 to open the Quick
Fix menu.
Double-click on Generate
factory method to create a
static factory method.

10. Add the defintion of an


additional instance method run
in the public section.

11. Position the cursor on the


method name and press
Ctrl+1 to open the Quick-Fix
menu.
Double-click on Add
implementation for run.

12. Fill the method


implementation of run with a
simple write statement.

13. Add a start-of-selection


event to your report and create
an instance of the local
class lcl_main. Call the
method run.

14. Click Activate


(Ctrl+F3) .

30
Explanation Screenshot

15. Click Run As... .

16. Double click on the entry


ABAP
Application
to select it.

17. Click the [F00]


Z_INVOICE_ITMES_EURO_<
NN>

tab to select it.

31
Create a global ABAP Class for data retrieval
In this part of the exercise you will replace the write statement in your report with data retrieval logic
based on the select statement created before in the SQL Console. Then you will display the retrieved
data using the SAP ABAP List Viewer (ALV). In order to separate concerns properly and to show you
a wider toolset the data retrieval logic will be encapsulated in a global ABAP class.

Explanation Screenshot
1. First remove the write
statement. Place the cursor
somewhere in the write
statement and use the shortcut
Ctrl+D to delete the whole line.

2. Create a local variable in the


run method. The variable
should be type ref
to zcl_invoice_retrieval_NN.
This is the global class for the
data retrieval.

3. Since this class does not yet


exist, you will get a syntax
error. To create the class place
the cursor on the class name
and press Ctrl+1 to get a Quick
Assist. In the Quick Fix menu
double-click on Create global
class
zcl_invoice_retrieval_NN .

A wizard will appear to create a


new ABAP class.

4. Enter
ZCL_INVOICE_RETRIEVAL_
NN in the Name: * box.
Replace NN with your user
number.

5. Enter Demo invoice


retrieval in the Description: *
box.
Confirm your entry by pressing
the Enter key.

6. Click Finish .

32
Explanation Screenshot
A new editor will be
opened showing the created class.

7. Back in your report trigger


the syntax check using the
keyboard shortcut Ctrl+F2. The
syntax error should no longer
occur.

8. Create an instance of class


zcl_invoice_retrieval_NN using
the new operator.

9. Call the method


get_items_from_db to read
the items from the database.
This method does not yet exist
and we will create it with a
Quick Assist.

10. Position the cursor on the


name of the missing method
and press Ctrl+1. In the Quick
Fix menu double-click on
Create method
get_items_from_db.

11. Click Finish to confirm the


creation of
get_items_from_db as a
public method without
parameters.

33
Explanation Screenshot
12. A method definition and...

13. an empty method


implementation have been
created by the Quick Fix.

14. Add an ABAP Doc


comment to the newly created
method definition.

ABAP Doc comments can be used


to document APIs and are
displayed in the Element Info.
ABAP Doc comments begin with
"! .

15. Go to the SQL Console.

On the bottom left hand side of the


SQL console is the query section.
It contains the last executed select
statements as Open SQL
statements ready to be transferred
into your ABAP code.

16. Resize the query section


and copy the Open SQL
statement using the shortcut
Ctrl+C.

34
Explanation Screenshot
17. Paste the statement into
the method implementation of
get_items_from_db. Add the
ABAP statement terminator
(period character) at the end of
the statement to ensure that it
is syntactically correct.

18. Now is a good time to pretty


print the source code. Open the
Source menu and Click
Format. Alternatively use the
shortcut Shift+F1.

Since there are no formatting


settings defined for your user on
the ABAP server a dialog appears
which allows you to maintain these
settings.

19. Click on the link in the pop-


up
dialog to

This takes you to the


corresponding page in the
properties dialog of the project.

20. Click on the checkbox to


indent lines in your source
code.

21. Choose Custom as case


conversion methos and then
select your prefered code style
from the combobox e.g.:
Keywords uppercase,
identifiers lowercase.

22. Click Apply to activate


these settings.

23. Click OK to close the


Properties dialog.
35
Explanation Screenshot
24. Trigger
source formatting again by
pressing Shift+F1.

25. Use the shortcut Ctrl+D to


remove the UP TO 100 ROWS
addition.

26. Add some line breaks in the


join conditions to make the
select statement more
readable.

The method still doesn't deliver


any result data. You will now
execute a sequence of quick
assists to transform the inline
declared variable lt_result into a
fully typed returning parameter.

27. First position the cursor on


the inline declared
variable lt_result and press
Ctrl+1.

28. Select Declare local


variable lt_result
explicitlywith a double click in
the Quick Fix menu.

36
Explanation Screenshot

Wow! The local variable was


declared explicitly and a local
helper type was generated which
reflects the structure of our select
list containing the fields
company_name, gross_amount,
currency, and payment_status.

29. Position on the type name


helper_type and trigger
the Quick Fix proposals (
Ctrl+1 ).

30. In the Quick Fix menu


double-click on Convert
helper_type to class type.

The Quick Assist moved the


helper type from inside the method
implementation into the private
section. In order to use this type
for a parameter of your public
method get_items_from_db the
type should be moved into the
public section. Let's see if we can
find a Quick Assist for that.

31. Again put the cursor on the


type name helper_type and
press Ctrl+1.

32. In the Quick Fix


menu select Make helper_type
public with a double-click.

Now the helper_type has moved


into the public section and we can
transform the local
variable lt_result into a returning
parameter.

33. To do so place the cursor


on the variabe lt_result and
press Ctrl+1.

34. Double-click on Convert


lt_result to returning
parameter.

37
Explanation Screenshot

Note that the returning parameter


was added to the method and an
additional table type based on the
helper_type was generated.

35. ABAP Doc also offers the


possibility to document method
parameters and we have a
quick assist to do so. Place the
cursor inside of the ABAP Doc
comment. Then press Ctrl+1 to
open the Quick Fix menu and
double-click on Add missing
parameters to
documentation.

36. Add a proper text to


comment the parameter.

37. Activate the class by


clicking the activation
icon in the toolbar and go
back to your report.

38. Back in the report position


the cursor on the method call
get_items_from_db and Press
F2 to see the Element Info of
the method. In addition to the
method signature it also shows
the ABAP Doc you wrote
before.

39. Press ESC or click


somewhere in the editor to
close the Element Info.

40. Use a new inline declared


variable to receive the result of
the returning parameter.

Now you can display the invoice


items using the class
cl_salv_table.

41. Type cl_salv_table=> and

38
Explanation Screenshot
press Ctrl+Space to get code
completion proposals.

42. Click on the static


method factory and ...

43. Press Shift+Enter to insert


the full signature of the method
call.

If you prefer to insert the full


signature by default, you can
change the behaviour of the code
completion in the Preferences.
Select Window in the menu and
click on Preferences. In the
Preferences Dialog enter code
completion in the filter field or
open the following path ABAP
Development > Editors > Source
Code Editors > Code
Completion. In the Code
Complition settings you can
activate a checkbox to Always
insert full signature on
completion.

44. In the generated method


call...
• Remove the commented
importing parameters
list_display,
r_container, and
container_name using
the shortcut Ctrl+D
• Uncomment the
exporting parameter
r_salv_table using the
shortcut Ctrl+7 and
assign it to an inline
variable alv_table
• Assign the variable
invoice_items to the
changing parameter
t_table

Your method call should be the


same as the statement in the
screenshot.

39
Explanation Screenshot
45. Finally, call the display
method of alv_table.

46. Activate your report by


clicking the activation
icon in the toolbar or
using the keyboard shortcut
Ctrl+F3.

47. Run your report by


pressing F8.
48. The invoice items are
displayed in the SAP List
Viewer.

Notice that the payment status


can contain the internal codes
P or <SPACE>. In our case all
record have status <SPACE>.
Wouldn't it be better to display
more readable texts, e.g. Paid
and Open?
49. Go back to your invoice
retrieval class and adjust the
payment_status component of
the helper_type so that it can
hold 10 characters.

50. Add a loop in


the implementation part of the
method get_items_from_db
which transforms the values of
payment_status into readable
text.

51. Activate the class


by clicking or use the
shortcut Ctrl+F3.

40
Explanation Screenshot

52. Go back to your report by


clicking on the corresponding
editor tab and execute it by
pressing F8.

Check the result of your changes


in the SAP List Viewer.

Summary
You have completed the exercise!

You are now able to:


• Create an ABAP Project which represents a logon to your development system
• Use the Data Preview to look at the content in database tables and views
• Use the SQL Console to create and fine tune more complex select statements
• Create ABAP Programs and Classes
• Use Quick Assists via the shortcut for quick fixes Ctrl+1

41
5. Using Core Data Services

Overview
Estimated time: 30 minutes

Objective

In the following exercise you will learn how to use the new Core Data Services (CDS) tools in ABAP in
Eclipse. CDS is an extension of the ABAP Dictionary that allows you to define semantically rich data
models in the database and to use these data models in your ABAP programs. CDS is a central part
of enabling Code Pushdown in ABAP applications.

You will learn to define a new CDS view in a DDL source and to consume the CDS view in the SAP
List Viewer with Integrated Data Access (ALV with IDA). Using ALV with IDA it is possible to display
views and tables that contain very large quantities of data in the UI. You will also learn about some
of the CDS enhanced view-building capabilities such as associations and annotations.

You can find more information about CDS and ALV with IDA in the SAP Help Portal
(help.sap.com) and the SAP Community Network (scn.sap.com).

Exercise Description

• Create a CDS View


• Use the CDS View in ALV with IDA

Create a CDS View

Explanation Screenshot
1. In the context menu of your
Local Objects $TMP package
select New and then click
Other ABAP Repository
Object.

42
Explanation Screenshot
2. Enter ddl in the text field and
click Data Definition.

3. Click .

4. Check that $TMP is filled in


the Package:
* box.

5. Enter
Z_INVOICE_ITEMS_NN in the
Name: * box. Replace NN with
your user number.

Confirm your entry by pressing


the Tab key.

6. Enter Invoice items in the


Description: * box.

7. Click Next .

8. Click Next .

43
Explanation Screenshot
9. Select the Define View
template by clicking Define
View

10. Click Finish .

11. Enter
ZINVOICEITEMS_NN for the
SQL view name. Replace NN
with your user number.

The SQL view name is


the internal/technical name of the
view which will be created in the
database. Z_Invoice_Items_Nn is
the name of the CDS view which
provides enhanced view-building
capabilities in ABAP. You should
always use the CDS view name in
your ABAP applications.

Enter the CDS view


sepm_sddl_so_invoice_item as
the data source for your view. Use
the code completion to get
suggestions for the data source.

12. Enter sepm_sddl_so_inv


and use the keyboard shortcut
CTRL+SPACE to trigger the
code completion.

13. Double-click on

44
Explanation Screenshot

Use code completion to help you


add the fields to the select list. For
example, ent.er gross and use
the keyboard shortcut
CTRL+SPACE. Click on the field
gross_amount.

14. Add the fields


gross_amount and
currency_code to the select
list of the CDS view. The fields
must be separated by a
comma.
sepm_sddl_so_invoice_item.gr
oss_amount,
sepm_sddl_so_invoice_item.cu
rrency_code

CDS associations model the


relationships between data
sources. You can use associations
and path expressions to access
fields in related data sources
without specifying JOIN
conditions.

15. Display the Element Info for


the data source
sepm_sddl_so_invoice_item.
Position the cursor on the data
source name in the FROM
clause and press F2.

16. Scroll down to see the


related data sources which are
accessible via associations.
Click on the hyperlink
sepm_sddl_so_invoice_head
er to see details about the
target data source of the
association header.

17. Close the Element Info.


Press ESC.

45
Explanation Screenshot

Use the associations in path


expressions to add fields of related
data sources to the select list of
Z_Invoice_Items. Don't forget to
separate the fields with a comma.

18. Use the association header


to add the payment_status
from the invoice header to the
select list.
sepm_sddl_so_invoice_item.he
ader.payment_status

19. Use the associations


header and buyer in a path
expression to add the
company_name of the
business partner to the select
list.
sepm_sddl_so_invoice_item.he
ader.buyer.company_name,

20. Implement a case


statement to set the code of the
payment status to readable
text.
case
sepm_sddl_so_invoice_item.he
ader.payment_status
when 'P' then 'Paid'
else 'Open'
end as payment_status

21. Save the DDL source. Click


Save (Ctrl+S) .

22. Activate the DDL Source.


Click Activate (Ctrl+F3) .

46
Explanation Screenshot
23. Open the Data Preview for
your CDS view. Press F8.

The invoice items are displayed in


the Data Preview.

Use the CDS View in ALV with IDA

Explanation Screenshot
1. In the context menu of the
program
Z_INVOICE_ITEMS_EURO<N
N> click Duplicate....

47
2. Give the duplicated program
a name. Enter
Z_INVOICE_ITEMS_CDS_NN
in the field Name: *. Replace
NN with your user number.

3. Click Finish .

Replace the implementation of the


run method. Create an ALV with
IDA for your CDS View
Z_Invoice_Items_Nn (Nn
represents your user number) and
display the ALV with IDA in
fullscreen.
DATA(alv_display) =

cl_salv_gui_table_ida=>create_for
_cds_view(
'Z_INVOICE_ITEMS_NN' ).
alv_display->fullscreen( )->display(
).

4. Click Save (Ctrl+S) .

5. Click Activate (Ctrl+F3) .

6. Execute the program. Press


F8.

48
Explanation Screenshot

The invoice items are displayed in


ALV with IDA.

In the next steps we will filter the


results to only display items
with currency code EUR.

7. Click .

8. Select ISO Currency Code.


Add the column to the Filter
criteria. Click .

49
Explanation Screenshot
9. Set the filter values. Click
.

10. Enter EUR for the ISO


Currency Code filter criteria.

11. Click .

The filtered invoice items are


displayed in ALV with IDA.

Notice that the label for the


PAYMENT_STATUS column is
missing. We will fix this in the next
steps.

12. Close the application. Click


.

50
Explanation Screenshot
13. Click the [FXX]
Z_INVOICE_ITEMS_NN
tab to
open the DDL editor.

14. Insert the annotation


@EndUserText.label:
'Status' before the case
statement of the
field PAYMENT_STATUS.

Tip: Use code completion to


insert the annotation. Enter
@End and use the keyboard
shortcut CTRL+SPACE to
trigger the code completion.

15. Click Save (Ctrl+S) .

16. Click Activate


(Ctrl+F3) .

17. Click the [FXX]


Z_INVOICE_ITMES_CDS_<N
N>
tab.

18. Press F8 to execute the


program.

51
Explanation Screenshot

The PAYMENT_STATUS column


is displayed with the label 'Status'.

Summary
You have completed the exercise!

You are now able to:


• Create a CDS view in ABAP in Eclipse
• Use a CDS view in ALV with IDA

52
www.sap.com/contactsap

© 2018 SAP SE or an SAP affiliate company. All rights reserved.


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.

The information contained herein may be changed without prior notice. 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 are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated companies shall not be liable for errors or
omissions with respect to the materials. The only warranties for SAP 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, and
they should not be relied upon in making purchasing decisions.

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. All other product
and service names mentioned are the trademarks of their respective companies. See http://www.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.

You might also like