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: 
Former Member

Introduction

Over the last week i spent a vast amount of time playing around with the Smart Table Control and trying to generate an ODATA Service in our Gateway Backend delivering the needed Annotations for this Control.

After endless hours of trial and error and analyzing the Smart Table Example in the Explored App

https://sapui5.hana.ondemand.com/explored.html#/sample/sap.ui.comp.sample.smarttable/preview

i finally managed to get the needed Annotations like the LineItem for setting default Columns delivered by our Gateway.

In this Blog i will share my Experience with this and show the method i used to maybe save others this time consuming task of trial.

The only Requirement for this to work is that you are using SAPUI5 Version 1.30.3 or above as they fixed the parsing of Collections and Records for Annotations in this Version which is neccesary for this to work properly.

In this Part of the Blog we will look on how to implement the ODATA Service in the Backend Gatway System.

The Problem

The Smart Table Control requires not only the Standard SAP Annotations like creatable, filterable etc. but also the use of ODATA Annotation which are supported by Netweaver Gateway for a while now. The Problem is in the current state of the Gateway Service Builder Transaction you could choose to either use the SAP or the ODATA Annotations not both of them at the same time.

The Solution

By utilizing the possibility to create seperate Annotation Models to enrich the Standard Service with SAP Annotations with the needed ODATA Annotations and linking the ODATA Model on the Clientside with the Annotation Model you will be able to use both Annotation Types. However this requires some manual Coding as the Service Builder by now is not able to generate the needed Annotations (as far as i know).

This requires some steps which i will explain in the following sections.

Creating the ODATA Service

To deliver some Data to actually display in the Smart Table we need to create an basic ODATA Service. For this Service i used the BAPI BAPI_CUSTOMER_GETLIST to get a List of Customers to display in the Table.

Be sure to select "Service with SAP Annotation" for the Project Type.

I´m not going into Details here about creating the mapping and this stuff as this should be relatively well documented by now.

Just get sure you are checking some of the Entity Properties as filterable to enable the Filtering for these in the Smart Table.

After setting up the Service generate the Runtime Artifacts.

Creating the Annotation Model

To enrich the previous Service with the additional Annotations, for example the LineItem for the default Columns we need to create an Annotation Model.

In Service Builder create a new Project of Type "Annotationmodel for referenced Service".

Then open this Project in Edit Mode and right Click on the Data Model, select Import and Servicereference

In the Popup select the Service you want to annotate. This will import the Data Model into your Annotation Model.

Then do the same again but this time select Vocabulary and import the Vocabularies you want to use.

You can now generate the Annotation Model for the Service as from now on the Gateway Builder will not be able to generate the needed Changes.

Extending the Annotation Model

Generating the Runtime Artifacts for the Annotation Model will generate an Extension Class (ZCL_MODELNAME__01_APC_EXT) for you.

Open this Class go to the Methods, select the Method "DEFINE_VOCAB_ANNOTATIONS" and click on redefine.

In the Redefinition of this Method we want to implement the Annotation for the LineItem Collection for the Smart Table like this:


METHOD define_vocab_annotations.
*Data Declaration
    DATA: lo_ann_target TYPE REF TO /iwbep/if_mgw_vocan_ann_target.                 
    DATA: lo_annotation TYPE REF TO /iwbep/if_mgw_vocan_annotation. 
    DATA: lo_collection TYPE REF TO /iwbep/if_mgw_vocan_collection. 
    DATA: lo_function  TYPE REF TO /iwbep/if_mgw_vocan_function.   
    DATA: lo_fun_param  TYPE REF TO /iwbep/if_mgw_vocan_fun_param.   
    DATA: lo_property  TYPE REF TO /iwbep/if_mgw_vocan_property.   
    DATA: lo_record    TYPE REF TO /iwbep/if_mgw_vocan_record.     
    DATA: lo_simp_value TYPE REF TO /iwbep/if_mgw_vocan_simple_val.
    DATA: lo_url        TYPE REF TO /iwbep/if_mgw_vocan_url.       
    DATA: lo_label_elem TYPE REF TO /iwbep/if_mgw_vocan_label_elem. 
    DATA: lo_reference  TYPE REF TO /iwbep/if_mgw_vocan_reference.   
