Site icon Learn SAP HANA through easy tutorials

Creating SAP ABAP Views

The SAP ABAP View

Welcome everyone to the next BI ABAP tutorial on how to create an SAP ABAP view. This will require your understanding of joins and I highly recommend reading our tutorial on joins before reading this one.

Before we continue this tutorial, I would ask you to read this tutorial on JOIN types in SAP and come back to this tutorial when finished. If you already know what a JOIN is and it’s types, you can proceed.

A view, as discussed earlier is a logical combination of different related tables which, at run-time provides the fields required for analysing a business problem. The data representation here is purely virtual and is not persisted in the disk. Views take data from the persisted tables and generate a run-time query that displays a new structure with the desired fields for further analysis.

An actual business requirement?..hmm..Interesting

Let’s take a real business scenario using sales document data as an example. Sales documents have two parts – A header and an item. If you are new to this concept, you can visualize this in the form of any bill that you have received till date. Such a bill has a header/top part that always remains constant providing probably the company name, address and some more header level information. Thereafter, there is an Item section which contains individual items that you have ordered. In SAP, header and item details are often stored in separate header tables and item tables. Our example will utilize the sales document header table – VBAK and the sales document item table VBAP. These are two of the most commonly used tables for analysis in actual projects.

First, let’s decide on which fields we need from each table. We go into the SE11 TCODE as usual to display the table to see all it’s fields.

You can see that the table contains 156 fields and has field MANDT and VBELN as keys. MANDT is the client number. If you remember from our initial tutorials where we discussed about Clients, they are logical partitions of the database and most SAP tables are cross client and will contain MANDT as the first field in key. VBELN is the sales document number and is also the key. From this table, we will also pick up VBTYP (Document Category) and AUART (Sales Document Type).

Now that we have analyzed which fields we need from this table, let’s go to our line item table VBAP to check what we need from there. We use the same procedure to get there. Go SE11, provide the table name as VBAP and click Display.

From here, let’s take POSNR since that is the key that identifies the item number, MATNR (Material Number) and MATWA (Material entered).

Now, we know our requirement.

Building our first SAP ABAP View

To do this, go to SE11 again but this time click on the “View” radio button and enter in the name of the view you wish to create. I give it a name ZSALES_VIEW. Press the create button when done.

Choose the view type as Database View.

Now, you reach the view builder screen where you need to enter the view description, the names of involved tables and join conditions as marked in the image below. The join conditions are the fields based on which you can combine two tables. The joining condition here would be the sales document header VBELN and also the client ID MANDT. Client ID MANDT should be a default join condition in all SAP table joins as they would be cross client tables.

Once done, it should look like the below. Now, move on to the View fields tab to specify the fields you wish to select from each table.

You can either write it or take the easy route and click on Table Fields button.

This will display the list of involved tables as shown below. Double click on the first table – VBAK in this case.

This will open up the list of all fields in VBAK table along with check-boxes in front of them.

Mark the checkboxes to select a field. As discussed before, we need MANDT, VBELN and VBTYP from this table. Consequently, we mark them as below. Press Copy to confirm.

As seen below, the fields and their relevant information get auto-populated.

Repeat the same steps for table VBAP and its fields POSNR, MATNR and MATWA.

Once you press copy, all the VBAP fields we marked also become available in the view as shown below. Press activate to activate this view.

Note: You can additionally also go to selection conditions tab to specify filter conditions to filter out records you don’t want to involve in this join.

Save it as a local object.

As seen now, the SAP ABAP view has become active. Pressing the black button marked by the arrow displays the data contents of this view. The same button can be used in tables to see their data as well.

This opens up the data browser. You can run the data preview for a particular filter that you can enter here or to just run and preview the data, press execute.

Note: The maximum no. of hits column below is filled by default as 500 rows. If you wish to preview more/less data, increase/decrease the number manually before executing.

As seen below, both tables have successfully joined to create a view with fields from the source tables VBAK and VBAP.

Important thing to note here is that there was no option to choose the type of join . Sadly, joins using this method only support inner joins. If you require any other type of join, you would have to code it in an ABAP program.

This ends the tutorial on creating an SAP ABAP View. These will be used when we build DataSources. But before that we need to learn some basic amount of SAP ABAP coding in the coming tutorials.

Thank you for reading this tutorial and if you liked it, please show your support by sharing this document across social media by pressing the share buttons below and also don’t forget to subscribe to our newsletter for alerts on new tutorials that are added regularly.

Update (1-Nov-2016) : Due to time constraints, I have discontinued ABAP tutorials for now to focus on SAP HANA related topics. I will try to add to this in the future, but for now, this section will contain no further ABAP for BW topics. My apologies for this.

Happy Learning.

<<Previous Tutorial                                                                                                                 

Exit mobile version