Skip to Content
Author's profile photo Former Member

Dynamic modification of Configuration fields ( Part -1) : Form View

I wonder so many requirements are based on the modification of configuration fields, its properties and positions at run time. So I thought to provide some techniques to change the configuration of fields including the properties at run time for different types of views which we commonly use in most of our components.

The standard way is to create a new configuration for each view which renders different set of fields, its properties and alignment. So at runtime depending upon the configuration key, it chooses the appropriate configuration which is the close match and renders the selected configuration view on screen. Now assume we have only limited configurations and we need to use the same configuration and render it differently based on some other conditions at run time.

                       And also as a technical consultant you might not have authorization to create a new configuration and play around with it. But fortunately we have some tricky way to get control on the configuration which is being shown on UI.

We mostly use four types of views in our components.

  1. Form View
  2. Table view
  3. Search View
  4. Overview

In all the views (except Overview) , we have a .htm page for the view which constructs the UI page layout with fields and its properties. Luckily we have a configuration tag which accepts the xml file of the configuration and uses it to render different UI components on screen.

  <%
  DATA:
  lv_xml    TYPE string.
  lv_xml = controller->configuration_descr->get_config_data( ).
%>


<chtmlb:config xml  = “<%= lv_xml %>”
               mode = “RUNTIME” />

So our technique is based on modifying the XML file according to our requirement and then passing it to the configuration tag to display the modified xml .

In this document we will concentrate on Form View.

Reading the XML file and figuring out the fields is a tedious job. As we have some utility classes which covert them to ABAP, we can start playing out with the fields and their properties.

   *********************************************************************************************************************************************************************************

<%@page language=”abap” %>
<%@extension name=”thtmlb” prefix=”thtmlb” %>
<%@extension name=”chtmlb” prefix=”chtmlb” %>
<%@extension name=”bsp” prefix=”bsp” %>
<%
  DATA:lv_xml    type string,
             lv_xml_inp type string,
             lv_config_type type BSP_DLC_CONFIG_TYPE,
             lv_view_desc type ref to IF_BSP_DLC_VIEW_DESCRIPTOR,
             it_adv_conf type BSP_DLCT_ADV_CONF_ITM.

* ************Read the original configuration data and property descriptors of the view as an xml file

  lv_xml_inp    = controller->CONFIGURATION_DESCR->GET_CONFIG_DATA( ).
  lv_view_desc = controller->CONFIGURATION_DESCR->GET_PROPERTY_DESCRIPTOR( ).

*********************** Use the utility class to convert xml to ABAP format
    CL_BSP_DLC_CONFIG_UTIL=>ADV_CONF_META_TO_TABLE( exporting IR_VIEW_DESCR = lv_view_desc
                                                                                                                          IV_ADV_CONF_META_XML = lv_xml_inp
                                                                                                         importing ET_ADV_CONF = it_adv_conf ).

**************************************************************
    ***  As it_adv_conf have the structure BSP_DLCT_ADV_CONF_ITM which describes each field on the UI with its properties like mandatory,display only. Also the field label name and its positions are captured . Now you can modify them according to your requirement.

    ***  Place the validation logic here ********                                          

***************************************************************
                                                 

********************* Convert the modified config ABAP table to XML


  CL_BSP_DLC_CONFIG_UTIL=>ADV_CONF_TABLE_TO_META( exporting IT_ADV_CONF = it_adv_conf
                                                                                                                         IR_VIEW_DESCR = lv_view_desc
                                                                                                          importing EV_ADV_CONF_META_XML = lv_xml ).

