Anda di halaman 1dari 73

End to End Development Example in

SAP NetWeaver 7.4 & SAP HANA


SAP NetWeaver 2013 - Developer Experience III
Author: Jens Weiler jens.weiler@sap.com
Target Audience
Developer
Consultants

For Public usage


Document version 1.00 May 9th, 2013

Installation Guide: ABAP Development Tools for SAP NetWeaver

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

Full Reference Application ........................................................... 5

3 Technical Prerequisites .................................................................. 6


3.1

Install SAP HANA Studio .............................................................. 6

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

Install needed Eclipse Plug-Ins .................................................... 6


Enter system in SAP Logon.......................................................... 9
Adding your system to the ABAP Development Tools .............. 9
Generate Example Data............................................................... 13
ICF Configuration ........................................................................ 17
Customizing for the Scenario ..................................................... 19
Customizing for UI5 & Gateway Services ................................. 23

4 Classical ABAP Implementation .................................................. 25


5 ABAP & HANA Implementation ................................................... 28
5.1
5.2
5.3
5.4

SAP HANA Calculation View ...................................................... 28


ABAP External view..................................................................... 40
SAP NetWeaver Gateway Service .............................................. 44
SAP UI5 Implementation ............................................................. 58

6 Appendix ...................................................................................... 69
6.1

ADT Shortcuts .............................................................................. 69

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

SAP HANA Development Guide ................................................. 70


SAP HANA SQL Script Reference .............................................. 70
Full SQL Script coding of Calculation View BUPA_Figures .... 70

1 Remarks before you start


This demo can be executed on an SAP NetWeaver AS ABAP 7.4 running on a SAP
HANA database SPS5 or higher.
All screenshots have been made in a AS ABAP System with SID A4H installed in
the HANA Database Schema SAPH74. Please consider to adapt this based on the
SID and schema of your System.
All ABAP Entities have been created in the $TMP Package of the user
DEV4CLONE.
All HANA Entities have been created in the HANA Package system-local.A4H and the
user SYSTEM.
You will need users on SAP NetWeaver AS ABAP and SAP HANA.
o AS ABAP users need to have at least the following role assigned:
SAP_BC_DWB_ABAPDEVELOPER
SAP_BC_DWB_WBDISPLAY
/IWFND/RT_DEVELOPER (For Gateway Service Development)
o HANA User needs the HANA Role ABAP_DEV.
The screenshots have been created based on HANA Studio for SAP HANA SPS5
and can differ with respect to other HANA releases.
For more details, information and guides based on SAP NetWeaver AS ABAP and
SAP HANA please visit our SCN Page: http://scn.sap.com/docs/DOC-35518

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.2 Scenario Procedure

2.3 Data model


The data model you will be using consists of 3 tables. Each table has a primary key
(datatype GUID) called NODE_KEY together with CLIENT.

Full Reference Application

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.

2.4 Full Reference Application


The scenario described here is just a part of the full reference application, showing you more
details how ABAP on HANA can be leveraged. For more details start Transaction
SEPM_OIA in your AS ABAP.

Install SAP HANA Studio

3 Technical Prerequisites

3.1 Install SAP HANA Studio


The HANA Studio Installer is available with your SAP HANA Installation DVD or through the
Service Market Place. Please keep in mind to always use the version of the SAP HANA
Studio corresponding to the installed version of your SAP HANA Database. HDBSetup.exe
can be started with parameters -a studio for installing only the SAP HANA Studio. The
HANA version must be least 1.0.55 in order to install the following Plug-Ins.
Important Remark: If you install your SAP HANA Studio or Eclipse in the Program Files
Folder you must always run it with Administrator Privileges. We would advise to not install it
under this folder.
If your version is 1.055 or higher you can continue with 3.2 and ignore the next paragraph.

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).

3.2 Install needed Eclipse Plug-Ins


1. Open SAP HANA Studio and in the Help menu open the entry Install new Software

2. Click on Add... to add the needed update Sites for the Plug-Ins.

Install needed Eclipse Plug-Ins