*Calling the generated mehtod for creating annotations
    CALL METHOD super->define_vocab_annotations( ).
*Creating the references for the vocabularies
    lo_reference = vocab_anno_model->create_vocabulary_reference( iv_vocab_id = '/IWBEP/VOC_CAPABILITIES'
                                                                iv_vocab_version = '0001').
    lo_reference->create_include( iv_namespace = 'Org.OData.Capabilities.V1' ).
    lo_reference = vocab_anno_model->create_vocabulary_reference( iv_vocab_id = '/IWBEP/VOC_CORE'
                                                                  iv_vocab_version = '0001').
    lo_reference->create_include( iv_namespace = 'Org.OData.Core.V1' ).
    lo_reference = vocab_anno_model->create_vocabulary_reference( iv_vocab_id = '/IWBEP/VOC_COMMON'
                                                                  iv_vocab_version = '0001').
    lo_reference->create_include( iv_namespace = 'com.sap.vocabularies.Common.v1' ).
    lo_reference = vocab_anno_model->create_vocabulary_reference( iv_vocab_id = '/IWBEP/VOC_COMMUNICATION'
                                                                  iv_vocab_version = '0001').
    lo_reference->create_include( iv_namespace = 'com.sap.vocabularies.Communication.v1' ).
    lo_reference = vocab_anno_model->create_vocabulary_reference( iv_vocab_id = '/IWBEP/VOC_MEASURES'
                                                                  iv_vocab_version = '0001').
    lo_reference->create_include( iv_namespace = 'Org.OData.Measures.V1' ).
    lo_reference = vocab_anno_model->create_vocabulary_reference( iv_vocab_id = '/IWBEP/VOC_UI'
                                                                  iv_vocab_version = '0001').
    lo_reference->create_include( iv_namespace = 'com.sap.vocabularies.UI.v1' ).
*Creating the Annotation Target
    lo_ann_target = vocab_anno_model->create_annotations_target( iv_target = 'ZCUSTOMER_SRV.Addressdata' ).
*Creating the LineItem Collection
lo_annotation = lo_ann_target->create_annotation( iv_term = 'com.sap.vocabularies.UI.v1.LineItem' ).
    lo_collection = lo_annotation->create_collection( ).
*Creating the Records
    lo_record = lo_collection->create_record( iv_record_type = 'com.sap.vocabularies.UI.v1.DataField' ).
    lo_property = lo_record->create_property( iv_property_name = 'Value').
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_path( 'Customer' ).
    lo_property = lo_record->create_property( iv_property_name = 'Label').
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_string( 'Kunde' ).
*
    lo_record = lo_collection->create_record( iv_record_type = 'com.sap.vocabularies.UI.v1.DataField' ).
    lo_property = lo_record->create_property( iv_property_name = 'Value').
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_path( 'Country' ).
    lo_property = lo_record->create_property( iv_property_name = 'Label').
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_string( 'Land' ).
*
    lo_record = lo_collection->create_record( iv_record_type = 'com.sap.vocabularies.UI.v1.DataField' ).
    lo_property = lo_record->create_property( iv_property_name = 'Value').
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_path( 'Name' ).
    lo_property = lo_record->create_property( iv_property_name = 'Label').
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_string( 'Name' ).
*
  ENDMETHOD.






In Line 36 we are creating an Annotation for our Entity (i called it Adressdata).

You must set the target with the Pattern ServiceNamespace.Entity. You can find this Namespace in your Service Metadata Definition.

We are then creating an Annotation for the LineItem and add a Collection to it. In the Collection Records you can then set your Default Columns.

The Path in the Value Property must correspond to one of your Entity Properties while the Label can be anything you want (this is the Text which is shown in the Table as Column Title).

Activate this Class and we are done with the Backend Coding.

You can verify that everything went smoothly by calling your Annotation Model in the Gateway Client with the URL:

/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/Annotations(TechnicalName='YOURMODELNAME_MDL',Version='0001')/$value

You should see the Annotations we made on the bottom of the Response.

In the next Part we will look on the Coding required on the SAPUI5 Application to tell the Smart Table about the created Annotation Model.

Regards,

Florian

17 Comments
Labels in this area