26
ABAP Dictionary Objects: Views March-2005 ABAP Dictionary Objects: Views | 2.08

Chapter 08 abap dictionary objects views1

Embed Size (px)

Citation preview

Page 1: Chapter 08 abap dictionary objects views1

ABAP Dictionary Objects: Views

March-2005ABAP Dictionary Objects: Views |

2.08

Page 2: Chapter 08 abap dictionary objects views1

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

Page 3: Chapter 08 abap dictionary objects views1

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.

Page 4: Chapter 08 abap dictionary objects views1

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

Page 5: Chapter 08 abap dictionary objects views1

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.

Page 6: Chapter 08 abap dictionary objects views1

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.

Page 7: Chapter 08 abap dictionary objects views1

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.

Page 8: Chapter 08 abap dictionary objects views1

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.

Page 9: Chapter 08 abap dictionary objects views1

Specifying Selection Criteria

March-2005ABAP Dictionary Objects: Views |

2.089

1 2 3 4 5

Can include unprojected fields

Page 10: Chapter 08 abap dictionary objects views1

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.

Page 11: Chapter 08 abap dictionary objects views1

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.

Page 12: Chapter 08 abap dictionary objects views1

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.

Page 13: Chapter 08 abap dictionary objects views1

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.

Page 14: Chapter 08 abap dictionary objects views1

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

Page 15: Chapter 08 abap dictionary objects views1

Types of Views in the ABAP Dictionary

• Database View• Projection View • Help View• Maintenance View

March-2005ABAP Dictionary Objects: Views |

2.0815

Page 16: Chapter 08 abap dictionary objects views1

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.

Page 17: Chapter 08 abap dictionary objects views1

Demonstration

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

March-2005ABAP Dictionary Objects: Views |

2.0817

Page 18: Chapter 08 abap dictionary objects views1

Practice

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

March-2005ABAP Dictionary Objects: Views |

2.0818

Page 19: Chapter 08 abap dictionary objects views1

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.

Page 20: Chapter 08 abap dictionary objects views1

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

Page 21: Chapter 08 abap dictionary objects views1

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

Page 22: Chapter 08 abap dictionary objects views1

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.

Page 23: Chapter 08 abap dictionary objects views1

Demonstration

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

March-2005ABAP Dictionary Objects: Views |

2.0823

Page 24: Chapter 08 abap dictionary objects views1

Practice

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

March-2005ABAP Dictionary Objects: Views |

2.0824

Page 25: Chapter 08 abap dictionary objects views1

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

Page 26: Chapter 08 abap dictionary objects views1

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