consuming existing hana artifacts in abap is easy

Upload: raghavendra-sanagavarapu

Post on 01-Jun-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Consuming Existing HANA Artifacts in ABAP is Easy

    1/6

    Consuming existing HANA artifacts in ABAP iseasy! Posted by Christiaan Edward Swanepoel in ABAP in Eclipse on May 12, 2013 9:27:26 PM

    inShare2

    If you’re already started developing ABAP on SAP HANA or if you’re planing on doing so, then you’ll soon ask yourself; “Howdo I consume my HANA artifacts in ABAP?”. Once you’ve figured that one out and you’ve been baptised in the fire of nativeSQL, 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 existingHANA 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 ABAPDatabase Connectivity ( ADBC ). While native SQL is both powerful and flexible, it is also tedious and error-prone. Thedevelopment cycle consists largely of string concatenations and runtime validations, which some ABAP developersaffectionately refer to as “dump-driven development”.

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

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

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

  • 8/9/2019 Consuming Existing HANA Artifacts in ABAP is Easy

    2/6

    When the External View is created, the HANA types are automatically mapped to ABAP types. Errors which occur during theimport 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 HANAtypes in the External View editor.

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

    SELECT so_ i d bupa_i d days_open gr oss _amount

    FROM zopen_i nvoi ce_vw INTO TABLE open_i nvoi ces .

  • 8/9/2019 Consuming Existing HANA Artifacts in ABAP is Easy

    3/6

    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 yourSQLScript procedure (New > Other ABAP Repository Object > Dictionary > Database Procedure Proxy).

    When a Database Procedure Proxy is created, the HANA types are automatically mapped to ABAP types and a read-only ABAPinterface is created with ABAP type definitions for the parameters of the SQLScript procedure. The type definitions can be usedto 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 tothe HANA types in the Database Procedure Proxy editor. You can also use an existing DDIC data element or structure as a

    parameter type.

  • 8/9/2019 Consuming Existing HANA Artifacts in ABAP is Easy

    4/6

    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: t arget _curr ency_code TYPE zi f _zopen_i nv_amount =>i v_t arget _curr ency_code , f i gures TYPE STANDARD TABLE OF zi f _zopen_i nv_amount =>et _f i gur es WITH EMPTY KEY.

    CALL DATABASE PROCEDURE zopen_i nv_amount EXPORTI NG

    i v_t arget _cur r ency_code = t arget _curr ency_code I MPORTI NG

    et _f i gur es = f i gur es .

    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 hasalready been imported.

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

    HANA artifact, you're not my type!

  • 8/9/2019 Consuming Existing HANA Artifacts in ABAP is Easy

    5/6

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

    HANA Data Type ABAP Dictionary Type

    SMALLINT INT2

    INTEGER INT4DECIMAL DEC

    SMALLDECIMAL DEC

    FLOAT FLTP

    VARCHAR CHAR

    NVARCHAR CHAR

    VARBINARY RAW

    BLOB RAWSTRING

    CLOB STRING

    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 manuallysynchronized 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 tothe External Views and Database Procedure Proxies (ABAP names, types, etc.) are preserved when they are synchronized.

    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 .

  • 8/9/2019 Consuming Existing HANA Artifacts in ABAP is Easy

    6/6

    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 ABAPDevelopment Tools (Help > Help Contents > SAP - ABAP for HANA Development User Guide) and the ABAP for SAP HANAReference 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 themtogether with your External Views and Database Procedure Proxies, then the answer is the HANA Transport Container. But moreabout that another time.