0% found this document useful (0 votes)
361 views13 pages

Access SAP HANA Via A Secondary Database Connection

The document describes how to access data from SAP HANA using a secondary database connection in ABAP. It involves copying a template program, identifying the secondary database connection to SAP HANA, and editing the program to use Open SQL statements with the CONNECTION addition to read from tables in SAP HANA instead of the primary database. The key steps are to define a constant for the database connection name, copy the subroutine that retrieves data, and modify the SELECT statements within it to use the secondary connection to SAP HANA.

Uploaded by

Esther Vizarro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
361 views13 pages

Access SAP HANA Via A Secondary Database Connection

The document describes how to access data from SAP HANA using a secondary database connection in ABAP. It involves copying a template program, identifying the secondary database connection to SAP HANA, and editing the program to use Open SQL statements with the CONNECTION addition to read from tables in SAP HANA instead of the primary database. The key steps are to define a constant for the database connection name, copy the subroutine that retrieves data, and modify the SELECT statements within it to use the secondary connection to SAP HANA.

Uploaded by

Esther Vizarro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Access SAP HANA Via a Secondary

Database Connection
Copy and Understand Templates

In SAP GUI, log on to system ZME, which uses Sybase as its primary database, and start
the
ABAP Workbench. Create a copy of report HA400_SEC_DB_CON_T1 in your package
ZHA400_## (suggested name: ZHA400_##_SEC_DB_1, where ## is your group number).
Analyze the program code to get an idea of its functionality. Activate and execute the
program.
1. If you are not still logged in, log on to the system labelled ZME on Sybase and start the
ABAP workbench (transaction SE80).
a) Perform this step as in previous exercises.
2. Create a copy of the report. Place it in your package ZHA400_## and assign it to your
workbench request.
Hint:
Make sure to mark Screens and User Interface in the Copy Program dialog
step.
a) Start the ABAP Workbench (for example, using transaction code SE80).
b) In the toolbar, choose Edit Object ... (Shift-F5).
c) Enter development object HA400_SEC_DB_CON_T1.
d) Choose Copy (CTRL-F5).
e) Enter the target program name, ZHA400_##_SEC_DB_1, where ## is your group
number, and choose Copy.
Analyze a Secondary Database Connection

Look for a secondary database connection that points to the SAP HANA server. Find out
which tables can be accessed with Open SQL via this connection.
1. Look up the secondary database connections that have been maintained in your SAP
NetWeaver Application Server for ABAP.
a) Start transaction DBACOCKPIT.
b) In the navigation area on the left, choose Database Connections.
2. Find a database connection that points to your SAP HANA server and note the database
user and connection name.
a) To find all database connections that point to an SAP HANA database, in the list on the
right, expand the SAP HANA database node.
b) Find the connection with the correct server in the DB Host column.
3. The connection name is(1) HANADB and the database user for the SAP HANA server is
REPZME(2).

4. Go to the SAP HANA Modeler perspective in Eclipse and open the schema with the same
name as the user in the database connection.
a) In Eclipse, open perspective SAP HANA Modeler.
b) In the navigation window on the left, choose Catalog → REPZME.

5. Look for the tables you find in this schema. Those are the ones you can access via the
secondary database connection using Open SQL.
Hint:
Tables starting with DD0 and RS_ are technical objects and should not be
considered here. They are used by the mechanism that replicates data from
primary to secondary databases. Tables starting with SNWD belong to the
Enterprise Procurement model which is not used in this training.
a) Under the REPZME schema, expand the tables node.
6. Which tables are of interest to the application programmer?
MARA, SBOOK, SCARR, SCUSTOM, SFLIGHT, SPFLI, STRAVELAG
7. Verify for at least one table that the definition in the SAP HANA database is identical to
the
definition in the primary database.
a) To see the list of fields, double-click one of the tables, their SQL data types, and
dimensions.
b) On the SAP NetWeaver Application Server for ABAP, open the definition of this table in
the ABAP Dictionary (transaction SE11 or SE80).
c) To see the definition of this table on the primary database, from the menu, choose
Utilities → Database Object → Display.
Access SAP HANA

