Database Views in ABAP

  • If a view is created on one or more tables by combining the fields using inner join, such a view is called a Database view. Since this view uses the inner join, it only combines the matching records from the table.
  • The database view gives an application-specific view to data of an application object, which is distributed among different tables.
  • In this view, we cannot perform any maintenance operation on table data; instead we can just read the data.
  • The database views are specified within the ABAP dictionary, and a database view is automatically created in the underlying database when we activate the view.
  • We can also view the data of database views in an ABAP program with the help of the database interface. One can access the data in the program using OPEN SQL and NATIVE SQL.
  • This view can include data from some fields of a table and also the entire table.

Note: The join conditions used in this view can be applied using the equality relationship between any base fields. But in other views type(maintenance, help, and projection view), the join condition must be achieved using the foreign key relationship.

The below diagram explains the working of the ABAP database view:

Database Views in ABAP

Key features of database view

  • If the view contains more than one table, then it only allows us to read the data, but if the view contains only a single table, the maintenance status can be checked to find if the data can also be inserted in the view table or not.
  • If we want to select the logically connected data from different tables simultaneously, then we need to create the database views.
  • This view can only combine the transparent tables, as it is implemented in the database.

Creating Database view

Below are the steps used to create the database view in SAP ABAP:

Step-1: Open the data dictionary initial screen by navigating the menu path or entering the transaction code SE11 in the command field.

Step-2: Click the radio button in front of View option, and give a name to the view then click the Create button given on the screen.

Database Views in ABAP

Step-4: A pop-up window will appear with all the views, from where select the "Database view" and click on the Copy button.

Database Views in ABAP

Step-5: A view maintains screen appears that contains multiple tabs, where first provide the description in the field "Short description." Consider the below image:

Database Views in ABAP

In the above screen, first, we will select the Table/Join Conditions tab and will provide the table names (base tables) that we want to link. In our example, we will take two SAP standard tables that are MARA and MARC. After entering the table name, we need to click on the Relationships button. Consider the below image:

Database Views in ABAP

Step:7- When we click on the Relationships button, all the tables with the foreign key relationship with the base table (MARA) will be displayed. Consider the below image:

Database Views in ABAP

As another table, we have selected MARC (SAP standard table), and clicked on the Copy button, given at the bottom of the screen.

Step-8: Once we will select the MARC table, all the join conditions field names will be filled automatically. Consider the below image:

Database Views in ABAP

Step-9: Now, we will move to the next tab, which is View fields, to select the fields of both tables that we want to display. Consider the below image:

Database Views in ABAP

Step-10: To select the fields of each table, we need to click on the Table fields button given on the screen (See the above image). It will open a new pop window with both table names (MARA and MARC). We will select one table at a time and will select the required fields of each table.

Database Views in ABAP

Step-11: Once we click on the Choose button given at the bottom of the screen, it will open all the fields of the selected table from where we can select the required fields. Consider the below image:

Database Views in ABAP

After selecting the fields, click on the Copy button. Similarly, we will choose the fields of another table (MARC).

Step-12: After selecting all the required fields of both tables, save the view as a local object and activate the view (CTRL+F3) or by clicking on the activate button. Consider the below image:

Database Views in ABAP

Step-13: The activation window will open, select the View, and click to the Green tick.

Database Views in ABAP

Step-14: Now, we can display the records that we have selected using the database view. For this, click on the Content (CTRL+SHIFT+F10) option given at the screen. Once we click on the content option, it will open the selection screen as given in the below image:

Database Views in ABAP

In the above, we can see all the fields of the table are displayed that we have selected from both the table. We can either fill the details in the field for the particular record or can view all the records using the execute button given at the above image. It will display all the records, consider the below image:

Database Views in ABAP




Latest Courses