Tuesday, 06 April 2021 07:55

Some useful tips while writing custom Core Data Service(CDS) and ABAP Managed Database Procedure(AMDP)

Written by Krishma Bhatia
Rate this item
(0 votes)
Source https://blogs.sap.com/2021/04/07/some-useful-tips-while-writing-custom-core-data-servicecds-and-abap-managed-database-procedureamdp/
“© 2020. SAP SE or an SAP affiliate company. All rights reserved.” “Used with permission of SAP SE”

Hi Friends!

I am very excited to share with you all my very first blog post!!

I recently got the opportunity to work on custom CDS and AMDP in the SAP S/4HANA Implementation project which involved quite complex logic, but it gave me a lot of new learning which I felt like sharing with you all. This was my very first time I worked on CDS and AMDP so thought to share with you all thinking it might be helpful( especially for beginners like me ).

Below are a few of the learnings which I got while working on custom CDS and AMDP:-

  1. You must be familiarized with calling parameterized CDS with a left outer join but to call parameterized CDS with the association, the syntax is quite different. Also always prefer to use association over joins since associations are kind of Joins to fetch data from multiple tables on Join Conditions but these are ‘JOINS ON-DEMAND’ i.e. they will only be triggered when a user would access the required data which needs the Association of tables.  For example, your CDS view has 4 associations configured and the user is fetching data for only 2 tables, the association on the other 2 tables will not be triggered and the system would return the results quickly, so it enables a really high turn-around time as compared to regular SQL JOINS. Coming back to the syntax of calling parameterized CDS with association use the following syntax:-
 define view ZC_TEST_REPORT with parameters p_comdate :zcom_date as select from ZC_TEST_REPORT as _Rpt left outer join ZI_TEST_SUBREPORT(p_comdate:$parameters.p_comdate) as _Subrpt on _Rpt.ProdHrId = _Subrpt.prod_hr_id association [0..1] to ZI_TEST_NONOFR as _NonOfr on _Rpt.ProdHrId = _NonOfr.ProdHrId { key _Rpt.ProdHrId as ProdHrId, _Subrpt.comtype as Comtype, _NonOfr(p_comdate:$parameters.p_comdate).destination as destination }
  1. Always take care if any column of the internal table on which calculation is being performed( like arithmetic operation) has a null value then the result of the operation will always be null. Therefore take care to check for null value and fill the column values( like with ‘0’ if the value doesn’t exist for int column type)  before performing any calculation else the result will be always null for columns not having any value.

3. If you want to perform division operation in CDS which should have value after decimal point (like 123.45) use division numerical SQL function instead of div in CDS. Div always returns an integer value as a result(123.45 will be 123

Continue reading here
Read 78 times

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.