Contents
1 Remarks before you start............................................................... 3
2 The Scenario .................................................................................. 4
2.1
2.2
2.3
Description ..................................................................................... 4
Scenario Procedure ....................................................................... 4
Data model ..................................................................................... 4
2.3.1
2.3.2
2.3.3
2.4
SNWD_BPA .......................................................................................................... 5
SNWD_SO_INV_HEAD ......................................................................................... 5
SNWD_SO_INV_ITEM .......................................................................................... 5
3.1.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
Only relevant if your HANA Studio version is lower than 1.0.55 .......................... 6
6 Appendix ...................................................................................... 69
6.1
6.1.1
6.1.2
6.1.3
6.1.4
6.2
6.3
6.4
Edit .................................................................................................................... 69
Help ................................................................................................................... 69
Navigate ............................................................................................................ 69
Run, Debug ........................................................................................................ 69
Description
2 The Scenario
2.1 Description
The scenario you are going to implement is a part of the reference scenario delivered with
AS ABAP 7.40 SP2. It will give you an overview about different business figures based on
open invoices. Including the average number of days the invoices of a customer are open,
the sum of the amount of these open invoices (including currency conversion) and a flag set
by customization values to identify critical customers.
2.3.1 SNWD_BPA
This table contains all relevant data of the business partner for this scenario.
2.3.2 SNWD_SO_INV_HEAD
This is the header table of the invoices containing the BUYER_GUID, which is connected in
a 1:1 relation to the SNWD_BPA table.
2.3.3 SNWD_SO_INV_ITEM
The Invoices Item table containing all items of a invoice in different currencies. The
PARENT_KEY contains the SNWD_INV_HEAD-NODE_KEY connecting the item and
header table with a n:1 relation.
3 Technical Prerequisites
3.1.1 Only relevant if your HANA Studio version is lower than 1.0.55
Please use 2 different Eclipse Installation: The SAP HANA Studio itself as standalone and a
separate Eclipse Juno, version 4.2 or higher (http://www.eclipse.org/). The guide will always
show the process only with one eclipse. Please use SAP HANA Studio only for chapters
relevant with HANA configuration & development (Eclipse Views Modeler or Administration
Console).
2. Click on Add... to add the needed update Sites for the Plug-Ins.
Name
SAP DT Tools
Location
https://tools.hana.ondemand.com/juno
8. Last step for this chapter is to restart Eclipse if you are asked for.
2. Add the ABAP Perspective to access your ABAP System. Go to Menu: Window -> Open
Perspective -> Other
3. Add the ABAP Perspective to access your ABAP System by first clicking on ABAP and
afterwards on the OK Button
10
4. Now you can add your ABAP System by right clicking in the empty space of the project
explorer and choosing New -> ABAP Project in the context menu.
5. In the dialog window please insert the relevant data for your user and click Finish.
11
12
13
4. The transaction will generate the all data necessary to run the described scenario and
show you the benefit of the SAP HANA. We recommend you to run the data generation
as a background job because it takes a while to generate the data.
The values as shown on the screenshot will generate 1.000.000 Sales Orders with
approximately 6.000.000 Items, the according Invoices and the corresponding master
data. Feel free to edit the starting and end dates to your choice, but keep the dates in the
past to avoid strange results in your implementation.
Press F9 to execute the program as a background job or F8 or the execute button to
run the program directly (not recommend).
5. If you have chosen wisely to run it as a background job, just continue with the next dialog
window. ..
14
7. This is now the time to take a break and fetch a coffee or continue with the configuration.
15
9. You should wait until Status becomes Finished before continuing with Chapter 4 !
16
ICF Configuration
17
ICF Configuration
5. Repeat it for the UI5 Node (sap -> bc -> ui5_ui5 and press YES (with sub nodes)
6. Finally activate the Gateway node (default_host -> sap -> opu) also with sub nodes
18
19
5. Enter for your user the data as shown below and click Save
20
6. A dialog window will appear asking for a customizing request. Create a new request
8. Your new request should be entered in the request dialog. You can now continue.
21
9. The customizing values are saved and you can close the transaction.
22
23
24
To give you an overview how this scenario looks like and also show you how it would have
been done with classical ABAP without HANA, there is already a Class which calculates all
this figures and returns it as internal table.
1. If you are not already in the ABAP perspective please switch back to it.
2. To consume this internal table please create a new ABAP Program in your $TMP
package using the context menu in the project explorer on your $TMP Package.
25
4. You are creating a local object in the $TMP Package, so there is no need to specify a
transport request
5. The class cl_oia_vanilla_abap_prvdr already contains all relevant coding to return the data
for this scenario. You just have to consume this class in your report. Feel free to
investigate the class, if you are interested in the detailed coding. This will be the coding
you are going to push down to HANA.
The coding you see below will call the mentioned class and return the value in an ALV
grid.
Remark: Object Navigation in Eclipse is done by either moving the cursor o the object
and press Ctrl + F3 or CTRL + Left Click.
Code: Program calling classical ABAP Implementation
REPORT ZDEV_CLASSICAL_ABAP.
DATA lo_data_provider TYPE REF TO cl_oia_vanilla_abap_prvdr.
DATA lo_alv TYPE REF TO cl_salv_table.
DATA lo_err TYPE REF TO cx_salv_error.
CREATE OBJECT lo_data_provider.
DATA(lt_data) = lo_data_provider->read_bupa_figures( ).
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = lo_alv
CHANGING t_table
= lt_data ).
lo_alv->display( ).
CATCH cx_salv_error INTO lo_err.
MESSAGE lo_err TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
26
6. Press CTRL + F3 to activate the program and afterwards press the F8 key to run it. The
program will take a while to execute. The data is completely raw fetched into ABAP and
all calculations are done purely on the ABAP side. So if you are thirsty again -> This is
the chance to grab another coffee.
The result will look like this, but please keep in mind, that the open days are calculated
with your current date will have a higher value.
27
SAP HANA has offers different kind of views for different purpose. For this scenario the
calculation view is the view of choice.
Remark: A calculation view is used to define more advanced slices on the data in SAP HANA
database. Calculation views can be simple and mirror the functionality found in both attribute
views and analytic views. However, they are typically used when the business use case
requires advanced logic that is not covered in the previous types of information views. For
example, calculation views can have layers of calculation logic, can include measures
sourced from multiple source tables, can include advanced SQL logic, and so on. The data
foundation of the calculation view can include any combination of tables, column views,
attribute views and analytic views. You can create joins, unions, projections, and aggregation
levels on the sources.
1. Go to menu Window Open Perspective and add the Modeler perspective to your
Eclipse
28
2. Add the database to the tree on the left side via local menu Add System:
3. Add a new package in the Content -> system-local -> private Folder
29
4. Add the Name A4H as seen below and type a description of your choice
30
6. In the new dialog window type as Name BUPA_FIGURES, as View Type use SQL
Script and as Default Schema the schema of your ABAP System (so called SAP<SID>
schema). In our example it is the SAPH74.
Remark: The Default mapping will allow you to directly access tables in the View without
the need to add their schema in the front.
31
8. Next step is to add the desired output parameters to the view. For this right click on the
Output Pane and in the context menu click on Edit.
9. The Define Output dialog window appears. Here you can add all output attributes of this
script. A new row can be added by clicking on +.
32
10. Insert the Attributes with the data types as shown below. These are exactly the same
attributes as in our ABAP Implementation.
11. Now you have to create the real logic in HANA with SQL Script coding (For more
Information see 6.3 SAP HANA SQL Script Reference). The coding will be described in
multiple parts to help you understand it better. If you just want to copy and paste the
coding you can find it here: 6.4 Full SQL Script coding of Calculation View
BUPA_Figures.
12. First part is the Variable definition and variable initialization.
Code: Variable Definition
/********* Begin Procedure Script ************/
lv_client nvarchar(3);
lv_max_sum_gross_amount DECIMAL(15,2) := 0;
lv_max_avg_days_open DECIMAL(15,2) := 0;
lv_target_currency_code NVARCHAR(5);
lc_not_yet_paid nvarchar(1) := '';
33
13. Next part of the coding will read the customizing settings of the scenario into the defined
variables. It will also take advantage of existing session variables, which are filled by the
AS ABAP.
Code: Read Customizing
BEGIN
-- Read customizing
SELECT client, currency_code, max_Gross_amount, max_Days_open
INTO lv_client, lv_target_currency_code,
lv_max_sum_gross_amount, lv_max_avg_days_open
FROM sepm_oia_cust_t
WHERE CLIENT = SESSION_CONTEXT('CLIENT')
AND ID = SESSION_CONTEXT('APPLICATIONUSER');
14. This part will select the Invoices from the table, which are not yet paid in the table
lt_invoices.
Code: Select Open Invoices
-- The open invoices
lt_invoices = SELECT
inv_head.node_key AS invoice_guid,
inv_head.buyer_guid AS bupa_guid,
inv_head.gross_amount,
inv_head.currency_code
FROM snwd_so_inv_head AS inv_head
WHERE inv_head.client = :lv_client
AND inv_head.payment_status = :lc_not_yet_paid;
15. The next code snippet will take use of CE Functions in HANA and prepare the data for
the currency conversion, by selecting the invoice item data, providing the date field of the
invoice items in the needed format and joining variables.
Code: Select and prepare data for currency conversion
-- The invoices with their currency-converted amount
lt_invoice_items_unconverted = CE_COLUMN_TABLE(snwd_so_inv_item,
[node_Key, parent_key, gross_amount, currency_code ]);
lt_invoice_items_unconverted1 =
CE_PROJECTION(:lt_invoice_items_unconverted,
[node_key as item_guid, parent_key as invoice_guid, gross_amount,
currency_code,
CE_CALC('date(now())', DATE) as today]);
lt_invoice_head_created_at = CE_COLUMN_TABLE(snwd_so_inv_head,
[client, node_Key, payment_status, created_at]);
34
lt_invoice_head_created_at1 = CE_PROJECTION(:lt_invoice_head_created_at,
[client, node_Key as invoice_guid, payment_status, created_at],
'"CLIENT" = :lv_client AND "PAYMENT_STATUS" = ''''');
lt_invoice_items_unconverted_with_date =
CE_JOIN(:lt_invoice_items_unconverted1, :lt_invoice_head_created_at1,
[invoice_guid]);
16. Now the HANA business function of the currency conversions will be executed on the
prepared data and the result will be aggregated into a new table.
Code: Execute Currency Conversion
lt_invoice_items_converted =
CE_CONVERSION(:lt_invoice_items_unconverted_with_date,
[family = 'currency', method = 'ERP',
steps = 'shift,convert,shift_back',
target_unit = :lv_target_currency_code,
client = :lv_client,
source_unit_column = "CURRENCY_CODE",
reference_date_column = "TODAY",
output_unit_column = "CURRENCY_CODE_CONV"],
[gross_amount]);
lt_invoice_head_converted1 = CE_AGGREGATION(:lt_invoice_items_converted,
[SUM(gross_amount) AS gross_amount], [currency_code_conv,
invoice_guid]);
lt_invoice_amount_converted = CE_PROJECTION(:lt_invoice_head_converted1,
[invoice_guid AS invoice_guid1, gross_amount, currency_code_conv AS
currency_code]);
17. Next Data Selection will calculated the Open Days of the invoices using HANA built in
functions to prepare the data in format, that it can be consumed easily and does not need
to be transformed anymore.
Code: Calculating the Open Days of the invoices and Getting Businesspartner Data
-- Invoices with their age
lt_invoice_age = SELECT
inv_head.node_key AS invoice_guid,
inv_head.created_at AS created_at0,
to_timestamp(left(inv_head.created_at,14),'YYYYMMDDHHMISS') AS
created_at,
days_between(to_timestamp(left(inv_head.created_at,14),'YYYYMMDDHHMISS'),
to_timestamp(localtoutc(now(), 'CET'))) AS days_open,
FLOOR(seconds_between(to_timestamp(left(inv_head.created_at,14),'YYYYMMDDHHMISS'),
to_timestamp(localtoutc(now(), 'CET')))/(24*60*60)) AS full_days_open
FROM snwd_so_inv_head AS inv_head;
35
18. Last step is to join all the calculated and filled tables into the desired result, aggregate it
and set the reminder flag if the customizing values are exceeded.
Code: Calculating the Open Days of the invoices and Getting Business partner Data
-- Combine the elements to the result
lt_open_items = SELECT
inv.invoice_guid,
bupa.bupa_id,
bupa.company_name,
age.full_days_open AS days_open,
conv.gross_amount AS gross_amount_converted,
conv.currency_code AS currency_code_converted
FROM :lt_invoices AS inv
JOIN :lt_bupa AS bupa on inv.bupa_guid = bupa.bupa_guid
JOIN :lt_invoice_age AS age ON age.invoice_guid = inv.invoice_guid
JOIN :lt_invoice_amount_converted AS conv ON conv.invoice_guid1 =
inv.invoice_guid;
-- Do the aggregation
var_out =
SELECT bupa_id,
company_name,
AVG(days_open) AS avg_days_open,
currency_code_converted AS currency_code,
SUM(gross_amount_converted) AS sum_gross_amount,
CASE
WHEN SUM(gross_amount_converted) > :lv_max_sum_gross_amount
AND AVG(days_open) > :lv_max_avg_days_open
THEN 'X'
ELSE ' '
END AS customer_tagging
FROM :lt_open_items
GROUP BY bupa_id, company_name, currency_code_converted;
END /********* End Procedure Script ************/
36
19. On the Scenario Pane switch again back to Output. In the Details Pane you will see a
new Script View which is showing you the Output of your script. Now add the Output of
the script as attributes and measures to the Output of the view, by right clicking each field
and clicking Add as <type>. In the picture below the AVG_DAYS_OPEN as Measure.
Remark: Attributes and measures form the content data that is used for modeling. While
attributes represent the descriptive data like city and country, measures represent
quantifiable data like revenue and quantity sold.
20. Repeat this with each field available. See the screeshot below for Type of each field.
21. The Calculation view is now ready to be deployed. First you can validate the view to see if
everything works fine.
37
22. In the Job Log Tab you see the result of the validation
23. After successful validation, you can now activate the view
24. Again the Job Log will show you the result of your action.
25. You can also get a data preview of your created view, but this will lead to an error
because the view uses session variables, that are not populated. If you want to test the
view, replace the customizing code block with the following coding and activate the view
again. Please keep in mind to revert your change afterwards.
Code: Executable Customzing Block on HANA
SELECT client, currency_code, max_Gross_amount, max_Days_open
INTO lv_client, lv_target_currency_code, lv_max_sum_gross_amount,
lv_max_avg_days_open
FROM sepm_oia_cust_t
WHERE CLIENT = '001'
AND ID = 'DEV4CLONE';
38
Result
39
This part will show you how to make the just created Calculation view available in AS ABAP
and consume it with Open SQL.
7. If you are not already in the ABAP perspective please switch back to it.
8. First step is to create the DDIC representation of the view. This is entity is called the
external view. Right click on your $TMP Package and click Other ABAP Repository
Object
40
10. In the next Dialog enter as Name for the View ZDEV_BUPA_FIGU_V and a description.
Change to External View, in the field HANA View type BU and press CTRL +
SPACE. Select your view and click NEXT.
41
14. Now we will consume the view in a program to see how it works to select the data and get
the result to the screen. First step is to create a new Program.
42
17. In the code you need to create an internal table based on the data structure of the
created view and then you can use well known ABAP Open SQL to consume the data
and map it to an ALV Grid.
Code: ABAP Program consuming External View
REPORT ZDEV_CALC_VIEW.
DATA lo_alv TYPE REF TO cl_salv_table.
DATA lo_err TYPE REF TO cx_salv_error.
DATA lt_data TYPE standard table of zdev_bupa_figu_v.
SELECT * FROM zdev_bupa_figu_v INTO TABLE lt_data.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = lo_alv
CHANGING t_table
= lt_data ).
lo_alv->display( ).
CATCH cx_salv_error INTO lo_err.
MESSAGE lo_err TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
43
With the SAP NetWeaver Gateway you can easily create a ODAA Service to expose your
data via XML or JSON. This part will show you how to expose the created External View
within an ODATA Service.
20. Create a new Project in Eclipse. This is a local folder in which files are stored.
21. A new Dialog window will appear. Use as Project Name My_OData_Model and click
Finish.
22. Your new project should appear in the Project Explorer. You now need to create an
ODATA Service Model in the project to define your service. Right click on your project
and in the context menu select New -> Other.
44
24. As Model Name use A4H_DEMO, select Blank Service as Initial model content and click
Finish.
45
25. On the right side you see the Palette. Select Entity Type and left click in the grid. A new
Entity Type will appear. Name it ZDEV_DEMO_SRV. A Key property with the same
name is also generated.
26. Rename the Entity Set to Results by selecting it first and afterwards click it again. You
can also use the property tab on the bottom in your Eclipse. Also rename the Key
Property to BupaId.
46
27. In the Property tab also change the Max Length of the data type (default Edm.String).to
10.
28. Hover over your Entity Set and a small pane will appear next to it. Click on the add
Property Button in it.
29. Add the Properties of these tables and adapt the data type, precision and scale as seen
in the this table
Property
Data Type
Max Length
Precision
Scale
BupaId
Edm.String
10
CompanyName
Edm.String
80
AvgDaysOpen
Edm.Int32
CurrencyCode
Edm.String
SumGrossAmount
Edm.Decimal
CustomerTagging
Edm.String
3
17
47
30. When you are finished the screen should look like this
48
33. In the dialog window select OData Develpopment->OData Model and click Next.
49
34. In the Export As filed specify a folder of your choice, name the file A4HDemo.xml and
click Finish.
35. Press Run ABAP Development Object Button or press ALT + F8.
36. Type SEGW. This is the main transaction for SAP NetWeaver Gateway.
37. Click on New
and as Project is ZDEV_DEMO_SRV, as Generation Strategy
Standard and click on Local Object.
38. Your Project is created. Now you can import your created Model by using the context
menu on on Data Model and then click Data Model from File.
50
39. Choose the folder and file you gave exported in step 35.
51
41. In the Entity Sets Folder, click on Results and remove the flag for requires filter.
42. Now you can generate the Runtime Objects of the Service. In the top menu click
52
53
46. Next step is to register the service to the ICF. Use the tree on the left and double click on
Service Maintenance and afterwards on register.
47. You can continue with the warning message by clicking on Yes.
48. Next step is specifying a system alias where the service should be deployed. The service
should run on our system, so you can type LOCAL.
49. In the new dialog click on LOCAL button and continue. The service is now registered and
activated in the ICF.
54
50. Final Step is to do the Service Implementation. The Gateway framework will initially call
the GetEntitySet Method to retrieve the data. To implement this right click on
GetEntitySet (Query) and Click Go to ABAP Workbench.
55
52. The Implementation is simple. Select the data from your external view into the exporting
internal table of the generated gateway service implementation and you are done.
Code: Definition of Service Provider Class for Gateway Service
CLASS ZCL_ZDEV_DEMO_SRV_DPC_EXT IMPLEMENTATION.
METHOD results_get_entityset.
CLEAR: es_response_context, et_entityset.
TRY.
53. Save
and activate
the implementation.
54. The service is no ready. In the next step you will test the service. Press Run ABAP
Development Object Button or press ALT + F8.
55. Type SICF to get to the ICF Transaction. Here you can directly test the Service.
56. In the field Service Name type OPU and click on Execute int the selection screen
56
57. Goto default_host -> sap -> opu -> odata ->sap and right click zde_demo_srv_srv
58. In the context menu click test service In the Message screen allow the access to this
file. The ODATA Meta.xml should appear in the browser.
Remark: Internet Explorer might have some problems with the document type and will try
to download it. If his is the case, you can open it with a XML Editor or the notepad to see
the Document.
59. If you want to see the data results, add to the URL of the service in the browser
<yourServer:yourPort>/sap/opu/odata/sap/zdev_demo_srv_srv/Results?sapclient=<yourclient>
57
Last part of this guide will show you how to model a SAP UI5 Page consuming the created
ODATA Service and showing the result on your browser.
1. Open the context menu in the Project Explorer Tab of your Eclipse and click New
Project
58
4. The next dialog is to select the Gateway Service for your Project. Click on Catalog
59
5. In the new dialog window click on Manage Connections and in the next window on
Add.
6. Type in a Name for your connection and fill the Fields with the server details of your AS
ABAP ICF and your current development user. Press OK when you are finished.
7. Select the Name of your Connection, choose the Service ZDEV_DEMO_SRV_SRV and
press OK again.
60
8. Click on Finish
9. Type view Title MyResult and click the right + to add Fields.
61
11. If you like you can sort the fields as you want them to appear. If you are ready you can
click Finish and your Project is ready on your local drive.
62
12. Next step is to connect the local Project to your AS ABAP. In the Project Explorer richt
click on the Team->Share Project entry.
63
14. Specify your ABAP System and type your user name & password
64
15. Choose Create a new BSP Application, specify the data as shown on the screen and
click Next.
Remark: This is no BSP Application. Just the repository of the BSP is used to store your
UI5 Application. It is not possible to use BSP in it.
65
16. You have connected your local development to the BSP Repository. Click Finish.
17. The last step is to submit the local project to the ABAP Repository. Right click your
project and click Team -> Submit
66
19. Finally to open the webpage press Run ABAP Development Object Button or press
ALT + F8
67
23. Your SAPUI5 page is displayed in the browser and should look like this
congratulations!
Thanks a lot for trying out our E2E guide. We hope you enjoyed implementing it and we
could give you a small insight in the power of SAP NetWeaver 7.4 combined with SAP
HANA. And of course feedback is highly appreciated.
68
ADT Shortcuts
6 Appendix
6.1 ADT Shortcuts
6.1.1 Edit
Ctrl+Shift+A Open development object
Ctrl+F2 Check development object
Ctrl+F3 Activate development object
Ctrl+Shift+F3 Activate all inactive objects
Ctrl+Space Code completion
Ctrl+1 Quick fix proposal
Ctrl+< Add comment
Ctrl+Shift+< Remove comment
Shift+F1 Format source aka pretty printer
6.1.2 Help
F1 ABAP keyword documentation
F2 Show code element information
Ctrl+3 Search for commands & views
Ctrl+Shift+L List all keyboard shortcuts
6.1.3 Navigate
F3 Open definition
Alt+Left Backward history
Alt+Right Forward history
Ctrl+T Quick hierarchy
F4 Open Type Hierarchy
Ctrl+O Quick outline
Ctrl+Shift+G Where-used list
69
70
71
age.full_days_open AS days_open,
conv.gross_amount AS gross_amount_converted,
conv.currency_code AS currency_code_converted
FROM :lt_invoices AS inv
JOIN :lt_bupa AS bupa on inv.bupa_guid = bupa.bupa_guid
JOIN :lt_invoice_age AS age ON age.invoice_guid = inv.invoice_guid
JOIN :lt_invoice_amount_converted AS conv ON conv.invoice_guid1 =
inv.invoice_guid;
-- Do the aggregation
var_out =
SELECT bupa_id,
company_name,
AVG(days_open) AS avg_days_open,
currency_code_converted AS currency_code,
SUM(gross_amount_converted) AS sum_gross_amount,
CASE
WHEN SUM(gross_amount_converted) > :lv_max_sum_gross_amount
AND AVG(days_open) > :lv_max_avg_days_open
THEN 'X'
ELSE ' '
END AS customer_tagging
FROM :lt_open_items
GROUP BY bupa_id, company_name, currency_code_converted;
END /********* End Procedure Script ************/
72
www.sap.com