Quick guide into your own ABAP CDS compatibility views

ABAP CDS compatibility views

While researching the topic of the new data models introduced in SAP S/4HANA, I’ve noticed a limited availability of the technical information related to the “compatibility” ABAP CDS views, like the ones replacing the well-known MSEG and MKPF tables. And therefore, I would like to share some of my findings as a quick guide to creating your own “compatibility” ABAP CDS views.

For my own example I’ve taken an SFLIGHT and SBOOK tables, familiar to the most of you since your first steps in ABAP. Further in this article I’m going to work with an AA flight number 17 scheduled for 15-Dec-2016.

Figure 1: SFLIGHT table – AA flight 17 scheduled for 15.12.2016

I’ve considered the following rules while creating the compatibility view for the SFLIGHT table:

  • The number of components must match.
  • The names of the components must match (except for the client column) and must be in the same order.
  • The technical type properties predefined data type, length and number of decimal places must match for every component.

I’ve defined a view ZDP_V_SFLIGHT having the exact number of fields (14) with exact same names and technical properties as in the original SFLIGHT table. The following fields were replaced with the SBOOK table aggerates:

  • SFLIGHT-PAYMENTSUM: Total amount of bookings in local currency (sum of SBOOK-LOCCURAM for the flight where SBOOK-CANCELLED is blank)
  • SFLIGHT-SEATSOCC: Total seats occupied in economy class (count of SBOOK records for the flight where SBOOK-CANCELLED is blank and SBOOK-CLASS is “Y”)
  • SFLIGHT-SEATSOCC_B: Total seats occupied in business class (count of SBOOK records for the flight where SBOOK-CANCELLED is blank and SBOOK-CLASS is “C”)
  • SFLIGHT-SEATSOCC_F: Total seats occupied in first class (count of SBOOK records for the flight where SBOOK-CANCELLED is blank and SBOOK-CLASS is “F”)

Figure 2: SFLIGHT “compatibility” view

On top of it, SFLIGHT-PAYMENTSUM and SBOOK-LOCCURAM fields have different technical properties – data type CURR of length 17 and CURR of length 15 accordingly. In order to make it compatible with the SFLIGHT-PAYMENTSUM field, I’ve converted it to S_SUM data element using the cast expression.

cast(sum(case sbook.cancelled when ” then sbook.loccuram else 0 end) as s_sum) as paymentsum

I’ve used similar approach for the generic fields with occupied seats values:

cast(sum(case sbook.cancelled when ” then case sbook.class when ‘Y’ then 1 else 0 end else 0 end) as s_seatsocc) as seatsocc

cast(sum(case sbook.cancelled when ” then case sbook.class when ‘C’ then 1 else 0 end else 0 end) as s_socc_b) as seatsocc_b

cast(sum(case sbook.cancelled when ” then case sbook.class when ‘F’ then 1 else 0 end else 0 end) as s_socc_f) as seatsocc_f

As you have noticed above, instead of using count expression, I’m using sum combined with the case distinction in order to consider the booking class and cancellations. You may also split such and other actions into a several CDS views and join them with the join expressions. In that case you will be also able to use the count expression together with the where condition.

Figure 3: ABAP – Data Definition in Eclipse

In order to test the CDS view, I’ve cancelled a number of bookings in the SBOOK table by setting a cancellation flag into the SBOOK- CANCELLED field. After the SBOOK table changes have been saved, I’ve refreshed the SFLIGHT table and the ZDP_V_SFLIGHT table view outputs.

Figure 4: SBOOK – Cancellation flag set for several records


Figure 5: SFLIGHT table remains unchanged after several bookings have been cancelled

Figure 6: ZDP_V_SFLIGHT view after several bookings have been cancelled shows actual amount and number of the business class seats occupied

As expected, contents of the SFLIGHT table remain unchanged, while the ZDP_V_SFLIGHT view shows actual numbers.

The last step is assigning our newly created CDS view ZDP_V_SFLIGHT to the SFLIGHT table. I’m going to do it using a DD_SET_REDIRECT function module used by some of the SAP S/4HANA conversion programs. If there is a better/official way of doing this, you are welcome to share this information in the comments section.

When calling the function module, you have to fill the redirection map by specifying the following values:

  • OBJECTNAME – Name of the ABAP Dictionary object
  • OBJECTTYPE – ABAP Dictionary object type
  • REPLACENAME – of the ABAP Dictionary replacement object
  • REPLACETYPE – ABAP Dictionary replacement object type
  • ACTION – Action, use “CRE” to create and “DEL” to remove the redirection to the replacement object

Leave a default value equal to “0” for the return code field. Depending from the result, different return code could be assigned by the function module.

Figure 7: Function module DD_SET_REDIRECT input parameters

Once the function module DD_SET_REDIRECT has been successfully executed, you will see the proxy object assignment in the ABAP Dictionary. When executing the SFLIGHT table queries, the aggregated values, calculated based on the SBOOK table contents, are displayed. Every time you update the SBOOK table, the change is also reflected when reading the SFLIGHT table.

Figure 8: ABAP Dictionary – Proxy Object for SFLIGHT

Figure 9: SFLIGHT output after the proxy object assignment


To sum up, I would like to highlight several resources I’ve found useful while looking into understanding the way how the “compatibility” views and ABAP CDS views in general are made:

  1. Downloading and setting up Eclipse based ABAP Development Tools for SAP NetWeaver you would need to work with ABAP CDS views-

If you are new to Eclipse, I would mention that it utilizes your existing SAP connections and does not require any additional setup of your SAP system on top of it. Using Eclipse, you can also explore the code inside the existing compatibility views delivered by SAP as part of SAP S/4HANA package.

  1. Complete reference on ABAP CDS in ABAP Dictionary –
  2. Set of rules and notes to consider when dealing with database table replacement objects –
  3. Collection of useful links to a various CDS related topics:

2 comments on “Quick guide into your own ABAP CDS compatibility views

  1. Rahul Kumar on

    Very Impressive SAP HANA tutorial. The content seems to be pretty exhaustive and excellent and will definitely help in learning SAP HANA. I’m also a learner taken up SAP HANA training and I think your content has cleared some concepts of mine. While browsing for SAP HANA tutorials on YouTube i found this fantastic video on SAP HANA. Do check it out if you are interested to know more.:-


Leave a Reply

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