14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

15

ABAP Programming for SAP HANA

METHOD get_complex_monster_data

IMPORTING VALUE( this_and_that ) TYPE whatever

VALUE( id_client ) TYPE sy-mandt

EXPORTING VALUE( the_other ) TYPE something_else.

Listing 15.11 Class Definition with Interface to Enable Use of AMDPs

Although the CDS views discussed in Sect ion 15.2.1 are more or less database

independent, AMDPs are specific to SAP HANA. This is why _HDB (for “HANA

database”) appears at the end of the inte rface name shown in Listing 15.11. The

other point you may be puzzled about in Listing 15.11 is that you have to tell the

SAP HANA database what client you’re talking about, and thus the method needs

to get the client ( MANDT) as an importing parameter. In the ABAP world, you’re

used to the system automatically reading or writing to the client where the program

is running—but in the database world, the client is a vital piece of information.

(As mentioned in Section 15.2.1, when coding a DDL for a CDS view, you

don’t have to pass in the client; the runtime system handles it.)

Did you also notice that you have to pass everything by value? That’s compulsory

if you want a method to make use of an AMDP.

Implementing the ABAP Method Using an AMDP in SQLScript

If you just did a normal implementation of a method of a class defined as shown

in Listing 15.11 with normal ABAP code , then it would run in the application

server as normal. However, this isn’t wh at you want, so you have to tell the

method implementation to behave differently.

You can control whether a method is run on the normal ABAP application server

or within the database by adding some extra lines to the implementation of the

method. This is shown in Listing 15.12.

Warning: Houston, We Have a Problem

If you put the word SQLSCRIPT in lowercase, Eclipse gets really upset. Conversely the

word hdb has to be in lowercase.

CLASS zcl_monsters IMPLEMENTATION.

METHOD get_complex_monster_data

BY DATABASE PROCEDURE

FOR hdb

LANGUAGE SQLSCRIPT

672

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!