Skip to Content
Author's profile photo Nisha Chandrasekaran

Read Simple field metadata from View Configuration

Recently, I came across a requirement where I had to read some field metadata from view configuration (say for instance Field Name & Field Label)

Since I couldn’t find a ready-to-use “SAP-Standard” way to do this, I had to tweak some of the view configuration related methods to achieve this. I would like to share the same via this post.

1. Create a simple transformation for reading the fields from a view configuration. Let me call this as zz_tr_field_list.Code snippet shown below.

<xsl:transform xmlns:xsl=""
                xmlns:asx="" version="1.0">

   <xsl:output indent="yes" method="xml"/>
   <xsl:strip-space elements="*"/>

   <xsl:template match="/">
     <asx:abap><asx:values><xsl:element name="FIELDS">
         <!-- get mandatory fields from form configuration   -->
         <xsl:for-each select="//gridcell/*[@id]">
           <xsl:element name="FIELDS">
             <xsl:value-of select="@id"/>


2.  Using the configuration manager and configuration descriptor classes, call the above transformation to get the fields. I am pasting here below a small sub-routine (which we will call in a later step).

FORM read_fields_from_config USING
       iv_target_view_name        TYPE string
       iv_role_key                 TYPE bsp_dlc_role_key
       iv_object_type             TYPE bsp_dlc_object_type
       iv_sub_object_type         TYPE bsp_dlc_object_sub_type
       iv_component_usage         TYPE bsp_dlc_component_usage
       CHANGING lt_ums_field      TYPE STANDARD TABLE.

   DATA : lt_current_view_fields  TYPE bsp_dlct_field,
          lt_table_view_fields    TYPE bsp_dlc_column_descr_tab,
          ls_table_view_fields    LIKE LINE OF lt_table_view_fields.


 *       Get configuration manager for business role
       CREATE OBJECT lr_configuration_manager
           iv_role_key = iv_role_key.

 *       ... takes role configuration key and ui object type into account
       lr_result =  lr_configuration_manager->get_configuration( iv_viewname = iv_target_view_name
                                                               iv_view_comp_id = 'C16_W61_V62' ) ##no_text.

       IF iv_component_usage IS NOT INITIAL.
         CALL METHOD lr_result->set_component_usage
             iv_component_usage = iv_component_usage.
       ENDIF    .

       lr_configuration_descriptor2 ?= lr_result.

       lr_configuration_descriptor2->set_object_type( iv_object_type ).
       lr_configuration_descriptor2->set_object_sub_type( iv_sub_object_type ).

       CALL METHOD lr_result->get_config_data
           rv_result        = lv_configuration_xml
           foreign_lock     = 1
           config_not_found = 2
           OTHERS           = 3.
       IF sy-subrc <> 0.

 *       ... Perform XML transformation
 *       -> Result is list of all fields/headings

           CALL TRANSFORMATION zz_tr_field_list
           SOURCE XML lv_configuration_xml
           RESULT fields = lt_result.
         CATCH cx_root.

3. The above call transformation will work very fine for an Overview Page. So what if we have a table view? Here’s the code that follows.

IF lt_result IS INITIAL. "Possibly Table View...
         lt_table_view_fields = cl_bsp_dlc_table_utility=>get_table_from_config_xml( lv_configuration_xml ).

4. Now we are almost done. We still need to get the Field Labels. Let us use the following code to achieve this.

*       Get names of configured search criteria
       lr_view_descriptor = lr_result->get_property_descriptor( ).

       IF lt_result IS NOT INITIAL.
         LOOP AT lt_result INTO lv_result.
           CHECK lv_result CP '//*'. "could be a guid of heading
           ls_field-field_name = lv_result. "example for field name //HEADER/STRUCT.FIRSTNAME
           APPEND ls_field TO lt_current_view_fields.

       IF lt_table_view_fields IS NOT INITIAL.
         LOOP AT lt_table_view_fields INTO ls_table_view_fields WHERE name NE 'THTMLB_OCA'. "#EC CI_STDSEQ
           ls_field-field_name = ls_table_view_fields-title.
           APPEND ls_field TO lt_current_view_fields.

 *       Determine labels
       lr_view_descriptor->get_field_labels( CHANGING ct_fields = lt_current_view_fields ).

5. Let us see how to use the above snippet in a report program.

Eg: We would like to get the field metadata for Account Details View. We set the required parameters for the above sub-routine and then call it as seen below.

lv_target_view_name ='BP_HEAD/AccountDetails'.
  lv_role_key = <<Give Role Config Key here>>.
  lv_object_type = 'BP_ACCOUNT'.
  lv_sub_object_type = 'INDIVIDUAL'.
  lv_component_usage = 'BP_HEAD'.
  PERFORM read_fields_from_config USING lv_target_view_name
                                  CHANGING lt_ums_field.

Hope this was a useful read..!!

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Faisal PC
      Faisal PC

      Hi Nisha,

      Nice one. Keep posting....