Consuming CDS for – New And Experienced professionals- 2
There are many SAP blogs out there that explains inner working of CDS views or core data services in SAP’s S/4 boxes. But there are still struggle among experienced professionals who is switching from ECC system to S/4.
This blog is dedicated towards experienced professionals working on ECC systems for many years and yet to jump to S/4.In the next few min, we will look at a very basic concept of a CDS view and try to evaluate inner working of the CDS using classic SAP tools.
You have read / understood / Prototype items on Previous blog.
Lets Start –
At this point we have a CDS view created in the previous blog called – ZCDS_TRAVEL.
Like other views and dictionary tables we can consume a CDS view in ABAP executables-
We saw the below diagram in the previous blog also published in SAP help materials – *Courtesy SAP references – ABAP CDS Views (sap.com)
CDS and SQL view both are part of ABAP Dictionary and you can access them both from SAP ABAP Executables.
Executable – Consuming CDS view in a class and program.
Step1: Create an ABAP Package called – ZTRAVEL_BOOKING_PROG under super package ZTRAVEL_BOOKING.
Step2: Create new ABAP Class -> Right click new package ZTRAVEL_BOOKING_PROG->New->Search ABAP Class and click next.
Name the class- ZCL_CDS_DBO_ZTRAVEL
Description – CDS DBO Class for ZTRAVEL
Step3: Create two methods in the class one to select the data from ZCDS_TRAVEL another to publish the read data.
Observations from the above code – A CDS view and classic view SQL operations are same syntax wise for reading data.
Also while declaring variables using CDS view it works exactly the same way as transparent database tables.
Step3: Lets create a program to review the data stored in CDS view. Create a new program called ZCDS_REPORT_DATA executables in Eclipse.
Description – Report to display CDS Data
Step4: Execute the report. The below output should be displayed.
ST12 Trace: Lets trace the program in ST12 and review the results. We already have the same result as before the ZCDS_TRAVEL is not shown but the SQL view of the same is displayed in the trace from ST12.
CDS view can be consumed the same way the database view or table is because at the end of the day this is part of SAP DATA dictionary.
Congratulations now you would be able to consume a CDS view in your programming.
Onto next learning unit – CDS Annotations – New And Experienced professionals- 3 | SAP Blogs