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.

15

ABAP Programming for SAP HANA

view), so naturally the next part of the coding is the SELECT statement, which

looks almost the same as the usual SELECT statement you write in your ABAP programs

(Listing 15.2).

SELECT FROM zt_monsters AS monster_header

INNER JOIN zt_monster_items AS monster_items

ON monster_header.monster_number = monster_items.monster_number

LEFT OUTER JOIN zt_monster_pets AS monster_pets

ON monster_header.monster_number = monster_pets.owner

Listing 15.2 SELECT Statement

There are two differences between a SELECT statement in traditional ABAP Open-

SQL and the CDS view equivalent . First, the aliases (as in TABLE_NAME AS ALIAS)

have to be declared, whereas this is optional in ABAP (and not really used outside

of SAP examples or code cut and pasted from SAP ex amples). Second, in traditional

ABAP, after the SELECT statement is either an asterisk to denote “everything”

or a list of fields that you want from the database tables.

One aspect that remains the same as coding a regular SELECT statement in ABAP

is that when coding a DDL that generates a CDS view you don’t have to put the

client (MANDT) into the SELECT statement; the runtime system handles this for you,

just like you’ve always been used to. In Section 15.2.2, you’ll see that this is not

the case for ABAP Managed Database Procedures.

You will also notice that the example in Listing 15.2 contains an outer join, and

you cannot do an outer join in an SE11 database view. In fact, in the DDL that creates

a CDS view you can not only do a LEFT OUTER JOIN, but also a RIGHT OUTER

JOIN, UNION, UNION ALL, and UNION CITY BLUE, the latter four being unknown concepts

in traditional ABAP SELECT statements.

Next, you want to declare a list of fiel ds, just as you would in a traditional SE11

view. In SE11, you have two columns: on the left are human-friendly names, like

CUSTOMER and CUSTOMER_NAME; on the right are the data element names, like KUNNR

and NAME1. In CDS views, things are slightly different; you’re going to make a big

list of the human-friendly names for the fi elds that will be available in the view

(you can still use German abbreviations ifyou want), and how they’re going to be

typed will be determined later on by the system based on what values from the

database (or from a calculation) are going to be placed into them. This is rather

like the DATA( ) statement you looked at in Chapter 2 when defining variables in

ABAP at the place in the code where they have a value placed into them.

664

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

Saved successfully!

Ooh no, something went wrong!