Skip to Content

If you’re already started developing ABAP on SAP HANA or if you’re planing on doing so, then you’ll soon ask yourself; “How do I consume my HANA artifacts in ABAP?”. Once you’ve figured that one out and you’ve been baptised in the fire of native SQL, you’ll probably ask yourself; “Isn’t there an easier way?”. Well, there is!

SAP has made SAP NetWeaver 7.4 and the ABAP Development Tools 2.7 generally available (GA) to its customers. As promised, SAP NetWeaver 7.4 has been optimized for SAP HANA. This includes new features to easily consume existing HANA artifacts in your ABAP code.

Let’s give you an idea of how it’s done!

ABAP Dictionary, this is my HANA artifact!

Until now, the only way to consume existing HANA artifacts in your ABAP code was by using native SQL, e.g., by using ABAP Database Connectivity (ADBC). While native SQL is both powerful and flexible, it is also tedious and error-prone. The development cycle consists largely of string concatenations and runtime validations, which some ABAP developers affectionately refer to as “dump-driven development”.

Now, HANA views and SQLScript procedures which are stored in the HANA repository can be “imported” into the ABAP Dictionary. Proxy repository objects are created for the HANA artifacts in the ABAP Dictionary and the artifacts are optimally integrated into the ABAP development and runtime environments. This way you can take full advantage of the ABAP development tools (syntax check, static code checks, where-used, code-completion, etc.) when you write code which consumes your HANA artifacts.

The ABAP Development Tools 2.7 offer new tools to create proxy repository objects, i.e., External Views and Database Procedure Proxies for your HANA views and SQLScript procedures respectively.

External Views

You can import your HANA views into the ABAP Dictionary by creating an External View for your HANA view (New > Other ABAP Repository Object > Dictionary > Dictionary View).

CreateNewExternalView.png

When the External View is created, the HANA types are automatically mapped to ABAP types. Errors which occur during the import are displayed in the ABAP Log.

If the External View was successfully created, you can modify the DDIC types which were automatically mapped to the HANA types in the External View editor.

CustomizeExternalView.png

Once you have activated the External View, it can be used in OPEN SQL in the same way that you can use normal dictionary views!

SELECT

     so_id

     bupa_id

     days_open

     gross_amount

FROM zopen_invoice_vw INTO TABLE open_invoices.

HANA views with input parameters are not supported.

Database Procedure Proxies

You can import your SQLScript procedures into the ABAP Dictionary by creating a Database Procedure Proxy for your SQLScript procedure (New > Other ABAP Repository Object > Dictionary > Database Procedure Proxy).

CreateNewDatabaseProcedureProxy.png

When a Database Procedure Proxy is created, the HANA types are automatically mapped to ABAP types and a read-only ABAP interface is created with ABAP type definitions for the parameters of the SQLScript procedure. The type definitions can be used to define the actual parameters for calling the SQLScript procedure via its proxy in ABAP.

If the import was successful, you can modify the ABAP names and the built-in ABAP types which were automatically mapped to the HANA types in the Database Procedure Proxy editor. You can also use an existing DDIC data element or structure as a parameter type.

CustomizeDatabaseProcedureProxy.png

The database procedure is called via its proxy using the new and convenient ABAP statement CALL DATABASE PROCEDURE. If you’ve ever called a SQLScript procedure using native SQL, then you will appreciate the ABAP code below!

DATA:

   target_currency_code TYPE zif_zopen_inv_amount=>iv_target_currency_code,
   figures TYPE STANDARD TABLE OF zif_zopen_inv_amount=>et_figures WITH EMPTY KEY.

CALL DATABASE PROCEDURE zopen_inv_amount
  EXPORTING
    iv_target_currency_code = target_currency_code
  IMPORTING
    et_figures              = figures.


HANA artifact, we’ve already met!

It is technically possible to create more than one External View or Database Procedure Proxy for your HANA artifact. This, however, is not recommended and you will get a warning when you import a HANA artifact into the ABAP Dictionary which has already been imported.

If you want to know which External Views or Database Procedure Proxies have already been created for your HANA artifact you can perform an ABAP Object Search for the artifact (Search > Search …). The search will return all the proxy repository objects in the ABAP Dictionary which exist for the artifact.

ABAPObjectSearch.png

HANA artifact, you’re not my type!

Currently not all HANA data types can be mapped to ABAP Dictionary types. HANA artifacts which use HANA types not listed in the table below cannot be imported into the ABAP Dictionary. You need to keep this in mind when you model your HANA artifacts in the HANA Studio if you want to use them in ABAP.

HANA Data Type ABAP Dictionary Type
SMALLINT INT2
INTEGER INT4
DECIMAL DEC
SMALLDECIMAL DEC
FLOAT FLTP
NVARCHAR CHAR
VARBINARY RAW
BLOB RAWSTRING
NCLOB STRING

HANA artifact, let’s meet again!

If the underlying HANA artifacts are modified, then the External Views and Database Procedure Proxies have to be manually synchronized with the HANA Repository. The External View and Database Procedure Proxy editors provide a “synchronize” function to retrieve the active version of the HANA artifact from the HANA repository. By default, the manual changes made to the External Views and Database Procedure Proxies (ABAP names, types, etc.) are preserved when they are synchronized.