3. Add the listed updatesite to your Repository.

Name
SAP DT Tools

Location
https://tools.hana.ondemand.com/juno

4. Check the following Plug-Ins according to the screenshot below

Install needed Eclipse Plug-Ins

5. The next screen shows a summary of Plug-Ins - just click next.

6. Accept the terms of the license agreements and click Finish.

7. Please press OK if one or two Security Warning appears

8. Last step for this chapter is to restart Eclipse if you are asked for.

3.3 Enter system in SAP Logon


To add a ABAP System to the ABAP Development Tools you need to create the entry for
your system in the SAP Logon.
1. Open SAP Logon
2. Click New System

3. Add your System and Finish

3.4 Adding your system to the ABAP Development Tools


1. Start SAP HANA Studio and click on Workbench if the overview screen shows up.

Adding your system to the ABAP Development Tools

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

Adding your system to the ABAP Development Tools

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.

6. Your system will now appear in the project explorer.

11

Adding your system to the ABAP Development Tools

3.4.1 [Optional] Pretty Printer Settings


1. If you want to use PrettyPrinter (Shift + F1). Right Click in the Project Explorer on your
newly created system and click on Properties in the context menu.
2. In the Properties Screen select ABAP Development -> Editors -> Source Code
Editors -> Formatter and select the Options as shown below

12

Generate Example Data

3.5 Generate Example Data


1. If you are not already in the ABAP perspective please switch back to it.

2. Press Run ABAP Development Object Button or press ALT + F8

3. Type in SEPM_DG_OIA and press OK.

13

Generate Example Data

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

Generate Example Data

6. press Immediate button and press the save button afterwards

7. This is now the time to take a break and fetch a coffee or continue with the configuration.

15

Generate Example Data

8. . You can check the background job with transaction SM37

9. You should wait until Status becomes Finished before continuing with Chapter 4 !

16

ICF Configuration

3.6 ICF Configuration


For SAP Gateway services, SAP UI5 and ABAP Docu you will need to activate special nodes
on the ABAP ICF Server.
1. Press Run ABAP Development Object Button or press ALT + F8

2. Type the transaction SICFand press OK

3. In the opened search screen just press execute

17

ICF Configuration

4. Activate the Service for ABAP Docu (sap -> bc ->docu)

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

Customizing for the Scenario

3.7 Customizing for the Scenario


The scenario also features a customizing table. To be able to run the scenario a customizing
must be entered for your ABAP User.
1. Press Run ABAP Development Object Button or press ALT + F8

2. Open the transaction SEPM_OIA_CUST

19

Customizing for the Scenario

3. Switch to edit mode

4. Add a new entry

5. Enter for your user the data as shown below and click Save

20

Customizing for the Scenario

6. A dialog window will appear asking for a customizing request. Create a new request

7. add a short description of your choice and click Save.

8. Your new request should be entered in the request dialog. You can now continue.

21

Customizing for the Scenario

9. The customizing values are saved and you can close the transaction.

22

Customizing for UI5 & Gateway Services

3.8 Customizing for UI5 & Gateway Services


Remark:

You will be requested for a Customizing transport during the configuration


steps. Just use the already created transport from the last step.

1. Press Run ABAP Development Object Button or press ALT + F8.

2. Type the transaction SPRO and press OK.


3. Click on the Button SAP Reference IMG.
4. Open the Folders as shown here

5. Click on Activate or Deactivate SAP NetWeaver Gateway.


6. In the dialog window press activate,
7. Click back in the menu or press F3.

8. Click on Manage SAP System Aliases.


9. In the new screen press New Entries
10. Insert the values as shown below

11. Click back in the menu or press F3.

23

Customizing for UI5 & Gateway Services

12. Next steps is Create RFC Destination for Outbound Queues


13. In the configuration screen click create
14. Insert the values as shown below and click the save button

15. Click two times back in the menu or press F3.


16. Now you need to configure the SAP NetWeaver Gateway Settings.
17. Click New Entries and enter the values.
Remark: For Field Destination system use the hostname of your system

