Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Joseph_BERTHE
Active Contributor
3,642
Hello all,

In the forum I see lots of questions regarding the basics of Smart Control, and there is no place to find information about it.

I decided to write this blog to show and explain to you how to use Smart Control in the real context. I mean in a dynamic world.

When you want to use Smart Control in a freestyle applications or in an SAP Fiori Elements context, you have to deal with any business requirement which impose on you to show a field in certain types of Sales Order, make it in read-only for some reason and set it mandatory because it is the Financial guys who has to do something.

All that behaviour is handled through a particular property called: Field Control

This property is very useful to manipulate the visibility and the mandatory property of an element. The documentation sap:field-control explains all the possibilities that I summarize in the following table :



















7 Mandatory - property must contain a value
3 Optional - property may contain a null value
1 Read-only - property cannot be changed
0 Hidden - property should not be visible on user interfaces

The rest of this blog will show you how to use it.

How does it work?


In the annotation file, you have to add this annotation sap:field-control.  As explained in the documentation the value of this annotation has to be a path. For instance if you have an entity Address :



And you want to manage all the fields (or only one), you will add fields control attributes (doen't matter the name of this attribute) like this:



In the annotation file, you will have to add references to the properties you want to handle:
<Property Name="Street" Type="Edm.String" sap:field-control="FC_Street" />
<Property Name="City" Type="Edm.String" sap:field-control="FC_City" />
<Property Name="Number" Type="Edm.String" sap:field-control="FC_Number" />

But in some case, your data model could be more segmented, and you want to manage the visibility or the mandatory properties in an external entity like this :



In that case the annotation should be like this :
<Property Name="Street" Type="Edm.String" sap:field-control="to_Property/FC_Street" />
<Property Name="City" Type="Edm.String" sap:field-control="to_Property/FC_City" />
<Property Name="Number" Type="Edm.String" sap:field-control="to_Property/FC_Number" />

Be aware of !


If you want all of that working perfectly, you have to respect two things:

  1. The Field control should be a Byte type

  2. The property as to be nullable (even if you do not want it) : Nullable=”true”


Example


This example is available on Github here. The sample is very simple with a smart table and a selection mode. When we select a line, the Smart Form below appears with the correct context.


Edition Mode


To make your fields editable, you have to set it updatable.



In the picture the field Number is not updatable, then it stands read-only, but not the other fields which are updatable.

Mandatory field


The nullable property will affect the mandatory behaviour.



Without any field control, the property Nullable affect the field has shown in the picture. Only city is not nullable, thus it is a mandatory field. The others are optional.

Let's integrate the Field Control


All we've done above was manually (without field control), And you see that it is pretty simple to manage the fields. But now we are going to do it programmatically by using the field control.

To do so, it will be mandatory to do modification inside the OData service in the generated classes.

The next steps will be done through SEGW project.

In MPC_EXT class, you have to add the following code:
  METHOD define.
super->define( ).
me->add_fc_anno(
iv_entity_type = 'AddressWithFC'
iv_property_name = 'Street'
iv_field_ctrl = 'Fc_Street'
).

me->add_fc_anno(
iv_entity_type = 'AddressWithFC'
iv_property_name = 'Number'
iv_field_ctrl = 'Fc_Number'
).

me->add_fc_anno(
iv_entity_type = 'AddressWithFC'
iv_property_name = 'City'
iv_field_ctrl = 'Fc_City'
).
ENDMETHOD.

The complet code is available in GitHub

The code above will add the sap:field-control into the metadata:
<Property Name="ID" Type="Edm.String" Nullable="false" sap:unicode="false" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="City" Type="Edm.String" Nullable="false" sap:field-control="Fc_City" sap:unicode="false" sap:creatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Number" Type="Edm.Int16" sap:field-control="Fc_Number" sap:unicode="false" sap:creatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Street" Type="Edm.String" sap:field-control="Fc_Street" sap:unicode="false" sap:creatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Fc_City" Type="Edm.Byte" Nullable="false" sap:unicode="false" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Fc_Number" Type="Edm.Byte" Nullable="false" sap:unicode="false" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Fc_Street" Type="Edm.Byte" Nullable="false" sap:unicode="false" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>

Here is the impact of the view with the data:

Hidden: 0




Look at the city property which is set to 0 which mean hidden. The value is not shown in the table and in the Smart Form, the field is completely vanished, wherease the other are available.

Read-Only and Mandatory: 1 & 7



Optional: 3




Look at the impact of each property. Here you can see if the Nullable property is not set to true the field control will not have any action in the field. Number and Street can be manipulated but not City.

Conclusion


For your projects Freestyle I suggest to use Smart Control to increase the development process. With the above information you are able to do all what the business would ask of you. Do not answer by doing extension (in Fiori Elements) because with Field Control you have the full flexibility to do what you want.

Regards,

 
2 Comments
pierre_dominique2
Contributor
0 Kudos
Hi Joseph,

Good stuff, thanks for sharing this!

Cheers,

Pierre
fdemir
Explorer
0 Kudos

Hi Joseph,

Thank you for the information. Can we use this for search help?

For example, I have a problem like this:

https://answers.sap.com/questions/13543532/sapui5-smartfilterbar-setmandatory-not-working.html

Labels in this area