14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Top-Down Development 15.2

USING zt_monsters zt_monster_items.

" SQLScript code goes here

ENDMETHOD.

ENDCLASS.

Listing 15.12 Implementing a Method so that It Runs inside the Database

After the method implementation in Listing 15.12, you’ll see the words BY DATA-

BASE PROCEDURE, which says that this method will generate and execute a stored

procedure in the database at runtime. Having the control in the implementation

as opposed to the definition is a stroke of genius: It means you can redefine the

method so that subclasses can run the method in the server or in the database, or

during unit tests a test double can just return hard-coded values. In addition to

the obvious benefit for unit testing, if you’re dubious as to whether pushing a certain

method down to the database is re ally worthwhile, then you can create one

class that runs in the server and a subclass that runs in the database and do some

tests where you swap between them to compare the runtime.

The next line in Listing 15.12 says FOR hdb, which means that you want to use an

SAP HANA database, and LANGUAGE, to say what language you want. As Henry

Ford once said, “You can have any color you want, as long as it is black.” In the

same way, you have these options to specify what database you can use (it has to

be SAP HANA) and what language you are going to code the AMDP in (it has to

be SQLScript).

Finally, in Listing 15.12 you have the USING statement, in which you have to give

an explicit list of what database tables (or views) you’re going to use within the

procedure. It’s also possible for one database procedure to call another, and if you

want such a thing, then you have to mention the database procedure you’re going

to invoke in this list as well. This whol e concept will seem strange to ABAP programmers,

who are used to just reading from whatever database table takes their

fancy and calling global functions and methods at will, but remember: You’re in

another world now, the world of the database, where the laws of physics are different,

and water flows uphill; this is programming, but not as you know it.

Restrictions

You cannot create the AMDP coding (or any sort of SAP HANA artifact, for that matter)

in SE24 or SE80. You can display it, but to create or change the code you need to use

ABAP in Eclipse. (Hopefully Chapter 1 convin ced you that is the best tool to use any-

673

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

Saved successfully!

Ooh no, something went wrong!