Show TOC

Metadata Filtering Value ListLocate this document in the navigation structure

Applications often need value lists for properties, to give the user the ability to easily find a specific value. These value lists need OData entity types and entity sets. The size of the metadata document will increase if such value lists are used. To get only the needed information, you can use the filter options to reduce costs.

The following options for filtering are available:

  • GET ~/$metadata?sap-value-list=all (is equal to GET ~/$metadata)

    Document contains “base model” and value list entity types, entity sets and value-list annotations.

  • GET ~/$metadata?sap-value-list=none

    Document for “base model” without value list entity sets and value list annotations. Only indicator which properties have value list: sap:value-list="true"

  • GET ~/$metadata?sap-value-list=<qualified entity type name>/<property name>

    Document containing only binding annotation for this property and value list entity set / type for the requested property.

  • sap-value-list allows a comma-separated list of property specifications: ?sap-value-list=Type_1/Property_1,Type_1/Property_2,Type_2/Property_3

  • Support of metadata query via $batch.

Declaration of Value List in Metadata

A property can have a value list. The link between the property and the value list (entity type and entity set) is an annotation. It is possible that more than one property use the same value list.

It is also possible to create a value list for a property of a value list.

Value List for Properties in Metadata Provider Class

Properties (/iwbep/if_mgw_odata_property) have a method SET_VALUE_LIST to set a value list for a property. There are two types of value lists. Standard describes a pop-up dialog and fixed_values a combo box of values. Standard is the default of method SET_VALUE_LIST.


lo_data_object = model->create_entity_type( 'Booking' ). 
lo_property = lo_data_object->create_property( 'SMOKER' ). 
lo_property->set_value_list( ). 
lo_property = lo_data_object->create_property( 'LUGGWEIGHT' ). 
lo_property->set_value_list( iv_value_list_type = /iwbep/if_mgw_med_odata_types=>gcs_value_list_type_property-fixed_values ). 

This is the result in the metadata:

<Property Name="SMOKER" sap:label="Smoker" MaxLength="1" Type="Edm.String" sap:value-list="standard"/>
<Property Name="LUGGWEIGHT" sap:label="Luggage Weight" Type="Edm.Decimal" Precision="9" sap:unit="WUNIT" Scale="9" sap:value-list="fixed-values"/> 
Value List Entity Types and Entity Sets

Use method SET_IS_VALUE_LIST of interface /IWBEP/IF_MGW_ODATA_ENTITY_TYPE to mark an entity type and all entity sets, which use this entity type, as value list.


lo_data_object = model->create_entity_type( 'VL_BOOK_SMOKER' ). 
lo_data_object->set_is_value_list( abap_true ). "VH 
lo_property = lo_data_object->create_property( 'ID' ). 
lo_property->set_type_edm_string( ). 
lo_property->set_internal_type( iv_type = cl_abap_typedescr=>typekind_string ). 
lo_property->set_is_key( ). 
lo_property = lo_data_object->create_property( 'NAME' ). 
lo_property->set_type_edm_string( ). 
lo_property->set_internal_type( iv_type = cl_abap_typedescr=>typekind_string ). 
lo_data_object->create_entity_set( iv_entity_set_name = 'VL_BOOK_SMOKER_ES' ). 

Metadata:

<EntityType sap:content-version="1" Name="VL_BOOK_SMOKER" sap:value-list="true"> 

<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Nullable="false" Type="Edm.String"/>
<Property Name="NAME" Type="Edm.String"/>
</EntityType>
 

In the entity container:

<EntitySet sap:content-version="1" Name="VL_BOOK_SMOKER_ES" 
EntityType="RMTSAMPLEFLIGHT.VL_BOOK_SMOKER"/> 
Annotations to Link Value List With Properties

To link a property with a corresponding value list entity type / entity set you have to create an annotation inside an annotation target. The annotation target points to a property. The value behind the namespace (for example, '42') must be an exact match to the input of the filtering for a specific property (for example, GET ~/$metadata?sap-value-list=Booking/SMOKER). The annotation (/IWBEP/IF_MGW_VOCAN_ANNOTATION) has the method SET_IS_VALUE_LIST and method SET_VALUE_LIST_ET_NAME to link the annotation to an entity type.


lo_ann_target = vocab_anno_model->create_annotations_target( '42.Booking/SMOKER' ). 
lo_annotation2 = lo_ann_target->create_annotation( iv_term = 'com.sap.vocabularies.Common.v1.ValueList' ). 
lo_annotation2->set_is_value_list( abap_true ). 
lo_annotation2->set_value_list_et_name( 'VL_BOOK_SMOKER' ). 
lo_simp_value = lo_annotation2->create_simple_value( ). 
lo_simp_value->set_integer( 16032011 ). 

Metadata:

<Annotations xmlns="http://docs.oasis-open.org/odata/ns/edm" Target="42.Booking/SMOKER"> 
<Annotation Int="16032011" Term="com.sap.vocabularies.Common.v1.ValueList"/>
</Annotations>