18. Click the Save Button

24

Customizing for UI5 & Gateway Services

4 Classical ABAP Implementation

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.

3. In the dialog window use as Name: ZDEV_CLASSICAL_ABAP and type a description.

25

Customizing for UI5 & Gateway Services

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

Customizing for UI5 & Gateway Services

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 Calculation View

5 ABAP & HANA Implementation


You have seen the program with the result in ABAP and it took a while to execute. Now you
are going to speed this up by pushing the logic in the HANA database and consume the
generated HANA view in ABAP. First step is to create a HANA view.

5.1 SAP HANA Calculation View

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

SAP HANA Calculation View

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

SAP HANA Calculation View

4. Add the Name A4H as seen below and type a description of your choice

5. Add a New Calculation View

30

SAP HANA Calculation View

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.

7. In the newly created View press Script in the scenario pane.

31

SAP HANA Calculation View

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

SAP HANA Calculation View

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

SAP HANA Calculation View

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

SAP HANA Calculation View

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

SAP HANA Calculation View

-- The business partners


lt_bupa = SELECT
node_key AS bupa_guid,
bp_id AS bupa_id,
company_name,
3 AS rank
FROM snwd_bpa;

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

SAP HANA Calculation View

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

SAP HANA Calculation View

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';

Press Data Preview

38

SAP HANA Calculation View

Press Raw Data

Result

39

ABAP External view

5.2 ABAP External view

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

ABAP External view

9. Type view, select the Dictionary View and click Next.

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

ABAP External view

11. Again a local object - no transport is required. Click Finish.


12. After the wizard has finished you will get an overview screen showing all Fields of the
view and the mapped DDIC Types for the HANA Types of the underlying Calculation
View.

13. By clicking the activate button

the View is activated and now fully available in ABAP.

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.

15. Name it ZDEV_CALC_VIEW, type a description and click Next.


16. Once more a local object - no transport is required. Click Finish.

42

ABAP External view

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.

18. Activate the View


and press F8 to execute the Program.
19. Now you can run both reports after each other to feel the different performance.

43

SAP NetWeaver Gateway Service

5.3 SAP NetWeaver Gateway Service

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

SAP NetWeaver Gateway Service

23. SELECT OData Development -> OData Model

24. As Model Name use A4H_DEMO, select Blank Service as Initial model content and click
Finish.

45

SAP NetWeaver Gateway Service

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

SAP NetWeaver Gateway Service

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

SAP NetWeaver Gateway Service

30. When you are finished the screen should look like this

31. Save your Model l


.
32. The next step is to export your modeled EntitySet and import it into the ABAP Gateway
Service. Right click on your A4H_Demo File in the Project Explorer and choose Export.

48

SAP NetWeaver Gateway Service

33. In the dialog window select OData Develpopment->OData Model and click Next.

49

SAP NetWeaver Gateway Service

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

SAP NetWeaver Gateway Service

39. Choose the folder and file you gave exported in step 35.

51

SAP NetWeaver Gateway Service

40. The model is now imported successful.

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

SAP NetWeaver Gateway Service

43. Keep the suggested names and continue.

44. Click Local Object


45. In the message tab you will get the information about the status of the generation.

53

SAP NetWeaver Gateway Service

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

SAP NetWeaver Gateway Service

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.

51. In the definition of the class redefine the method results_get_entityset


Code: Definition of Service Provider Class for GatewaySerive
CLASS zcl_zdev_demo_srv_dpc_ext DEFINITION
PUBLIC
INHERITING FROM zcl_zdev_demo_srv_dpc
CREATE PUBLIC .
PUBLIC SECTION.
PROTECTED SECTION.
METHODS results_get_entityset REDEFINITION .
PRIVATE SECTION.
ENDCLASS.

55

SAP NetWeaver Gateway Service

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.

SELECT bupa_id AS bupaid


company_name AS companyname
avg_days_open AS avgdaysopen
currency_code AS currencycode
sum_gross_amount AS sumgrossamount
customer_tagging AS customertagging
FROM zdev_bupa_figu_v
INTO CORRESPONDING FIELDS OF TABLE et_entityset.

