You are on page 1of 26

IBM Global Business Services

ABAP Dictionary Objects: Views

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Objectives
The participants will be able to:
Define a View.
Explain the different Relational Operations.
Discuss the different types of Views.
Discuss how to use Views in an ABAP program.

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

What is a View?
Views are used to look into one or more tables.
A view does not contain data of its own.

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

The Most Basic Form of a View


In its most basic form, a view simply mirrors an entire database table

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

The Relational Operations


We can use views to Join several tables, Project (or choose) certain fields
from one or more tables & Select (or choose) certain records from one or
more tables.

Projection
Table 1

Selection
Table 2

Join
Table 3

Table 4

View C

View A
View B

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

The Projection Operation


The projection operation is used to narrow a views focus to certain fields in a
table.

Projection
Table 1

View A

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Specifying Projected Fields

Can use any field name if database view,


otherwise must be same name as table field.

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

The Selection Operation


The selection operation is used to narrow a views focus to certain records in a
table.

Selection
Table 2

Example:
Staff Level <= 3

View B

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Specifying Selection Criteria

Can include unprojected fields

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

The Join Operation


The join operation is used to combine information from multiple tables into a
single view.

Join
Table 3

Table 4

View C

10

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

The Necessity of the Join Operation


Database design principles often require related data to be stored in separate
tables. This is called normalising.
Employee
ID

Name

Salary 1

Salary 2

Salary 3

Salary

ID

Name

Salary

5579

Smith

$10,000.00

5579

Smith

$11,000.00
Wrong

11

5579

Smith

$12,000.00

5579

Smith

$13,000.00

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Understanding the Join Operation


The join operation essentially reverses the normalising process.
The result of a join is a view that looks like a table with redundant data.
Employee

ID

Name

Salary

12

ID

Salary

Date Effective

5579

$10,000.00

10/1/91

5579

$11,000.00

10/1/92

5579

$12,000.00

10/1/94

5579

$13,000.00

10/1/96

ABAP Dictionary Objects: Views |

Dec-2008

Right

IBM Corporation 2013

IBM Global Business Services

The Join Operation and Foreign Keys


Therefore, in order to use the join operation in SAP, you must first ensure that
the appropriate foreign key relationships exist among the tables to be joined.

Primary

Join

Table 3

Secondary
Table 4

View C

13

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Specifying Joined Fields


Indicate base tables that data will come from.

Join Conditions

Hit button to see related tables and


automatically generate join conditions.

14

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Types of Views in the ABAP Dictionary


Database View
Projection View
Help View
Maintenance View

15

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

The Database View


The database view is the only type of view in SAP that is physically created at
the database level.
Database View

Database

DB
16

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Demonstration
Creation of a database view using two related database tables.

17

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Practice
Creation of a database view using two related database tables.

18

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

The Projection View


The projection view is a logical view. In this context, the word logical means
that the view exists within the ABAP Dictionary but is not recognized by the
underlying database system.

Projection View

View C

19

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Database vs. Projection Views


Projection View

Database View

Can be built over many tables


Must be built over a single table
Data can be updated if the view is built
Data can be updated
over a single table
Data updates must use open SQL
Data updates can use open or native SQL
Updates are less efficient
Updates are more efficient
Fields in the view must be named the same Fields in the view can be named differently
as the fields in the underlying table
from the fields in the underlying table
Cant be buffered
Can be buffered
20

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Other Types of Views


Help View:
Help views can be used as selection methods for Search Helps.It might be
necessary to create a Help View if you are trying to accomplish an outer join.
Maintenance View:
These views permit maintenance of base table data. Transactions SM30 and
SE54 are provided for working with maintenance views.

21

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Using a View in Program Code

DATA : WA_YXXEMP_V TYPE YXXEMP_V.


SELECT
FROM

*
YXXEMP_V INTO WA_YXXEMP_V.

WRITE:

WA_YXXEMP_V-EMP_ID,
WA_YXXEMP_V-LAST_NAME,
WA_YXXEMP_V-FIRST_NAME.

ENDSELECT.

22

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Demonstration
Select data from the database view created earlier and display selected data in a
report.

23

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Practice
Select data from the database view created earlier and display selected data in a
report.

24

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Summary
Views are used to look into one or more tables. A view does not contain data of its
own.
The projection operation is used to narrow a views focus to certain fields
in a table.
The Selection Operation is used to narrow a views focus to certain records
in a table.
The Join Operation is used to combine information from multiple tables into a
single view.
Types of Views in the ABAP Dictionary are Database View, Projection View, Help
View & Maintenance View.
The syntax to reference a view in an ABAP program is the same syntax we use to
reference a table.

25

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

IBM Global Business Services

Questions
What is a View ?
What is a Database view ?
What is a Projection view ?
What is a Maintenance view ?
What is a Help view ?

26

ABAP Dictionary Objects: Views |

Dec-2008

IBM Corporation 2013

You might also like