This is the next blog post in this series. Here is the previous blog post Getting Started with ABAP: How to Create Table Type and Deep Structure
In the previous blog post, how to create table type and deep structure.
In this blog post we will learn how to create view and what is view.
What is View?
View is a grouping of columns from one or more database tables. Views are the data dictionary repository objects in ABAP. View can be created by combining the data of one or more database tables. It derives the data from one or more database tables and acts like virtual table. It doesn’t store data physically.
Types of Views
What is Database View?
If the view is created on one or more transparent tables by joining the fields of tables using inner join then that view is called as database view.
If we create database view on single database table then we can read, insert, delete and change data into the database table through database view.
If we create database view on more than one tables then we can only read the data through database view. We cannot maintain data on multiple tables through database view.
What is Inner Join?
If the two tables are joined using inner join then result set will contain combinations of rows whose columns together meet the join conditions. If there are rows which doesn’t satisfy the join condition then that row will not be in result set.
How to create Database View
How to create Database View on Single Database Table
Step 1: Go to SE11. Select View and enter name of view that you want to create.
Step 2: Click on Create. Here you can see what are the view that we can create. Select Database View and press Enter.
Step 3: Enter short description.
Step 4: Enter table name. We will use the table name which we have created earlier that is ZAKTABLE. Here we are creating view on single table hence I have given one table name in Table.
Step 5: Click on View Fields tab. In this tab we have to select fields from the table which we have entered in previous tab. We need to select field that we want in our result set of database view.
Step 6: Click on Table Fields button. Here we will get all the fields from the table.
Step 7: I want all fields in my result set of view hence I selected all fields from the table. Click on Copy.
Note: If you don’t select all key fields from your table then you will not be able to maintain your table through database view.
Step 8: Here you will get those fields.
Step 9: Click on Selection Conditions tab. On this tab you can put condition so that your result set of view will contain those records only.
For example, from my employee table I want al the details of the employee whose employee id is 2. Like this condition you can given in this tab so that instead of showing all data from the table it will show only those records which match the condition.
Note: If you give any condition and after getting the result if you add new entries then you will not be able to delete or edit that new entries through the database view.
Step 10: I want to put condition here. So first enter table name ZAKTABLE.
Step 11: Then select field name on which you want to put condition. So I selected employee_id field.
Step 12: Select Operator. Here I want equal to hence I selected it.
Step 13: Enter Comparison Value. I want data of employee whose employeed id is 2.
Hence, I entered 2.
If you want to add more condition then you can join second condition using AND/OR operator.
Step 14: Click on Maint.Status tab.
Here you can see that In Access there are two options.
Read Only: That means your view will be read only if you select this.
Read and Change: If you select this then you can view and maintain data through database view.
So, I will select read and change. Because I want to maintain data through this database view.
What is Data Browser/Table View Editing?
I have explained this in earlier blog post. Here you can check Getting started with ABAP: How to Create Table Part 1
Step 15: I selected read and change option.
Step 16: Save and Activate this database view.
Step 17: Click on Contents.
Step 18: You will get below window.
Step 19: Click on Execute. The data is display.
How to add entry through database view into the table
Step 1: Click on Create option.
Step 2: You will get below window.
Step 3: Enter the data.
Step 4: Click on Save. Click on Back. You will be able to see the new entry. Also you can check your database table whether new entry is added or not.
How to edit entries through Database view into the table
As I mentioned earlier once you put the condition and if you add new entries you will not be able to edit or delete new entries through database view. So, I will edit entry which match the condition.
Step 1: Select entry that you want to edit. Click on Change.
Step 2: I want to change name to AAA.
Step 3: Click on Save and you can check your database table.
In this way, you can edit your entries through database view.
How to delete entry through database view
Step 1: Select entry that you want to delete and right click on it.
Step 2: Click on delete. You will get below window.
Step 3: Click on Delete Entry. Here entry is deleted.
In this way you can delete your entry through database view.
Here we have completed how to created database view on single database table.
Follow my profile to be notified of the next blog post. Please feel free to ask any questions you have in the comments section below.