Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
nabheetscn
Active Contributor

Background


Off late we have been trying to get a deep understanding of ABAP CDS and Fiori Elements, this blog talks about one such adventure. So we created a base CDS view and then the intention was create an extension for it. So what following my instinct copied the base view and changed it as per extension format. We were expecting it to get activated smoothly but nothing is straight forward sometimes silly mistakes makes you understand the things at deeper level, read on!

An extension does not get activated


So when we tried to activate the CDS extension we were getting the error “The DDL source can only be used to define a view”. I double checked the syntax all looked fine as shown below.

Base View
@AbapCatalog.sqlViewName: 'ZBASEVVIEW'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'original for extension'
define view zbaseview as select from spfli as c
inner join scarr as a
on c.carrid = a.carrid {
key c.carrid,
key c.connid,
c.cityfrom,
c.cityto,
a.carrname
}

Extension View
@AbapCatalog.sqlViewAppendName: 'ZBASEVVIEWEXT'
@EndUserText.label: 'Copy and then extension'
extend view zbaseview with Zbaseviewext {
c.fltype,
c.distid
}

Activation Error



I thought rather than copying which we always do let's try to see does it work when we manually create an extension. Surprisingly it worked as can be seen below.

Manual Extension
@AbapCatalog.sqlViewAppendName: 'ZBASEVVIEWEXTM'
@EndUserText.label: 'Manual Extension'
extend view zbaseview with Zbaseviewextm {
c.fltype,
c.distid
}

 



So something is different in the backend, although the code for both the extension CDS is the same only difference being one is copied and other is manually extended. Next step was to drill more into understanding how it is working in the backend.

Finding the root cause


As a first step i tried to activate the CDS manually in SE80 to check if we can get more detail into the issue but sadly the same log shows.



Definitely the next step was to switch on the debugger and understand what is causing this issue. On debugging further we found out the place from where the error was coming as shown below.The base source type passed for copied is V and where it is expecting an E for extension. On comparing it with manual extension we found the base source type was passed as E which is in line with the expectation



The different constant values for reference for different type of views are shown below.


What is the learning?


Basically when you copy it copies the source type of the view and does not take into account the annotations used in the CDS. Irrespective of the annotation used it simply copies the base source type. I would have expected it to automatically adjust it considering the content of the CDS view being activated.

So learning is be careful when you copy things, things will not work the way you expect them to me like in this case. It actually helps in understanding the things in a better way if we dig more rather than just using the alternative which we have found by just creating the extension manually.

 
7 Comments