Edit your program. Copy the source code of subroutine get_data_template to subroutine
get_data_solution. In subroutine get_data_solution, make sure all SELECT-statements read
from SAP HANA instead of the primary database.
In all select statements of subroutine get_data_solution, read from SAP HANA rather than
the
primary database.
1. Edit your program ZHA400_##_SEC_DB_1. Copy the source code of subroutine
get_data_template to subroutine get_data_solution.
a) Use the Copy & Paste functions of the ABAP Editor to copy the source code of
subroutine get_data_template to subroutine get_data_solution.
2. In subroutine get_data_solution, search for all SELECT-statements and use the
CONNECTION addition to access the secondary database rather than the primary
database.
Hint:
Instead of hard coding the connection, it is recommended that you define a
constant of type dbcon_name (ABAP Dictionary data element).

a) See the source code extract from the model solution.


3. Activate and test your program.
a) Complete this step as you learned to do in previous classes.

b) Verify that your code matches the following solution:

Source code extract from model solution (Program HA400_SEC_DB_CON_S1)


*&--------------------------------------------------------------------*
*&
Form get_data_template
*&--------------------------------------------------------------------*
FORM get_data_template CHANGING ct_customers TYPE ty_t_customers.
* Declarations
****************
* Work Area for Result
DATA ls_customer LIKE LINE OF ct_customers.
* Targets for Select
DATA: ls_scustom TYPE scustom,
ls_sbook TYPE sbook.
* help variables
DATA lv_count TYPE i.
* Processing
*****************
CLEAR ct_customers.
SELECT * FROM scustom
INTO ls_scustom.
ls_customer-id = ls_scustom-id.
ls_customer-name = ls_scustom-name.
ls_customer-postcode = ls_scustom-postcode.
ls_customer-city = ls_scustom-city.
ls_customer-country = ls_scustom-country.
CLEAR ls_customer-days_ahead.
CLEAR lv_count.
SELECT * FROM sbook
INTO ls_sbook
WHERE customid = ls_scustom-id
AND cancelled = space.
ls_customer-days_ahead = ls_customer-days_ahead
+ ( ls_sbook-fldate
- ls_sbook-order_date ).
lv_count = lv_count + 1.
ENDSELECT.
IF lv_count <> 0.
ls_customer-days_ahead = ls_customer-days_ahead / lv_count.
INSERT ls_customer INTO TABLE ct_customers.
ENDIF.
ENDSELECT.

SORT ct_customers BY id.


ENDFORM. "
*&---------------------------------------------------------------------
*
*& Form get_data_solution
*&--------------------------------------------------------------------*
FORM
get_data_solution CHANGING ct_customers TYPE ty_t_customers.
* Declarations
****************
* Database connection
CONSTANTS lc_con TYPE dbcon_name VALUE 'HANADB'.
* Work Area for Result
DATA ls_customer LIKE LINE OF ct_customers.
* Targets for Select
DATA: ls_scustom TYPE scustom,
ls_sbook TYPE sbook.
* help variables
DATA lv_count TYPE i.
* Processing
*****************
CLEAR ct_customers.
SELECT * FROM scustom
CONNECTION (lc_con)
INTO ls_scustom.
ls_customer-id = ls_scustom-id.
ls_customer-name = ls_scustom-name.
ls_customer-postcode = ls_scustom-postcode.
ls_customer-city = ls_scustom-city.
ls_customer-country = ls_scustom-country.
CLEAR ls_customer-days_ahead.
CLEAR lv_count.
SELECT * FROM sbook
CONNECTION (lc_con)
INTO ls_sbook
WHERE customid = ls_scustom-id
AND cancelled = space.
ls_customer-days_ahead = ls_customer-days_ahead
+ ( ls_sbook-fldate
- ls_sbook-order_date ).
lv_count = lv_count + 1.
ENDSELECT.
IF lv_count <> 0.
ls_customer-days_ahead = ls_customer-days_ahead / lv_count.
INSERT ls_customer INTO TABLE ct_customers.
ENDIF.
ENDSELECT.
SORT ct_customers BY id.
ENDFORM. "

You might also like