****  ****Here the modified XML is retrieved , but it is not ready as it has been encoded. We have to remove encoding and put it in standard format for rendering.
                                                 
  DATA: lv_defidx    TYPE sy-fdpos,
  lv_clstagidx TYPE sy-fdpos.
 
  lv_defidx = -1.
  lv_clstagidx = 10000.
  IF lv_xml CS ‘<?xml’.                                  “#EC NOTEXT
  lv_defidx = sy-fdpos.
  IF lv_xml CS ‘>’.
  lv_clstagidx = sy-fdpos + 1.
  IF lv_clstagidx > lv_defidx.
  lv_xml = lv_xml+lv_clstagidx.
  ENDIF.
  ENDIF.
  ENDIF.
  CONCATENATE ‘<?xml version=”1.0″?>’ lv_xml INTO lv_xml.“#EC NOTEXT
%>

********* Finally pass the modified configuration data to the tag

<chtmlb:config xml  = “<%= lv_xml %>”
               mode = “RUNTIME” />

***************************************************************************************************************************************************************************

In the next document http://scn.sap.com/docs/DOC-29972 we will concentrate on other types of views.

Assigned Tags

      26 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Andrei Vishnevsky
      Andrei Vishnevsky

      Hello, Natish.

      It's very good that you've started this series. But as you said "In the next blog...". And you created the document. Do not know it's possible or not to convert current document to a blog post, but it seems to be better within blogs.

      Thank you and keep posting!

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hello Andrie,

      Thanks for your comments.

      My first thought is to create a single document and place all the content here itself . Then changed my mind as it would be clumsy to put all the stuff in single document and decided to go for series as blogs .But only after the content is published I noticed that it has been posted as a document and not as a blog 🙁 . Not sure whether we can convert it into a blog. 

      Cheers.

      Author's profile photo Andrei Vishnevsky
      Andrei Vishnevsky

      As the first approach you can ask Space Administrators is it possible to convert the document to the blog post or not. You can find them on the left side here: http://scn.sap.com/community/crm/webclient-ui-framework/people. May be they will be able to help you.

      I would think of copy-paste this document to new blog post and ask Administrators to delete the document. But it's only my opinion.

      Author's profile photo Former Member
      Former Member

      Very nice document 🙂 . Looking forward to learn more about other types of views aswell .

      Thanks and Regards,

      Nikhil Kulkarni

      Author's profile photo Ajaya Kumar
      Ajaya Kumar

      Very good document Nithish!!!

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Ajay and Nikhil.

      Andrie,

      As per the moderators, we cannot convert the document into blog and they advised to use series of documents rather than blogs for this content . And in the end I will use an overview blog which refers to  all these documents.

      Author's profile photo praveen kumar
      praveen kumar

      very nice document

      Author's profile photo sanguine007 crm
      sanguine007 crm

      very informative

      Author's profile photo Former Member
      Former Member

      Hi Nithish,

      Very nice document.

      I had few queries:

      Can similar coding be done in the DO_CONFIG_DETERMINATION method of the implementation class?

      Sometimes we have a requrement to make a certain field visible or mandatory depending on the value of another field. How to do that?

      Regards,

      Sayan

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Sayan,

      You can use the code not only in DO_CONFIG_DETERMINATION , but also in any other appropriate method where you can calculate the fields and place the logic to modify them ( dependent upon other fields). At the end we have the modified xml i.e lv_xml and to set this modified xml as our desired configuration we need to use

      me->CONFIGURATION_DESCR->SET_CONFIG_DATA(IV_CONFIG_DATA = lv_xml ).

      Please note the above statement will overwrite the original configuration and save it in database table BSPC_DL_XMLSTRX2, where as in the document I have chosen .htm page to render the modified xml so that it will be modified just before it renders on screen and original configuration created will be preserved .

      Assume we need to place some fields as mandatory , depending upon other field value . In this case if we set our configuration using SET_CONFIG_METHOD ,, in the next run assume if our condition is not satisfied then it will display the most recently modified configuration rather than the original configuration which is created through Customizing request . So in .htm page you can always retrieve the original configuration.

      Author's profile photo Former Member
      Former Member

      Hi Nithish,

      Can you provide me any help on the following...

      I have one requirement, wherein , I am hiding one mandatory field dynamically (dynamic programming in do_config_determination) based on other field value. But , While saving, it shows an error message saying "Make an entry in the field 'XXXXXX' " . How to make that field as optional using dynamic programming do_config_deterrination.  Or How to avoid this situation.Quick response will be helpful.

      Thanks .

      Srinivas

      Author's profile photo Former Member
      Former Member

      Nithish, It's a Great value..!!

      Thanks, Satish    

      Author's profile photo Santhosh Kadiyala
      Santhosh Kadiyala

      Very Good Document Nithish !!!

      Author's profile photo Former Member
      Former Member

      Hi Nithish,

      I need to add the fields dynamically in a form view. But these fields are not any of the AET extended fields. For example, i want to create the fields dynamically and display them on the UI as well. Can you please suggest something on this.

      Regards,

      Anil

      Author's profile photo Former Member
      Former Member

      Hello Anil ,

        Do you want to create entries and display them  ? Please explain your requirement properly as it is not clear.

      Dynamic creating of fields is not feasible as to start showing up on the UI it needs to be moved first to the configuration.

        Or

      May be you are looking in : You want to show some field's and hide some fields during certain transactions : to do this create separate configuration and load them dynamically in DO_CONFIG_DETERMINATION .

      Thanks and Regards,

        Qiong

      Author's profile photo Former Member
      Former Member

      Hi Qiong,

      I have to show the fields on the UI creating them dynamic. I dont have them in the value node nor the context node. I have a name value pair in some database table and i need to display them in the UI(form view)

      Author's profile photo Former Member
      Former Member

      Hello Anil,

      This is something which is not possible.

      The fields will be not able to appear in the UI until i move the fields in the configuration from available field to show fields. So this kindaa of requirement is not possible.

      I have never seen any coding in 5 years of my CRM practice where the fields to the configuration is dynamically added.

      Also looking into more information on this requirement.

      Thanks and Regards,

      Qiong

      Author's profile photo Former Member
      Former Member

      Hi Qiong,

      Thanks for the reply. Though this may be possible for a form view as there is something similar which is done for the table view.

      http://scn.sap.com/community/crm/blog/2012/09/24/dynamic-columns-in-a-table-view

      Please check this..

      Thanks,

      Anil

      Author's profile photo Former Member
      Former Member

      Hi Nithish,

      I tried according to your code . . .

      i am trying to change the FIeld_LABEL . It is getting changed in the ITAB but on the Webui it is remaining same . .  .

      Can you please help me on this

      Regards,

      Dinesh Gurram

      Author's profile photo Former Member
      Former Member

      Very clear and Informative.. Nice document..

      Thanks..

      Regards,

         DP.

      Author's profile photo Former Member
      Former Member

      Hi Nitish,

      This document help me alot.

      Regards,

      Y. Ravi Kumar

      Author's profile photo Former Member
      Former Member

      Hi ,

      I have one requirement, wherein , I am hiding one mandatory field dynamically (dynamic programming in do_config_determination) based on other field value. But , While saving, it shows an error message saying "Make an entry in the field 'XXXXXX' " . How to make that field as optional using dynamic programming do_config_deterrination.  Or How to avoid this situation.Quick response will be helpful.

      Thanks .

      Author's profile photo Luís Pérez Grau
      Luís Pérez Grau

      Hi Srinvas,

      Did you check this messages in not trigered by another layer, for example a standard API or a BADI? Mayber this field is mandatory by config, what object are you working on?

      Cheers!

      Luis

      Author's profile photo Former Member
      Former Member

      Don't usually comment on these SCN blogs/docs but this one was very useful to me, especially the bit with the helper classes for converting into an Abap Webcuif scenario then back to xml once done with any business logic. Thanks Nithish.

      Author's profile photo Former Member
      Former Member

      Hi Nitish,

      very good document.

      Cheers,
      Nagaraju

      Author's profile photo Former Member
      Former Member

      Hi,

      very good document. But I have a question.

      If I implement this change into my HTML document I see my changed view but below the original config is shown again.

      Do you know this issue?

      Thx

      Frank