Synchronization.png

So, HANA artifact, how was it?

So now that you’ve seen how easy it’s become to consume HANA artifacts in ABAP, let’s put it in a nutshell:

  1. You need SAP NetWeaver 7.4 and the ABAP Development Tools 2.7.
  2. You can import your HANA views and SQLScript procedures into the ABAP Dictionary as External Views and Database Procedure Proxies respectively.
  3. The HANA views and SQLScript procedures must be stored in the HANA repository for them to be imported.
  4. You cannot import HANA artifacts which use HANA types that cannot be mapped to ABAP types. HANA views with input parameters are not supported.
  5. You can use your External View in OPEN SQL statements and easily call your Database Procedure Proxy using the new ABAP statement CALL DATABASE PROCEDURE.
  6. If you modify your underlying HANA artifact you must manually synchronize your External View or Database Procedure Proxy.

You will find more information about these and many others features in the official documentation integrated into the ABAP Development Tools (Help > Help Contents > SAP – ABAP for HANA Development User Guide) and the ABAP for SAP HANA Reference Scenario delivered with SAP NetWeaver 7.4.

Uhmm, HANA artifact … your place or mine?

If you’re now asking youself how to get the HANA artifacts into your ABAP SAP system landscape and how to transport them together with your External Views and Database Procedure Proxies, then the answer is the HANA Transport Container.

To report this post you need to login first.

15 Comments

You must be Logged on to comment or reply to a post.

  1. Ganesh Padala

    Nice post, I had tried reading HANA Artifacts via Native SQL and ADBC and its tedious, this one sounds interesting, can’t wait to get my hands on SAP NW 7.4 and new ABAP workbench

    (0) 
  2. Shiva Kalikiri

    Hello Christiaan,

    Would this require ABAP 7.4 running on HANA as DB (Ex: Suite on HANA) or will this work for HANA as secondary DB scenario’s as well.

    Especially the the database procedure proxy function

    (0) 
    1. Christiano José Beltrão Magalhães

      Hi Shiva,

      Database procedure proxy only works for ABAP systems using HANA as primary database. Take a look in this video hosted by open.sap during the course “introduction to software development on SAP HANA ” :

      https://open.sap.com > courses > introduction do software development on SAP HANA > self study > extra knowledge > 2.6 SQLSCRIPT.

       

      BR,

       

      Christiano.

      (0) 
    2. Christiaan Edward Swanepoel Post author

      Hi Shiva, Hi Christiano,

      Sometimes, as developers, we know more than the course material 😏 .

      The CALL DATABASE PROCEDURE statement has an addition CONNECTION where you can specify the secondary database connection to a SAP HANA Database. The syntax is as follows:

           CALL DATABASE PROCEDURE

                { proxy  [CONNECTION con|(con_syntax)] parameter_list }.

      See the F1-help in your SAP NetWeaver 7.4 system for more information.

      The problem is rather: “How to create a Database Procedure Proxy when running SAP HANA as a secondary database?“.

      The problem here is that the ABAP Development Tools (ADT) are not secondary database connection aware. This means that you cannot create a Database Procedure Proxy via a secondary database connection in ADT. You could:

      1. Create the proxy in a system where SAP HANA is the primary database and transport the proxy into your system. Or
      2. Use the ABAP “proxy factory” CL_DBPROC_PROXY_FACTORY to create your Database Procedure Proxy programatically. With this ABAP class you can create/delete/check the proxy via a secondary database connection (see the class documentation about usage).  Note: Currently the proxies created via this factory class cannot be transported. This is a problem in a multi-system landscape where your consumers have to ensure that the proxy is created before it is used the first time. But this too can easily be solved by using TRY/CATCH/ENDTRY to catch the exception CX_SY_DB_PROCEDURE_NOT_FOUND and then, if necessary, creating the Database Procedure Proxy using CL_DBPROC_PROXY_FACTORY.

      Kind regards

      Chris

      (0) 
    1. Christiaan Edward Swanepoel Post author

      Hi Daniel,

      In ADT (“ABAP in Eclipse”): right-click on DB Procedure Proxy in Project Explorer > Delete.

      If you are using the proxy factory CL_DBPROC_PROXY_FACTORY (see my comment above), then the interface IF_DBPROC_PROXY_PUBLIC_API provides a method DELETE.

      Regards

      Chris

      (0) 
  3. Dinh An Nguyen

    Hi Christiaan,

    This is a very nice feature. I just try it out, but i got the following error message during the activation of proxy “Bei der Aktivierung ist ein Fehler aufgetreten.”. Is it related to missing authorization?

    Regards,

    Dinh

    (0) 
  4. Justin Molenaur

    Is it possible to have an external view that points to another HANA box (that’s not Suite On HANA)? I am thinking a sidecar scenario that has a view that I would want to call from the primary ERP on AnyDB.

    Regards,

    Justin

    (0) 

Leave a Reply