Файл: BC430_EN_Col62_FV_Part_A4_-_ABAP_Dictionary.pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 03.04.2021

Просмотров: 2298

Скачиваний: 40

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.
background image

Unit 7: Views and Maintenance Views

BC430

Figure 75: Structure of a View - Selection Condition

The set of records that can be displayed with the view can be further restricted
with a selection condition.

In our example, only records that have the value

DL

in the CARRID field should

be displayed with the view.

A selection condition therefore can also be formulated with a field that is not
contained in the view.

178

© 2007 SAP AG. All rights reserved.

2006/Q2


background image

BC430

Lesson: Views

Figure 76: How are Tables (basis tables) linked to Views?

Example:

Travel agencies sometimes have to check which customer is booked on

which flights. The corresponding data is distributed on several tables:

SCUSTOM:

Customer data, such as the customer number, name and
address

SBOOK:

Booking data, such as the airline, flight number and
passenger (customer number)

SPFLI:

Flight data, such as the city of departure and city of arrival

You have to create a view on tables SCUSTOM, SBOOK and SPFLI to obtain
the booking data.

In this case, the join conditions are:

SBOOK-CLIENT = SCUSTOM-CLIENT

SBOOK-CUSTOMID = SCUSTOM-ID

SPFLI-CLIENT = SBOOK-CLIENT

SPFLI-CARRID = SBOOK-CARRID

SPFLI-CONNID = SBOOK-CONNID

2006/Q2

© 2007 SAP AG. All rights reserved.

179


background image

Unit 7: Views and Maintenance Views

BC430

Figure 77: Structure of the View

You can get the bookings for a particular customer by selecting the corresponding
records for keys CLIENT and CUSTOMID in table SBOOK.

You can get the flight data from table SPFLI for each booking in table SBOOK by
selecting the corresponding record for the keys CLIENT, CARRID and CONNID
from table SPFLI.

You can display only the customer bookings that were not canceled using the view
with the following selection condition:

SBOOK-CANCELED <> X

The join conditions can also be derived from the existing foreign key relationships.
Copying the join conditions from the existing foreign keys is supported in the
maintenance transaction.

The field names of the underlying table fields are normally used as field names in
the view. However, you can also choose a different field name. This is necessary
for instance if two fields with the same name are to be copied to the view from
different tables. In this case, you must choose a different name for one of the
two fields in the view.

180

© 2007 SAP AG. All rights reserved.

2006/Q2


background image

BC430

Lesson: Views

Figure 78: Data Selection with Views

You can also formulate the join condition directly in OPEN SQL.

You would get the same result using an Inner Join:

SELECT C~CARRID C~CARRNAME P~CONNID P~CITYFROM P~CITYTO

F~FLDATE F~SEATSMAX F~SEATSOCC

INTO TABLE ITAB_FLIGHTS

FROM ( SCARR AS C INNER JOIN SPFLI AS P

ON C~CARRID = P~CARRID )

INNER JOIN SFLIGHT AS F

ON

F~CARRID = P~CARRID

AND F~CONNID = P~CONNID

WHERE CITYFROM IN SO_CITYF

AND

CITYTO

IN SO_CITYT

AND SEATSOCC < F~SEATSMAX

ORDER BY C~CARRID P~CONNID F~FLDATE.

A view has type character and can be accessed in programs like all other types
and can be used to define data objects.

2006/Q2

© 2007 SAP AG. All rights reserved.

181


background image

Unit 7: Views and Maintenance Views

BC430

Figure 79: Inner and Outer Join

The set of data that can be selected with a view greatly depends on whether the
view implements an inner join or an outer join.

With an inner join, you only get those records which have an entry in all the tables
included in the view. With an outer join, on the other hand, those records that
do not have a corresponding entry in some of the tables included in the view
are also selected.

The hit list found with an inner join can therefore be a subset of the hit list found
with an outer join.

Database views implement an inner join. You only get those records which have
an entry in all the tables included in the view.

Maintenance views implement an outer join.

182

© 2007 SAP AG. All rights reserved.

2006/Q2