You have connected an ABAP system to Visual Studio Code following the previous tutorial in this group .
Steps
Introduction
ABAP development tools for Visual Studio Code provides an efficient and feature-rich set of tools for ABAP development within the ABAP Cloud development model. It brings modern ABAP development to your editor, enabling you to create, edit, debug, and manage ABAP artifacts directly in VS Code. You need to set up your development environment in Visual Studio Code and connect it to your ABAP system.
This tutorial focus on non-Agentic AI capabilities and do not need any coding agent extension in Visual Studio Code (for e.g: GitHub Copilot)
Step 1Add package as folder to workspace in VS Code
—
You need to have a package created in ADT. This package can be added as a folder to workspace.
Open the Command Palette or Ctrl+Shift+P.Add Package
Type ABAP: Add Package as folder to Workspace
Search the package you have created in ADT.Search Package
Enter Workspace folder name.Folder Name
Folder is added to WorkspaceWorkspace Name
Step 2Logon to Destination
+
During any time if you have been logged out of system, you need to Log On to the Destination to continue the work by following options:
Right click on the Package which is added as a Folder to Workspace and choose “Log On to Destination”LogonOR
Open the Command Palette or Ctrl+Shift+P.
Type ABAP: Log On to DestinationLogon
Select the Destination. This will prompt to open the system in browser to enter the logon credentialsLogon
Step 3Open object
+
Open the Command Palette or Ctrl+Shift+P.
Type ABAP: Open ObjectOpen Object
Give the name of the object. E.g “I_Currency”. You can search for class, data definition.Search Object
You can analyse the opened object.View Object
Objects with unsaved backend changes are marked (L) — they must be activated (Ctrl+F3) to become active in the system.
Step 4Create new Databse table
+
Open the Command Palette or Ctrl+Shift+P.
Type ABAP: Create New ABAP ObjectCreate Object
You can choose the object type that you want to create. Choose ‘Database Table’.choose Table
Choose the package name that was used in the previous step.choose Package
Enter the name of the Database Table ‘ZADT_Travel_###’to be created and press Enter to confirm.Table Name
Give a DescriptionTable Description
A new ‘Database Table’ will be created.
Copy the below code and replace it in the Database table. Replace ‘###’ with the unique number that you have given.
Type ABAP: Check Object. This will run the syntax check on the opened object. The message ‘Running Syntax check’ appears in the Status barCheck Object
To Activate an object: open the Command PaletteCtrl+Shift+P and Type ABAP: Activate.Activate Object
You can also use Ctrl+F3. Activate icon is also available on top of the editor window.
Button Object
Step 6Create a data generator Class
+
Open the Command Palette or Ctrl+Shift+P.
Type ABAP: Create New ABAP ObjectCreate Object
You can choose the object type that you want to create. Choose ‘Class’.choose Object
Choose the package name that was used in the previous step.choose Package
Enter the name of the Class to be created and press Enter to confirm.Class Name
Give a DescriptionClass Description
Choose a Super Class and interface if required.Add Interface
A new ‘Class’ will be created.Class created
Copy the below code and replace it in the Class. Replace ‘###’ with the unique number that you have given.
ABAP
CLASSzcl_adt_travel_###DEFINITIONPUBLICFINALCREATE PUBLIC.PUBLIC SECTION.INTERFACESif_oo_adt_classrun.PROTECTED SECTION.PRIVATE SECTION.ENDCLASS.CLASSzcl_adt_travel_###IMPLEMENTATION.METHODif_oo_adt_classrun~main.DATA:group_idTYPE stringVALUE'###'.*cleardataDELETEFROMzadt_travel_###.*DELETEFROMzadt_travel_###."insert travel demo data
INSERTzadt_travel_###FROM(SELECTFROM/dmo/travelAStravelFIELDStravel~travel_idAStravel_id,travel~agency_idASagency_id,travel~customer_idAScustomer_id,travel~begin_dateASbegin_date,travel~end_dateASend_date,travel~booking_feeASbooking_fee,travel~total_priceAStotal_price,travel~currency_codeAScurrency_code,travel~descriptionASdescription,CASEtravel~status"[N(New) | P(Planned) | B(Booked) | X(Cancelled)]
WHEN'N'THEN'O'WHEN'P'THEN'O'WHEN'B'THEN'A'ELSE'X'ENDASoverall_status,travel~createdbyAScreated_by,travel~createdatAScreated_at,travel~lastchangedbyASlast_changed_by,travel~lastchangedatASlast_changed_at,travel~lastchangedatASlocal_last_changed_atORDER BYtravel_idUPTO10ROWS).COMMITWORK.out->write(| Demo data generated for table zadt_travel_{group_id}. |).ENDMETHOD.ENDCLASS.
To Format the document, right click on the class and choose Format Document.Format Class
Save and Activate the new Class by following Step 5.
Now execute your class by hitting F5 or Type ABAP: Open with ADT for Eclipse in the Command Palette.Execute Class
You will get a message ‘Demo data generated for table zadt_travel_###’ in the console.
Step 7Create new CDS View
+
Open the Command Palette or Ctrl+Shift+P.
Type ABAP: Create New ABAP ObjectCreate Object
You can choose the object type that you want to create. Choose ‘Data Definition’.choose CDS
Choose the package name that was used in the previous step.CDS Package
Enter the name of the Database Definition ‘ZI_ADT_Travel_###’to be created and press Enter to confirm.CDS Name
Give a Description
In the next step you can choose the reference object for the new CDS view to be buildReference Object
A new ‘Data Definition’ will be created.
Copy the below code and replace it in the CDS View Entity. Replace ‘###’ with the unique number that you have given.
CDS
@AbapCatalog.viewEnhancementCategory: [#NONE] @AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: 'CDS view for ADT Tools' @Metadata.ignorePropagatedAnnotations: true define view entity ZI_ADT_Travel_### as select from ZADT_TRAVEL_### { key travel_id as TravelId, agency_id as AgencyId, customer_id as CustomerId, begin_date as BeginDate, end_date as EndDate, @semantics.amount.currencyCode: 'CurrencyCode' booking_fee as BookingFee, @semantics.amount.currencyCode: 'CurrencyCode' total_price as TotalPrice, currency_code as CurrencyCode, description as Description, overall_status as OverallStatus, created_by as CreatedBy, created_at as CreatedAt, local_last_changed_by as LocalLastChangedBy, local_last_changed_at as LocalLastChangedAt, last_changed_at as LastChangedAt }
Activate the new CDS View Entity by following Step 5
Step 8Open with ADT for Eclipse
+
We will open the newly created CDS view in ADT for Eclipse.
Open the Command Palette or Ctrl+Shift+P.
Type ABAP: Open with ADT for EclipseOpen ADT
CDS View Entity is opened in ADT for Eclipse.
Step 9Preview of a Fiori Application
+
Open the Command Palette or Ctrl+Shift+P.
Type ABAP: Open ObjectOpen Object
Search for the Service Binding ‘/DMO/UI_TRAVEL_APPR_M_O2’Search Service
Object opens and there are 3 options.Preview Service
Publish/Unpublish depending if the Service binding is Published or not
Preview: To preview the Fiori Application
Create a SAP Fiori app
Click on Preview
This will launch Fiori Application in Preview mode.
Step 10Create a new class method to display 10 records
+
First create a new class ZCL_ADTVSCODE_### by following the same steps in Create a data generator Class section until Step 4. In the newly created class we will add a new method to display 10 rows from the table /dmo/carrier. Copy the below code and replace it with the code in the new class.
ABAP
CLASSzcl_adtvscode_###DEFINITIONPUBLICFINALCREATE PUBLIC.PUBLIC SECTION.INTERFACESif_oo_adt_classrun.PROTECTED SECTION.PRIVATE SECTION.TYPEStt_carriersTYPE STANDARD TABLE OF/dmo/carrierWITHDEFAULTKEY.METHODSget_carriersRETURNINGVALUE(rt_carriers)TYPE tt_carriers.ENDCLASS.CLASSzcl_adtvscode_###IMPLEMENTATION.METHODif_oo_adt_classrun~main.out->write(get_carriers()).ENDMETHOD.METHODget_carriers.SELECT*FROM/dmo/carrierINTOTABLE@rt_carriersUPTO10ROWS.ENDMETHOD.ENDCLASS.
To view the result in the console, Open the Output from View option.output
Run the class to see the output. Open the Command PaletteCtrl+Shift+P.
Type ABAP: Run ABAP Application(Console)Run Object
You can see the result under Output tab.result
Step 11Debug a method
+
To debug let us use a the same class created in the previous step. First put a Breakpoint at the SELECT statement by clicking to the left of the line number as shown in the below screenshot.Add Breakpoint
Once the breakpoint is set, it’ll be highlighted.
To Run the ABAP Application, you can right click on the editor and choose Run ABAP Application (Console).Run Breakpoint
Run and Debug view will be opened to the left of the editor. You will see the parameter RT_CARRIERS which doesnt have any entries now.DebugView
Now let us execute the select statement by clicking on Step Into or F11.StepInto
After executing the select statement we can see that RT_CARRIERS now has 10 entries.
We can open each record to analyze the data.records
Step 12Run ABAP Test Cockpit (ATC) Checks.
+
Using ATC you can detect the quality issues with regards to performance, security & programming conventions by regularly executing static and dynamic checks. We will run ATC Checks on the same class used to Debug in the above step.
Open the Command PaletteCtrl+Shift+P.
Type ABAP: Run ABAP Test Cockpit or Ctrl+Shift+F10Run ATC
Check the Problems tab to view the ATC findings as shown below.ATC Findings
Step 13Run Unit Test
+
Enhance the CDS view ZI_ADT_Travel_### created in Step 7 to include a new DiscountedFlightPrice field.
Add the following code lines for the field DiscountedFlightPrice to provide 10% discount on the total price if total_price is > 1000.
Your CDS data definitiondata definitionZI_ADT_Travel_### should look like this:
CDS
@AbapCatalog.viewEnhancementCategory: [#NONE] @AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: 'CDS view for ADT Tools' @Metadata.ignorePropagatedAnnotations: true define view entity ZI_ADT_Travel_### as select from zadt_travel_### { key travel_id as TravelId, agency_id as AgencyId, customer_id as CustomerId, begin_date as BeginDate, end_date as EndDate, @Semantics.amount.currencyCode: 'CurrencyCode' booking_fee as BookingFee, @Semantics.amount.currencyCode: 'CurrencyCode' total_price as TotalPrice, case when total_price > 1000 then cast(total_price as abap.dec(16,2)) * cast('0.90' as abap.dec(5,2)) else cast(total_price as abap.dec(16,2)) end as DiscountedFlightPrice, currency_code as CurrencyCode, description as Description, overall_status as OverallStatus, created_by as CreatedBy, created_at as CreatedAt, local_last_changed_by as LocalLastChangedBy, local_last_changed_at as LocalLastChangedAt, last_changed_at as LastChangedAt }
Savesave iconCtrl+S and activateactivate iconthe changes.
Now switch to Eclipse and create a unit test class for the CDS view above. In the Project Explorer, right-click on the CDS data definition ZI_ADT_Travel_### and select New ABAP Test Class from the context menu.
Enter the information below in the popup for the new ABAP Class that will be created and click on Next.
Name: ZCL_TEST_CDS_TRAVEL_###
Description: Test Class for CDS View ZI_ADT_Travel_###
The popup now displays the SQL dependencies for the CDS Test Double Framework.Dependencies
Click on Next 2 times and finally click on Finish.
Copy and replace the entire code inside the test class with the code below:
ABAP
"!@testing ZI_ADT_TRAVEL
CLASSltc_zi_adt_travelDEFINITIONFINALFORTESTINGRISKLEVELHARMLESSDURATIONSHORT.PRIVATE SECTION.CLASS-DATAenvironmentTYPE REF TOif_cds_test_environment.DATAtd_zadt_travelTYPE STANDARD TABLE OFzadt_travelWITHEMPTYKEY.DATAact_resultsTYPE STANDARD TABLE OFzi_adt_travelWITHEMPTYKEY.DATAexp_resultsTYPE STANDARD TABLE OFzi_adt_travelWITHEMPTYKEY."! In CLASS_SETUP, corresponding doubles and clone(s) for the CDS view under test and its dependencies are created.
CLASS-METHODSclass_setupRAISINGcx_static_check."! In CLASS_TEARDOWN, Generated database entities (doubles & clones) should be deleted at the end of test class execution.
CLASS-METHODSclass_teardown."! SETUP method creates a common start state for each test method,
"! clear_doubles clears the test data for all the doubles used in the test method before each test method execution.
METHODSsetupRAISINGcx_static_check."! In this method test data is inserted into the generated double(s) for test case
"! "Calculate DISCOUNTEDFLIGHTPRICE field"
METHODStd_calc_discountedflightprice."! In this method test data is inserted into the generated double(s) for test case
"! "When total_price > 1000"
METHODStd_total_price_gt_1000."! <strong>Test Case:</strong> Calculate DISCOUNTEDFLIGHTPRICE field <br><br>
"! Test calculation of DISCOUNTEDFLIGHTPRICE field.
"! <br><br> The results should be asserted with the actuals.
METHODScalc_discountedflightpriceFORTESTINGRAISINGcx_static_check."! <strong>Test Case:</strong> When total_price > 1000 <br><br>
"! Test a CDS View when the CASE condition When total_price > 1000 is satisfied.
"! <br><br> The results should be asserted with the actuals.
METHODStotal_price_gt_1000FORTESTINGRAISINGcx_static_check.ENDCLASS.CLASSltc_ZI_ADT_TRAVELIMPLEMENTATION.METHODclass_setup.environment=cl_cds_test_environment=>create(i_for_entity='ZI_ADT_TRAVEL_###').ENDMETHOD.METHODsetup.environment->clear_doubles().ENDMETHOD.METHODclass_teardown.environment->destroy().ENDMETHOD.METHODcalc_discountedflightprice.td_calc_discountedflightprice().SELECT*FROMzi_adt_travel_###INTOTABLE@act_results.cl_abap_unit_assert=>assert_equals(exp=lines(exp_results)act=lines(act_results)msg='Test Generated using AI: Recheck test data').LOOP AT exp_resultsINTODATA(exp_result).cl_abap_unit_assert=>assert_equals(exp=exp_result-discountedflightpriceact=act_results[sy-tabix]-discountedflightpricemsg='Test Generated using AI: Expected result for field DISCOUNTEDFLIGHTPRICE is incorrect. Recheck test data.').ENDLOOP.ENDMETHOD.METHODtd_calc_discountedflightprice." Prepare test data for 'ZADT_TRAVEL_###'
td_zadt_travel=VALUE#((client='100'travel_id='00000001'total_price='1200.00')).environment->insert_test_data(i_data=td_zadt_travel)." Prepare test data for 'zi_adt_travel_###'
exp_results=VALUE#((travelid='00000001'totalprice='1200.00'discountedflightprice='1080.00')).ENDMETHOD.METHODtotal_price_gt_1000.td_total_price_gt_1000().SELECT*FROMzi_adt_travel_###INTOTABLE@act_results.cl_abap_unit_assert=>assert_equals(exp=lines(exp_results)act=lines(act_results)msg='Test Generated using AI: Recheck test data').LOOP AT exp_resultsINTODATA(exp_result).cl_abap_unit_assert=>assert_equals(exp=exp_result-DiscountedFlightPriceact=act_results[sy-tabix]-DiscountedFlightPricemsg='Test Generated using AI: Expected result for field DiscountedFlightPrice is incorrect. Recheck test data.').ENDLOOP.ENDMETHOD.METHODtd_total_price_gt_1000." Prepare test data for 'ZADT_TRAVEL_###'
td_zadt_travel=VALUE#((client='100'travel_id='00000001'total_price='1200.00')).environment->insert_test_data(i_data=td_zadt_travel)." Prepare test data for 'zi_adt_travel_###'
exp_results=VALUE#((travelid='00000001'totalprice='1200.00'discountedflightprice='1080.00')).ENDMETHOD.ENDCLASS.
Savesave iconCtrl+S and activateactivate iconthe changes.
Now switch back to Visual Studio code and open the class zcl_test_cds_travel_###.clas.testclasses.abap file in editor as shown below.Open Testclass
Run the Unit Test by hitting Ctrl+Shift+F10 or Type ABAP: Run ABAP Unit Tests.Unit Test
The unit test results will be shown as below:Test Result
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 14
1. Add package as folder to workspace in VS Code2. Logon to Destination3. Open object4. Create new Databse table5. Check and Activate Object6. Create a data generator Class7. Create new CDS View8. Open with ADT for Eclipse9. Preview of a Fiori Application10. Create a new class method to display 10 records11. Debug a method12. Run ABAP Test Cockpit (ATC) Checks.13. Run Unit Test14. Test yourself
Joule
AI Notice
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.