Chapter 08_ABAP Dictionary Objects-Views

26
IBM Global Business Services © IBM Corporation 2013 ABAP Dictionary Objects: Views | Dec-2008 ABAP Dictionary Objects: Views

description

Chapter 08_ABAP Dictionary Objects-Views

Transcript of Chapter 08_ABAP Dictionary Objects-Views

ABAP Dictionary Objects: VIEWSDefine a View.
Discuss the different types of Views.
Discuss how to use Views in an ABAP program.
ABAP Dictionary Objects: Views |
IBM Global Business Services
Views are used to look into one or more tables.
A view does not contain data of its own.
ABAP Dictionary Objects: Views |
A view is an object, like the telescope, that provides a picture of something.
We can construct a view with special “lenses” or “filters” to allow us to look at one or more dictionary tables. We can look at parts of one table (selected records and/or fields) or combinations of tables and parts of tables.
A view is an ABAP Dictionary object.
In many cases, you reference a view in an ABAP program just as you would a table. For example, you can select data from a view. However, a view does not contain data of its own – rather, the view provides specialised access to the data that exists in other tables. For this reason, views are often called virtual tables.
10.unknown
The Most Basic Form of a View
In its most basic form, a view simply mirrors an entire database table
ABAP Dictionary Objects: Views |
In its most basic form, a view simply mirrors an entire database table. It looks just like the table and it acts just like the table – but it isn’t actually the table.
Of course, if this is all that views could do, they wouldn’t be very useful. Let’s take a look at some of the other capabilities of views.
The view name cannot be the same as an existing table name.
12.unknown
Join
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.
Table 4
Table 3
Join several tables
Project (or choose) certain fields from one or more tables
Select (or choose) certain records from one or more tables
Join, projection, and selection are called relational operations.
IBM Global Business Services
View A
The projection operation is used to narrow a view’s focus to certain fields in a
table.
ABAP Dictionary Objects: Views |
The projection operation is used to narrow a view’s focus to certain fields in a table.
For example, we might have a view of an employee table that does not contain the salary field. Employees authorised to view salary data would be given authorisation to view the actual table, while other employees might only have authorisation to use the view without the salary data.
IBM Global Business Services
ABAP Dictionary Objects: Views |
When designing a view, view fields need to be given names. The view field names should be the same as the regular table fields they are reflecting, unless the view is a database view. Only in that situation are you permitted to use different names. When referencing the view field in code, you would refer to VIEW_NAME-VIEW_FIELD_NAME.
IBM Global Business Services
Staff Level <= 3
The selection operation is used to narrow a view’s focus to certain records in a
table.
ABAP Dictionary Objects: Views |
The selection operation is used to narrow a view’s focus to certain records in a table.
For example, we might sometimes wish to view only the information about employees belonging to a certain staff classification. This might mean creating one view containing partners and principals one view containing principal consultants, and another view containing consultants. Each view would be built using selection criteria that indicated which records to include in that view. As an example of why such a view might be used, staff members might be permitted to view the billing rates of employees in the same staff classification or lower, but not of employees in a higher classification.
IBM Global Business Services
You specify selection criteria by building logical expressions that compare specific fields of a table to hard-coded literal values.
(1 & 2) Specify the table and field on which the restricted selection should take place. Any fields, including unprojected ones, can be indicated.
(3) Specify the relational operator used to compare the field to the value. You may use EQ, NE, LE, LT, GE, GT, LIKE, and NOT LIKE.
(4) Specify the comparison value. Comparison values must be text or numeric literals. Text literals must be enclosed in single quotes.
(5) You can specify multiple selection criteria (one per line) and link them using the logical operators AND and OR. Unlike elsewhere in SAP (and most other systems), OR takes priority over AND. Also, OR operations are only permitted between lines which refer to the same field.
If the projection and selection operations are both used within the same view, it is possible to specify selection criteria for fields that are not included within the view. For example, it would be possible to create a view that contained only employees making over $100,000 per year even if the view did not contain the salary field.
IBM Global Business Services
Table 4
View C
The join operation is used to combine information from multiple tables into a
single view.
ABAP Dictionary Objects: Views |
The join operation is used to combine information from multiple tables into a single view.
For example, we might wish to create a report listing employees by name, along with their salary history. Database design considerations would probably result in the salary history being stored in one table and basic employee information (such as the name) being stored in another. Thus, we might create a view that would combine the data from both tables. We could write our report program using this view, and it would seem to our program as if the data was stored in a single table.
Using the join operation within a view is generally the most efficient way to access data from multiple tables. We’ll examine some other methods later on.
IBM Global Business Services
Wrong
Database design principles often require related data to be stored in separate
tables. This is called normalising.
The Necessity of the Join Operation
ID Name Salary 1 Salary 2 Salary 3 …
Employee
ABAP Dictionary Objects: Views |
Database design principles often require related data to be stored in separate tables. This is necessary to provide flexibility in one-to-many and many-to-many relationships, and also to prevent data redundancy.
For example, if employee name and salary history were stored in the same table, we would encounter one of the following situations:
If we stored salary history on the employee record, we would have to create a fixed number of “previous salary” fields in the employee table. For many employees, most of those fields would be blank, and for long-term employees, we might eventually run out of fields.
If we stored employee name on the salary history record, we would have many copies of the employee’s name. If the employee’s name changed, that change would have to be made many times. Additionally, we would run the risk of not updating all the data correctly, and the employee and the salary table could get “out of sync.” Whenever possible, redundant copies of the same information should be avoided.
As a result, data is often “broken apart” into several tables. This is called normalising the database. The join operation essentially reverses this process. The result of a join is a view that looks like a table with redundant data.
IBM Global Business Services
The join operation essentially reverses the normalising process.
The result of a join is a view that looks like a table with redundant data.
ID Salary Date Effective
ABAP Dictionary Objects: Views |
When data is broken apart into separate tables, it is still necessary to duplicate some data – namely the key fields of the tables involved. For example, the salary history table would contain a field for employee ID number, so that we knew which employee each salary record belonged to. In this case, the employee ID number becomes a foreign key in the salary history table.
The key to understanding the join operation is to understand that different tables are joined together using foreign keys. We don’t want every employee’s name associated with every salary history record. Rather, we want each employee’s name to be associated with only those salary records belonging to that employee.
IBM Global Business Services
Join
Primary
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.
View C
Table 4
Table 3
ABAP Dictionary Objects: Views |
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. Also, you must ensure that the semantic attributes of those foreign keys have been maintained (see Chapter 4 for a discussion of semantic attributes and foreign keys).
Other notes on the join operation:
Views are created with a primary table and up to 10 secondary tables.
The primary table can be either a check table or a foreign key table with respect to the other tables in the view (i.e., the primary table does not have to be the check table).
Note : When a join operation is employed, only those primary table records that have a match in all secondary tables are retrieved. For example, in a join between employees and salary history, employees with no salary history records would not appear at all.
IBM Global Business Services
Hit button to see related tables and
automatically generate join conditions.
ABAP Dictionary Objects: Views |
You can hard code all the tables you need all at once. Then you would have to hard code the foreign key relationships between them as well.
It might be simpler to input the first base table, and from there hit the Relationships pushbutton. Then you can select a related table and the join conditions will be filled in automatically for you.
IBM Global Business Services
Database View
Projection View
Help View
Maintenance View
Database View
The database view is the only type of view in SAP that is physically created at
the database level.
ABAP Dictionary Objects: Views |
The database view is the only type of view in SAP that is physically created at the database level. In other words, the underlying database system also directly recognises the view, apart from SAP. Therefore, database views must be created over transparent tables.
With the database view, all three of the relational operations (projection, selection, and join) can be used.
Database views can be buffered just like transparent tables. In the technical settings you can decide whether to have buffering off, or on with type single record, generic, or full.
14.unknown
15.unknown
Creation of a database view using two related database tables.
ABAP Dictionary Objects: Views |
IBM Global Business Services
Creation of a database view using two related database tables.
ABAP Dictionary Objects: Views |
IBM Global Business Services
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.
ABAP Dictionary Objects: Views |
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 recognised by the underlying database system.
Projection views must be defined over a single transparent table.
The only relational operation that is valid for a projection view is projection.
IBM Global Business Services
Data can be updated
Updates are less efficient
as the fields in the underlying table
Can’t be buffered
Data can be updated if the view is built
over a single table
Updates are more efficient
from the fields in the underlying table
Can be buffered
ABAP Dictionary Objects: Views |
Projection Views Database Views
Must be built over a single table Can be built over many tables
Data can be updated Data can be updated if the view is built over a
single table
Data updates must use open SQL Data updates can use open SQL or Native SQL
Updates are less efficient than using Updates are more efficient than using
a Database View a Projection View
Fields in the view must be named the Fields in the view can be named
same as the fields in the differently from the fields in the
underlying table underlying table(s)
IBM Global Business Services
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.
ABAP Dictionary Objects: Views |
Help Views: 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, since database views only create inner joins.
Maintenance Views: These views permit maintenance of base table data. Transactions SM30 and SE54 are provided for working with maintenance views.
In previous releases, Help Views used to play a major role in matchcodes. However, matchcodes have been replaced by Search Helps, and therefore, Help Views no longer have as big a presence.
IBM Global Business Services
DATA : WA_YXXEMP_V TYPE YXXEMP_V.
ABAP Dictionary Objects: Views |
In the code above, we select data from the view YXXEMP_V to write the id, last name, and first name fields to the screen.
The syntax to reference a view in an ABAP program is the same as that used to reference a table.
IBM Global Business Services
Demonstration
Select data from the database view created earlier and display selected data in a report.
ABAP Dictionary Objects: Views |
IBM Global Business Services
Practice
Select data from the database view created earlier and display selected data in a report.
ABAP Dictionary Objects: Views |
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 view’s focus to certain fields
in a table.
The Selection Operation is used to narrow a view’s 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.
ABAP Dictionary Objects: Views |
IBM Global Business Services
ABAP Dictionary Objects: Views |