chapter 08 abap dictionary objects views1
TRANSCRIPT
IBM Global Services
© 2005 IBM CorporationABAP Dictionary Objects: Views | 2.08
March-2005
ABAP Dictionary Objects: Views
IBM Global Services
© 2005 IBM Corporation2 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.
IBM Global Services
© 2005 IBM Corporation3 March-2005ABAP Dictionary Objects: Views | 2.08
What is a View?
Views are used to look into one or more tables.
A view does not contain data of its own.
IBM Global Services
© 2005 IBM Corporation4 March-2005ABAP Dictionary Objects: Views | 2.08
The Most Basic Form of a View
In its most basic form, a view simply mirrors an entire database table
IBM Global Services
© 2005 IBM Corporation5 March-2005ABAP Dictionary Objects: Views | 2.08
The Relational Operations
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.
IBM Global Services
© 2005 IBM Corporation6 March-2005ABAP Dictionary Objects: Views | 2.08
The Projection Operation
Projection
View AView A
Table 1
The projection operation is used to narrow a view’s focus to certain fields in a table.
IBM Global Services
© 2005 IBM Corporation7 March-2005ABAP Dictionary Objects: Views | 2.08
Specifying Projected Fields
Can use any field name if database view, otherwise must be same name as table field.
IBM Global Services
© 2005 IBM Corporation8 March-2005ABAP Dictionary Objects: Views | 2.08
The Selection Operation
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.
IBM Global Services
© 2005 IBM Corporation9 March-2005ABAP Dictionary Objects: Views | 2.08
Specifying Selection Criteria
1 2 3 4 5
Can include unprojected fields
IBM Global Services
© 2005 IBM Corporation10 March-2005ABAP Dictionary Objects: Views | 2.08
The Join Operation
Table 3Table 3Join
Table 4Table 4
View CView C
The join operation is used to combine information from multiple tables into a single view.
IBM Global Services
© 2005 IBM Corporation11 March-2005ABAP Dictionary Objects: Views | 2.08
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.
The Necessity of the Join Operation
IBM Global Services
© 2005 IBM Corporation12 March-2005ABAP Dictionary Objects: Views | 2.08
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
Understanding the Join Operation
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.
IBM Global Services
© 2005 IBM Corporation13 March-2005ABAP Dictionary Objects: Views | 2.08
The Join Operation and Foreign Keys
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.
IBM Global Services
© 2005 IBM Corporation14 March-2005ABAP Dictionary Objects: Views | 2.08
Specifying Joined Fields
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
IBM Global Services
© 2005 IBM Corporation15 March-2005ABAP Dictionary Objects: Views | 2.08
Types of Views in the ABAP Dictionary
Database View
Projection View
Help View
Maintenance View
IBM Global Services
© 2005 IBM Corporation16 March-2005ABAP Dictionary Objects: Views | 2.08
Database
The Database View
DB
Database View
The database view is the only type of view in SAP that is physically created at the database level.
IBM Global Services
© 2005 IBM Corporation17 March-2005ABAP Dictionary Objects: Views | 2.08
Demonstration
Creation of a database view using two related database tables.
IBM Global Services
© 2005 IBM Corporation18 March-2005ABAP Dictionary Objects: Views | 2.08
Practice
Creation of a database view using two related database tables.
IBM Global Services
© 2005 IBM Corporation19 March-2005ABAP Dictionary Objects: Views | 2.08
The Projection View
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.
IBM Global Services
© 2005 IBM Corporation20 March-2005ABAP Dictionary Objects: Views | 2.08
Database vs. Projection Views
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
IBM Global Services
© 2005 IBM Corporation21 March-2005ABAP Dictionary Objects: Views | 2.08
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.
IBM Global Services
© 2005 IBM Corporation22 March-2005ABAP Dictionary Objects: Views | 2.08
Using a View in Program Code
TABLES: YXXEMP_V.
SELECT*FROM YXXEMP_V.
WRITE: / YXXEMP_V-EMP_IDYXXEMP_V-LAST_NAME,YXXEMP_V-FIRST_NAME.
ENDSELECT.
IBM Global Services
© 2005 IBM Corporation23 March-2005ABAP Dictionary Objects: Views | 2.08
Demonstration
Select data from the database view created earlier and display selected data in a report.
IBM Global Services
© 2005 IBM Corporation24 March-2005ABAP Dictionary Objects: Views | 2.08
Practice
Select data from the database view created earlier and display selected data in a report.
IBM Global Services
© 2005 IBM Corporation25 March-2005ABAP Dictionary Objects: Views | 2.08
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 fieldsin 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.
IBM Global Services
© 2005 IBM Corporation26 March-2005ABAP Dictionary Objects: Views | 2.08
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 ?