You are on page 1of 7

My CDS view self study tutorial – Part 7 unveil the secret of @Objec... https://blogs.sap.com/2016/04/22/my-cds-view-self-study-tutorial-part...

Almost one month has passed since my last tutorial and now

1 of 7 26/03/2022, 23:21
My CDS view self study tutorial – Part 7 unveil the secret of @Objec... https://blogs.sap.com/2016/04/22/my-cds-view-self-study-tutorial-part...

I am able to build a useful UI5 application with CDS view +


Smart template

See my study result recently:

Create a CRM Service Order Fiori application within a


couple of minutes
Enable CRM Service Order application with edit
functionality

Now let me continue the self study tutorial.

In my application with edit function enabled, I have set


posting date as read only by using the annotation below
according to sap help.

It works as expected in the runtime. However, why it works?


Being a developer, I hate the fact that these whole stuff work
as a black box to me. I want to know what happens under the
hood. Here below I will share with you how I dig it out via
debugging in both frontend and backend.

2 of 7 26/03/2022, 23:21
My CDS view self study tutorial – Part 7 unveil the secret of @Objec... https://blogs.sap.com/2016/04/22/my-cds-view-self-study-tutorial-part...

1. Debugging in UI5 application

In Chrome development tool, I know that the editable state is


controlled by property “editable” of the given UI model.

So set a breakpoint on SmartField.setEditable function as


below, then click edit button, we can observe the parameter
bValue is passed as false into this function. Now next
question, how and where is this bValue calculated to false?

From the callstack I can find another important function:


canUpdateProperty. Inside this function, from line 241 we
can get this conclusion: any property with attribute
“sap:updatable” equals to false, will be rendered as read only
in UI.

3 of 7 26/03/2022, 23:21
My CDS view self study tutorial – Part 7 unveil the secret of @Objec... https://blogs.sap.com/2016/04/22/my-cds-view-self-study-tutorial-part...

Apparently this attribute is set in backend, as we can confirm


by checking in metadata:

Now question to ABAP backend: I never specify any


annotation like sap:updatable = false in my CDS view, where
does it come from?

2. Debugging in ABAP backend

In this method, framework is scanning against annotation


with name “OBJECTMODEL.READONLY”, as defined in
constant in line 836.

If found, ls_sfc-read_only is set as true.

This assignment will lead to the check succeeds in line 848 (


since by default a field is editable ), as a result an entry is

4 of 7 26/03/2022, 23:21
My CDS view self study tutorial – Part 7 unveil the secret of @Objec... https://blogs.sap.com/2016/04/22/my-cds-view-self-study-tutorial-part...

inserted into internal table mt_element_static_field_ctrl.

This is the detail view of the entry for posting date in the
table.

Later, the internal table is evaluated and if there is entry with


read_only = abap_true existing ( see line 71 ), lv_creatable
and lv_updatable is set as false.

Finally in line 82 and 85, lv_creatable and lv_updatable are


used to set property accordingly. All secrets are published
now!

5 of 7 26/03/2022, 23:21
My CDS view self study tutorial – Part 7 unveil the secret of @Objec... https://blogs.sap.com/2016/04/22/my-cds-view-self-study-tutorial-part...

6 of 7 26/03/2022, 23:21
My CDS view self study tutorial – Part 7 unveil the secret of @Objec... https://blogs.sap.com/2016/04/22/my-cds-view-self-study-tutorial-part...

7 of 7 26/03/2022, 23:21

You might also like