Skip to Content

Extend a Custom Core Data Service in ABAP Environment

Explore developer extensibility by creating a CDS view and extending it in ABAP Environment.
You will learn
  • How to extend SAP or custom table using Extensibility model
  • How to extend a CDS view by adding a new field
  • How to implement custom logic
  • How to consume fields from other exposed CDS view using Associations
shilpashankar02Shilpa ShankarOctober 30, 2025
Created by
rbrainey
September 15, 2025
Contributors
rbrainey

Prerequisites

  • You need to have access to an SAP BTP, ABAP environment, or SAP S/4HANA Cloud, ABAP environment or SAP S/4HANA (release 2022 or higher) system.
    For example, you can create a free trial user on SAP BTP, ABAP environment.
  • You have downloaded and installed the latest ABAP Development Tools (ADT) on the latest Eclipse© platform.
  • You have created an ABAP Cloud Project.
  • Your system has the ABAP flight reference scenario. If your system hasn’t this scenario. You can download it here. The trial systems have the flight scenario included.

This tutorial was written for SAP BTP ABAP Environment. However, you should also be able to use it in SAP S/4HANA Cloud Environment in the same way.
Always replace ### with your initials or group number.

  • Step 1
    1. Open Eclipse and connect to your system.

    2. Right-click on the package ZLOCAL and choose New > ABAP Package from the context menu.

    3. Create your own ABAP development package Z_Travel_### as a sub package of ZLOCAL.

      • Name: Z_Travel_###
      • Description: My travel package
      • Select the Add to favorite packages box
    4. Click Next.

      Create ABAP package
    5. Select package properties and click Next.

      • Software Component: ZLOCAL
      Create ABAP package
    6. Select a transport request or create new and click Finish.

      Transport request
  • Step 2

    Create a Structure with a field Description.

    1. Right-click on your ABAP package Z_Travel_### and select New > Other ABAP Repository Object from the context menu.

      Structure Repo Object
    2. Enter the filter text Structure > Structure, then choose Next.

    3. Enter a name such as ZTravel_struc_### - always replacing ### with your initials or group number - and a description, then choose Next.

      provide-structure-name
    4. Accept the proposed transport request and click Finish.

    5. Replace the default code with the code snippet provided below and replace all occurrences of the placeholder ### with your group ID using the Replace All function (CTRL+F).

      ABAP
      Copy
      @EndUserText.label : 'Structure of Travel Data'
      @AbapCatalog.enhancement.category : #EXTENSIBLE_ANY
      @AbapCatalog.enhancement.fieldSuffix : 'ZAC'
      @AbapCatalog.enhancement.quotaMaximumFields : 350
      @AbapCatalog.enhancement.quotaMaximumBytes : 3500
      define structure ztravel_struc_### {
      
        description : /dmo/description;
      
      }
      
    6. Save

      save icon
      and activate
      activate icon
      the changes.

  • Step 3

    Create a database table to store the Travel data. This Travel table contains Travel ID, Total Price and Currency Code.

    1. Right-click on your ABAP package Z_Travel_### and select New > Other ABAP Repository Object from the context menu.

      Table Repo Object
    2. Enter the filter text Table > Database table, then choose Next.

    3. Enter a name such as ZTravel_### - always replacing ### with your initials or group number - and a description, then choose Next.

      provide-table-name
    4. Accept the proposed transport request and click Finish.

    5. Replace the default code with the code snippet provided below and replace all occurrences of the placeholder ### with your group ID using the Replace All function (CTRL+F).

      ABAP
      Copy
      @EndUserText.label : 'Travel data for Extensibility'
      @AbapCatalog.enhancement.category : #EXTENSIBLE_ANY
      @AbapCatalog.tableCategory : #TRANSPARENT
      @AbapCatalog.deliveryClass : #A
      @AbapCatalog.dataMaintenance : #RESTRICTED
      define table ztravel_### {
      
        key client    : abap.clnt not null;
        key travel_id : /dmo/travel_id not null;
        @Semantics.amount.currencyCode : 'ztravel_###.currency_code'
        total_price   : /dmo/total_price;
        currency_code : /dmo/currency_code;
        include ztravel_struc_###;
      
      }
      
    6. Save

      save icon
      and activate
      activate icon
      the changes.

  • Step 4

    Create an ABAP class to generate demo travel data.

    1. Right-click on your ABAP package Z_Travel_### and select New > ABAP Class from the context menu.

    2. Enter a name such as ztravel_fill_data_### - always replacing ### with your initials or group number - and a description, then choose Next.

      new class
    3. Accept the proposed transport request and click Finish.

    4. Replace the default code with the code snippet provided below and replace all occurrences of the placeholder ### with your group ID using the Replace All function (CTRL+F).

      ABAP
      Copy
      CLASS ztravel_fill_data_### DEFINITION
        PUBLIC
        FINAL
        CREATE PUBLIC .
      
        PUBLIC SECTION.
          INTERFACES if_oo_adt_classrun.
        PROTECTED SECTION.
        PRIVATE SECTION.
      ENDCLASS.
      
      CLASS ztravel_fill_data_### IMPLEMENTATION.
      
        METHOD if_oo_adt_classrun~main.
      
      *   clear data
          DELETE FROM ztravel_###.
      
          "insert travel demo data
      
          INSERT ztravel_### FROM (
          SELECT
            FROM /dmo/travel AS travel
            FIELDS
            travel~travel_id AS travel_id,
            travel~total_price AS total_price,
            travel~currency_code AS currency_code,
            travel~description AS description
          ).
          COMMIT WORK.
          out->write( | Data generated for table ztravel_### | ).
        ENDMETHOD.
      ENDCLASS.
      
    5. Save
      save icon
      and activate
      activate icon
      the changes.
    6. Run your console application. For that, select your ABAP class ztravel_fill_data_###, select the run button > Run As > ABAP Application (Console) F9 or press F9.

      class
  • Step 5

    Create a CDS view ZITravel_### based on the database table ZTravel_###

    1. Right-click on your ABAP package Z_Travel_### and select New > Data Definition from the context menu.

      CDS Object
    2. Enter a Name such as ZITravel_### - always replacing ### with your initials or group number - and a description, then choose Next.

      provide-CDS-name
    3. Accept the proposed transport request and click Finish.

    4. Replace the default code with the code snippet provided below and replace all occurrences of the placeholder ### with your group ID using the Replace All function (CTRL+F).

      ABAP
      Copy
          @AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST]
          @AccessControl.authorizationCheck: #NOT_REQUIRED
          @EndUserText.label: 'Travel View Entity'
          @Metadata.ignorePropagatedAnnotations: true
          @AbapCatalog.extensibility: {
            extensible: true,
            elementSuffix: 'ZAC',
            quota: {
              maximumFields: 500,
              maximumBytes: 5000
            },
            dataSources: [ '_Travel' ]
          }
          define view entity ZITRAVEL_###
            as select from ztravel_### as _Travel
          {
            key travel_id     as TravelId,
                description   as Description,
                @Semantics.amount.currencyCode: 'CurrencyCode'
                total_price   as TotalPrice,
                currency_code as CurrencyCode
          }
      
    5. Save
      save icon
      and activate
      activate icon
      the CDS view.
    6. Click anywhere in the editor and choose Open With > Data Preview from the context menu.

      CDS-data-preview
  • Step 6

    Let us consider a database table that is defined by a software provider, for example, SAP. A customer or partner wants to add fields to this database table.

    Instead of adding the fields to the database table definition in the dictionary, they create an append structure. The append structure is a separate dictionary object, owned and maintained by the customer or partner.

    1. Right-click on the structure ZTravel_struc_### and select New > Append Structure from the context menu.

      strcuture
    2. Enter a Name such as ZTravel_struc_ext_###- always replacing ### with your initials or group number - and a description, then choose Next.

      provide-CDS-name
    3. Accept the proposed transport request and choose Finish.

    4. Replace the default code with the code snippet provided below and replace all occurrences of the placeholder ### with your group ID using the Replace All function (CTRL+F).

      ABAP
      Copy
      @EndUserText.label : 'Structure for Travel table extension'
      @AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
      extend type ztravel_struc_### with ztravel_struc_ext_### {
      
      zztraveltype_zac : /dmo/carrier_name;
      
      }
      
    5. Save

      save icon
      and activate
      activate icon
      .

  • Step 7

    The new field zztraveltype_zac should be filled with the below logic in the ABAP class.

    If `total_price` > 4500, set Travel Type to 'Business'.
    Else, if `total_price` > 3000, set Travel Type to 'Premium Economy'.
    Otherwise, set Travel Type to 'Economy'
    
    1. Right-click on your ABAP package Z_Travel_### and select New > ABAP Class from the context menu.

    2. Enter a Name such as ztravel_ext_data_### - always replacing ### with your initials or group number - and a description, then choose Next.

    3. Accept the proposed transport request and click Finish.

    4. Replace the default code with the code snippet provided below and replace all occurrences of the placeholder ### with your group ID using the Replace All function (CTRL+F).

      ABAP
      Copy
        CLASS ztravel_ext_data_### DEFINITION
        PUBLIC
        FINAL
        CREATE PUBLIC .
      
        PUBLIC SECTION.
          INTERFACES if_oo_adt_classrun.
        PROTECTED SECTION.
        PRIVATE SECTION.
      ENDCLASS.
      
      CLASS ztravel_ext_data_### IMPLEMENTATION.
      
        METHOD if_oo_adt_classrun~main.
          DATA: lt_travel TYPE TABLE OF ztravel_###,
                ls_travel TYPE ztravel_###.
      
          " Select existing data from the table
          SELECT * FROM ztravel_### INTO TABLE @lt_travel.
      
          " Loop through the data and update the new field based on the logic
          LOOP AT lt_travel INTO ls_travel.
            IF ls_travel-total_price > 4500.
              ls_travel-zztraveltype_zac = 'Business'.
            ELSEIF ls_travel-total_price > 3000 AND ls_travel-total_price < 4500.
              ls_travel-zzTravelType_zac = 'Premium Economy'.
            ELSE.
              ls_travel-zzTravelType_zac = 'Economy'.
            ENDIF.
      
            " Update the table with the new value
            MODIFY ztravel_### FROM @ls_travel.
          ENDLOOP.
          out->write( |Table updated| ).
        ENDMETHOD.
      ENDCLASS.
      
    5. Save
      save icon
      and activate
      activate icon
      the changes.
    6. Run your console application. For that, select your ABAP class ztravel_ext_data_###, select the run button > Run As > ABAP Application (Console) F9 or press F9.

  • Step 8
    1. Right-click on the CDS View ZITravel_### and select New > Data Definition from the context menu.

    2. Enter a Name such as ZITravel_Ext_### - always replacing ### with your initials or group number - and a description, then choose Next.

      provide-CDS-name
    3. Accept the proposed transport request and click Finish.

    4. Replace the default code with the code snippet provided below and replace all occurrences of the placeholder ### with your group ID using the Replace All function (CTRL+F).

      ABAP
      Copy
          extend view entity ZITRAVEL_### with {
          _Travel.zztraveltype_zac as ZZTravelTypeZAC
          }
      
    5. Save

      save icon
      and activate
      activate icon
      the changes.

    6. Click anywhere in the editor and choose Open With > Data Preview from the context menu. The newly added field comes up in the data preview with the data filled.

  • Step 9

    While in the previous step, we added the logic in the ABAP class which updates the database table, in this step we will check how to dynamically calculate the values and add in a new field in the extended CDS view.

    1. Add a new field ZZDiscPriceZAC with the condition: If total_price > 1000, apply a 10% discount.

    2. Copy the below code snippet and add below the exposed field ZZTravelTypeZAC

      ABAP
      Copy
        @Semantics.amount.currencyCode: 'CurrencyCode'
        case
          when _Travel.total_price > 1000
            then  cast( _Travel.total_price as abap.dec(15,1) ) * cast( '0.9' as abap.dec(2,1) )
          else cast( _Travel.total_price as abap.dec(15,1) )
        end                      as ZZDiscPriceZAC
      
    3. Save

      save icon
      and activate
      activate icon
      the changes.

    4. Click anywhere in the editor and choose Open With > Data Preview from the context menu. A new field ZZDiscPriceZAC comes up with the dynamic calculation.

  • Step 10

    You will expose FlightDate field from /DMO/I_BOOKING_U and calculate the number of days left from today until the flight date.

    1. Below is the complete code of the extended view entity . Replace all occurrences of the placeholder ### with your group ID using the Replace All function (CTRL+F).

      ABAP
      Copy
        extend view entity ZITRAVEL_### with
      
        association [1..1] to /DMO/I_Booking_U as _ZZBooking on $projection.TravelId = _ZZBooking.TravelID
        {
          _Travel.zztraveltype_zac as ZZTravelTypeZAC,
      
          @Semantics.amount.currencyCode: 'CurrencyCode'
          case
            when _Travel.total_price > 1000
              then  cast( _Travel.total_price as abap.dec(15,1) ) * cast( '0.9' as abap.dec(2,1) )
            else cast( _Travel.total_price as abap.dec(15,1) )
          end                      as ZZDiscPriceZAC,
      
          _ZZBooking.FlightDate    as ZZFlightDateZAC,
      
          case
            when _ZZBooking.FlightDate > $session.system_date then
      
            dats_days_between( _ZZBooking.FlightDate, $session.system_date )
      
          else 0
          end                      as ZZDaysRemainingZAC
        }
      
    2. Save

      save icon
      and activate
      activate icon
      the changes.

    3. Click anywhere in the editor and choose Open With > Data Preview from the context menu. There will be 4 custom fields added through Developer Extensibility.

  • Step 11

    What is the recommended way to extend a database table?

Back to top