SAP ABAP Structures and Views

FREE Online Courses: Click, Learn, Succeed, Start Now!

In this tutorial, we’ll be learning about two important components of the SAP ABAP system. These are ABAP Structures and ABAP Views.

What are Structures in SAP ABAP?

  • A structure is similar to a user-defined data type.
  • We can create it similarly to a table and use from within an ABAP program.
  • However, the records in a structure are not addressed from a database table, and the data contained within a structure is not stored in memory i.e. it is only contained in the structure during execution or run-time of the program.
  • In all, we can create structures in a similar way as a table but can store them only in runtime of a code, defined by the ABAP Data Dictionary.

How to create structure in ABAP?

Here are the steps to create a structure in ABAP beginning with the Data Dictionary –

1. Open the SAP system.

2. Enter transaction code ‘SE11’ in top left.

3. Select ‘Data type’ option radio button.

4. Enter a suitable name for the structure (again, beginning with ‘Z’ or ‘Y’) and click on the ‘Create’ button to proceed.

How to create structure in ABAP

5. Now, select the option ‘Structure’ and hit enter. This opens a popup window of ‘Maintain/Change Structure’.

How to create structure in ABAP

6. Enter a ‘Short Description’ of what the structure is about, in your own words for reference.

7. Type in the Component and Component type (which is basically a combination of the two things that make up a structure – field name & data element)

How to create structure in ABAP

8. We have created the structure now. You can save it and use it as per the requirement.

In a program, we can use ‘BEGIN OF..’ and ‘END OF..’ additions to the statements ‘DATA’, ‘TYPES’ and so on. As in ABAP, we define Structures as data types hence we can code them this way.

What is a View in SAP ABAP?

  • A view in SAP ABAP is a temporary storage taken from a table, usually created for a specific purpose.
  • It is similar to a table for viewing, but we do not store its data in memory, i.e. we create a view and contain it within execution of the program only.
  • Views are usually created to filter, aggregate or summarise data of one or multiple database tables.
  • It is also a Data Dictionary object, and acts like a virtual table.
  • Due to its function of creating summaries, it saves time when a user wants to extract only specific information from a table but does not want the overhead of having to load the entire table at once.
  • Changes in the base tables (i.e. tables from where views are extracted) cause changes in the view.
  • But changes in the view do not reflect with changes in the base tables.
  • In case of multiple base tables, we use ‘joins’ which require at least one common key between the two tables, as we will see in the next section.

Joins in ABAP

As mentioned previously, we use joins to create views from more than one database table.

We use the common key between the tables as an anchor point from which to compare records and merge corresponding one from either table.

Types of Join in SAP ABAP

types of joins in SAP ABAP

Here are the types of joins in SAP ABAP –

1. Inner Join in ABAP

  • Inner joins merge only those records from two tables that have a corresponding match in each other
  • That is, it only selects records where the key is present in both tables
  • If table 1 contains a key that table 2 does not, it will simply not include the record with this key in the view

2. Outer join in SAP ABAP

  • As opposed to the inner join, the outer join will select records irrespective of whether it finds a match in the other table.
  • It will display all records from both tables.
  • If a key is common between the two tables, it will display those records side by side.
  • But if a key from say, table 1 does not have a corresponding match from table 2, it will still display that record but will show its table 2 counterpart as blank entries.

How to create a view in ABAP

  • To create a view, first we need to have the two tables that we will use for merging records in the view.
  • Now, these tables must use the ‘JOIN’ statement.
  • You can also apply a few conditions to join the two tables.
  • Save and activate the program to join the table.

Here are the steps to create view in SAP ABAP –

1. Open the SAP system.

2. Enter transaction code ‘SE11’ in top left.

3. Select the ‘Views’ option radio button.

4. Enter a suitable name for the view (again, beginning with ‘Z’ or ‘Y’) and click on the ‘Create’ button to proceed.

 

How to create a view in ABAP

5. Enter a ‘Short Description’ of the view for further purposes.

6. Select button called ‘Table fields’ which opens the field selection screen for table 1. Use check options to include whichever fields you want in the view.

 

How to create a view in ABAP 2

7. Follow the same steps for table 2 and save.

8. In the popup window of ‘Maintain/Change View’ use option ‘Display/Maintenance Allowed’.

9. Save and activate view.

Types of views in ABAP

Types of views in SAP ABAP

There are various types of views available in ABAP. They are as follows –

1. Database view in ABAP

  • A database view is created when we use an ‘INNER JOIN’ on multiple tables
  • Hence, it only shows matching or corresponding entries from multiple tables in the view
  • However, it is a ‘READ-ONLY’ view, i.e. we cannot perform any updates or changes on the view once created

2. Projection view in ABAP

  • A projection view is created on a single table
  • Hence, the usual purposes of a projection view is to create a concise view of the table with only those records that are currently required for the purpose
  • It is used to ‘filter out’ the table and keep only those rows that are needed
  • We can modify projection views once created, so they are not ‘READ-ONLY’ views

3. Maintenance view in ABAP

  • Maintenance views, as opposed to Database views, are created using ‘OUTER JOIN’ and are not ‘READ-ONLY’
  • Thus they show entries from all tables that match the condition, irrespective of them having a corresponding entry in the other table or tables
  • They can be modified and updated whenever required

4. Help view in ABAP

  • Help views are the search help version of views
  • They combine data using outer join, but we cannot update it hence it is a ‘READ-ONLY’ view
  • We can create help views on two or more tables, and we cannot run it directly
  • Help views are useful as a selection method when we use Search Help in ABAP

Summary

In this tutorial, we learnt about structures and views. We learnt their purpose, their functions, their types and how to create structures and views in ABAP.

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *