chapter 08 abap dictionary objects views1
TRANSCRIPT
ABAP Dictionary Objects: Views
March-2005ABAP Dictionary Objects: Views |
2.08
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.
March-2005ABAP Dictionary Objects: Views |
2.082
What is a View?
March-2005ABAP Dictionary Objects: Views |
2.083
Views are used to look into one or more tables.
A view does not contain data of its own.
The Most Basic Form of a View
March-2005ABAP Dictionary Objects: Views |
2.084
In its most basic form, a view simply mirrors an entire database table
The Relational Operations
March-2005ABAP Dictionary Objects: Views |
2.085
Table 2
Selection
View BView B
Table 1
Projection
View AView A View CView C
Join
Table 4Table 4Table 3Table 3
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.
The Projection Operation
March-2005ABAP Dictionary Objects: Views |
2.086
Projection
View AView A
Table 1
The projection operation is used to narrow a view’s focus to certain fields in a table.
Specifying Projected Fields
March-2005ABAP Dictionary Objects: Views |
2.087
Can use any field name if database view, otherwise must be same name as table field.
The Selection Operation
March-2005ABAP Dictionary Objects: Views |
2.088
Selection
View BView B
Table 2
Example:Staff Level <= 3
The selection operation is used to narrow a view’s focus to certain records in a table.
Specifying Selection Criteria
March-2005ABAP Dictionary Objects: Views |
2.089
1 2 3 4 5
Can include unprojected fields
The Join Operation
March-2005ABAP Dictionary Objects: Views |
2.0810
Table 3Table 3Join
Table 4Table 4
View CView C
The join operation is used to combine information from multiple tables into a single view.
The Necessity of the Join Operation
March-2005ABAP Dictionary Objects: Views |
2.0811
Salary
ID Name Salary
5579 Smith $10,000.00
5579 Smith $11,000.00
5579 Smith $12,000.00
5579 Smith $13,000.00
ID Name Salary 1 Salary 2 Salary 3 …
Employee
Wrong
Database design principles often require related data to be stored in separate tables. This is called normalising.
Understanding the Join Operation
March-2005ABAP Dictionary Objects: Views |
2.0812
ID Name …
EmployeeEmployee
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
SalarySalary
Right
The join operation essentially reverses the normalising process.
The result of a join is a view that looks like a table with redundant data.
The Join Operation and Foreign Keys
March-2005ABAP Dictionary Objects: Views |
2.0813
View CView C
Join
Table 4Table 4Table 3Table 3Primary Secondary
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.
Specifying Joined Fields
March-2005ABAP Dictionary Objects: Views |
2.0814
Indicate base tables that data will come from.Indicate base tables that data will come from.
Hit button to see related tables and automatically generate join conditions.
Join Conditions
Types of Views in the ABAP Dictionary
• Database View• Projection View • Help View• Maintenance View
March-2005ABAP Dictionary Objects: Views |
2.0815
The Database View
March-2005ABAP Dictionary Objects: Views |
2.0816
Database
DB
Database View
The database view is the only type of view in SAP that is physically created at the database level.
Demonstration
• Creation of a database view using two related database tables.
March-2005ABAP Dictionary Objects: Views |
2.0817
Practice
• Creation of a database view using two related database tables.
March-2005ABAP Dictionary Objects: Views |
2.0818
The Projection View
March-2005ABAP Dictionary Objects: Views |
2.0819
View C
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.
Database vs. Projection Views
March-2005ABAP Dictionary Objects: Views |
2.0820
Database ViewProjection View
• Must be built over a single table• Data can be updated• Data updates must use open SQL• Updates are less efficient • Fields in the view must be named the same as the fields in the underlying table• Can’t be buffered
• Can be built over many tables• Data can be updated if the view is built over a single table• Data updates can use open or native SQL• Updates are more efficient • Fields in the view can be named differently from the fields in the underlying table• Can be buffered
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.
March-2005ABAP Dictionary Objects: Views |
2.0821
Using a View in Program Code
March-2005ABAP Dictionary Objects: Views |
2.0822
TABLES: YXXEMP_V.
SELECT*FROM YXXEMP_V.
WRITE: / YXXEMP_V-EMP_IDYXXEMP_V-LAST_NAME,YXXEMP_V-FIRST_NAME.
ENDSELECT.
Demonstration
• Select data from the database view created earlier and display selected data in a report.
March-2005ABAP Dictionary Objects: Views |
2.0823
Practice
• Select data from the database view created earlier and display selected data in a report.
March-2005ABAP Dictionary Objects: Views |
2.0824
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 view’s focus to certain fields
in a table.• The Selection Operation is used to narrow a view’s focus to certain
recordsin 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.
March-2005ABAP Dictionary Objects: Views |
2.0825
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 ?
March-2005ABAP Dictionary Objects: Views |
2.0826