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.
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.
Steps
Intro
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 1Create your own ABAP package
—
Open Eclipse and connect to your system.
Right-click on the package ZLOCAL and choose New > ABAP Package from the context menu.
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
Click Next.
Create ABAP package
Select package properties and click Next.
Software Component: ZLOCAL
Create ABAP package
Select a transport request or create new and click Finish.
Transport request
Step 2Create a Structure
+
Create a Structure with a field Description.
Right-click on your ABAP package Z_Travel_### and select New > Other ABAP Repository Object from the context menu.
Structure Repo Object
Enter the filter text Structure > Structure, then choose Next.
Enter a name such as ZTravel_struc_### - always replacing ### with your initials or group number - and a description, then choose Next.
provide-structure-name
Accept the proposed transport request and click Finish.
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
@EndUserText.label:'Structure of Travel Data'@AbapCatalog.enhancement.category:#EXTENSIBLE_ANY@AbapCatalog.enhancement.fieldSuffix:'ZAC'@AbapCatalog.enhancement.quotaMaximumFields:350@AbapCatalog.enhancement.quotaMaximumBytes:3500definestructureztravel_struc_###{description:/dmo/description;}
Create a database table to store the Travel data. This Travel table contains Travel ID, Total Price and Currency Code.
Right-click on your ABAP package Z_Travel_### and select New > Other ABAP Repository Object from the context menu.
Table Repo Object
Enter the filter text Table > Database table, then choose Next.
Enter a name such as ZTravel_### - always replacing ### with your initials or group number - and a description, then choose Next.
provide-table-name
Accept the proposed transport request and click Finish.
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
@EndUserText.label:'Travel data for Extensibility'@AbapCatalog.enhancement.category:#EXTENSIBLE_ANY@AbapCatalog.tableCategory:#TRANSPARENT@AbapCatalog.deliveryClass:#A@AbapCatalog.dataMaintenance:#RESTRICTEDdefinetableztravel_###{keyclient:abap.clntnotnull;keytravel_id:/dmo/travel_idnotnull;@Semantics.amount.currencyCode:'ztravel_###.currency_code'total_price:/dmo/total_price;currency_code:/dmo/currency_code;includeztravel_struc_###;}
Create an ABAP class to generate demo travel data.
Right-click on your ABAP package Z_Travel_### and select New > ABAP Class from the context menu.
Enter a name such as ztravel_fill_data_### - always replacing ### with your initials or group number - and a description, then choose Next.
new class
Accept the proposed transport request and click Finish.
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
CLASSztravel_fill_data_###DEFINITIONPUBLICFINALCREATE PUBLIC.PUBLIC SECTION.INTERFACESif_oo_adt_classrun.PROTECTED SECTION.PRIVATE SECTION.ENDCLASS.CLASSztravel_fill_data_###IMPLEMENTATION.METHODif_oo_adt_classrun~main.* clear dataDELETEFROMztravel_###."insert travel demo data
INSERTztravel_###FROM(SELECTFROM/dmo/travelAStravelFIELDStravel~travel_idAStravel_id,travel~total_priceAStotal_price,travel~currency_codeAScurrency_code,travel~descriptionASdescription).COMMITWORK.out->write(| Data generated for table ztravel_### |).ENDMETHOD.ENDCLASS.
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 5Create a CDS view
+
Create a CDS view ZITravel_### based on the database table ZTravel_###
Right-click on your ABAP package Z_Travel_### and select New > Data Definition from the context menu.
CDS Object
Enter a Name such as ZITravel_### - always replacing ### with your initials or group number - and a description, then choose Next.
provide-CDS-name
Accept the proposed transport request and click Finish.
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
@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
{keytravel_idasTravelId,descriptionasDescription,@Semantics.amount.currencyCode:'CurrencyCode'total_priceasTotalPrice,currency_codeasCurrencyCode}
Click anywhere in the editor and choose Open With > Data Preview from the context menu.
CDS-data-preview
Step 6Extend the database table
+
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.
Right-click on the structure ZTravel_struc_### and select New > Append Structure from the context menu.
strcuture
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
Accept the proposed transport request and choose Finish.
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
@EndUserText.label:'Structure for Travel table extension'@AbapCatalog.enhancement.category:#NOT_EXTENSIBLEextendtype ztravel_struc_###withztravel_struc_ext_###{zztraveltype_zac:/dmo/carrier_name;}
Savesave iconand activateactivate icon.
Step 7Create a new ABAP class to generate the values for the newly added field
+
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'
Right-click on your ABAP package Z_Travel_### and select New > ABAP Class from the context menu.
Enter a Name such as ztravel_ext_data_### - always replacing ### with your initials or group number - and a description, then choose Next.
Accept the proposed transport request and click Finish.
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
CLASSztravel_ext_data_###DEFINITIONPUBLICFINALCREATE PUBLIC.PUBLIC SECTION.INTERFACESif_oo_adt_classrun.PROTECTED SECTION.PRIVATE SECTION.ENDCLASS.CLASSztravel_ext_data_###IMPLEMENTATION.METHODif_oo_adt_classrun~main.DATA:lt_travelTYPE TABLE OFztravel_###,ls_travelTYPE ztravel_###." Select existing data from the table
SELECT*FROMztravel_###INTOTABLE@lt_travel." Loop through the data and update the new field based on the logic
LOOP AT lt_travelINTOls_travel.IFls_travel-total_price>4500.ls_travel-zztraveltype_zac='Business'.ELSEIFls_travel-total_price>3000ANDls_travel-total_price<4500.ls_travel-zzTravelType_zac='Premium Economy'.ELSE.ls_travel-zzTravelType_zac='Economy'.ENDIF." Update the table with the new value
MODIFYztravel_###FROM@ls_travel.ENDLOOP.out->write(|Table updated|).ENDMETHOD.ENDCLASS.
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 8Extend the CDS View to consume the newly created custom field
+
Right-click on the CDS View ZITravel_### and select New > Data Definition from the context menu.
Enter a Name such as ZITravel_Ext_### - always replacing ### with your initials or group number - and a description, then choose Next.
provide-CDS-name
Accept the proposed transport request and click Finish.
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).
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 9Add a new calculated field to the extended CDS view
+
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.
Add a new field ZZDiscPriceZAC with the condition: If total_price > 1000, apply a 10% discount.
Copy the below code snippet and add below the exposed field ZZTravelTypeZAC
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 10Extend the view with an association to CDS view entity
+
You will expose FlightDate field from /DMO/I_BOOKING_U and calculate the number of days left from today until the flight date.
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).
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.
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 12
1. Create your own ABAP package2. Create a Structure3. Create a database table4. Create data generator class5. Create a CDS view6. Extend the database table7. Create a new ABAP class to generate the values for the newly added field8. Extend the CDS View to consume the newly created custom field9. Add a new calculated field to the extended CDS view10. Extend the view with an association to CDS view entity11. Test yourself12. More Information
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.