CATCH cx_oia_data_provider INTO DATA(lo_cx).


RAISE EXCEPTION TYPE /iwbep/cx_mgw_tech_exception EXPORTING previous
= lo_cx.
ENDTRY.
ENDMETHOD.
ENDCLASS.

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

SAP NetWeaver Gateway Service

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

SAP UI5 Implementation

5.4 SAP UI5 Implementation

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

2. Type in a project name, choose HTML5 and click next.

58

SAP UI5 Implementation

3. In the next screen choose List/Details Application (SAPUI5)

4. The next dialog is to select the Gateway Service for your Project. Click on Catalog

59

SAP UI5 Implementation

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

SAP UI5 Implementation

8. Click on Finish

9. Type view Title MyResult and click the right + to add Fields.

61

SAP UI5 Implementation

10. Select all Fields and click OK

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

SAP UI5 Implementation

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.

13. In the dialog window click on SAPUI8 ABAP Repository

63

SAP UI5 Implementation

14. Specify your ABAP System and type your user name & password

64

SAP UI5 Implementation

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

SAP UI5 Implementation

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

18. Click on Select all and Finish

66

SAP UI5 Implementation

19. Finally to open the webpage press Run ABAP Development Object Button or press
ALT + F8

20. Type the transaction SICFand press OK

21. Service Name ui5_ui5 and Execute (F8).


22. Navigate to default_host -> sap-> bc -> ui5_ui5 -> sap -> ZDEV_UI5_EXP and right click
->test Service.

67

SAP UI5 Implementation

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

6.1.4 Run, Debug


F8 Run current ABAP object
Alt+F8 Select & run ABAP application
Ctrl+Shift+B Toggle breakpoint
F5, F6, F7, F8 Step into, over, return, resume

69

SAP HANA Development Guide

6.2 SAP HANA Development Guide


http://help.sap.com/hana/hana_dev_en.pdf

6.3 SAP HANA SQL Script Reference


http://help.sap.com/hana/hana_dev_sqlscript_en.pdf

6.4 Full SQL Script coding of Calculation View


BUPA_Figures
/********* Begin Procedure Script ************/
-- Variable Definition
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) := '';
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');
-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';
-- 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;
-- 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,

70

Full SQL Script coding of Calculation View BUPA_Figures

[client, node_Key, payment_status, created_at]);


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]);
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]);
-- 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;
-- The business partners
lt_bupa = SELECT
node_key AS bupa_guid,
bp_id AS bupa_id,
company_name,
3 AS rank
FROM snwd_bpa;
-- Combine the elements to the result
lt_open_items = SELECT
inv.invoice_guid,
bupa.bupa_id,
bupa.company_name,

71

Full SQL Script coding of Calculation View BUPA_Figures

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

2013 SAP AG. All rights reserved.


SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP
BusinessObjects Explorer, StreamWork, SAP HANA, and other SAP
products and services mentioned herein as well as their respective
logos are trademarks or registered trademarks of SAP AG in Germany
and other countries.
Business Objects and the Business Objects logo, BusinessObjects,
Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and
other Business Objects products and services mentioned herein as
well as their respective logos are trademarks or registered trademarks
of Business Objects Software Ltd. Business Objects is an SAP
company.
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL
Anywhere, and other Sybase products and services mentioned herein
as well as their respective logos are trademarks or registered
trademarks of Sybase Inc. Sybase is an SAP company.
Crossgate, m@gic EDDY, B2B 360, and B2B 360 Services are
registered trademarks of Crossgate AG in Germany and other
countries. Crossgate is an SAP company.
All other product and service names mentioned are the trademarks of
their respective companies. Data contained in this document serves
informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials
are provided by SAP AG and its affiliated companies ("SAP Group")
for informational purposes only, without representation or warranty of
any kind, and SAP Group shall not be liable for errors or omissions
with respect to the materials. The only warranties for SAP Group
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.

Anda mungkin juga menyukai