SAP List Report-Selection Mandatory with default value

You are using SAP Fiori elements list report and like to make a selection field mandatory and specify a default value.

Using CDS Annotation


@Consumption.filter: { mandatory: true , selectionType: #SINGLE,
multipleSelections: false , defaultValue: 'P' }
@UI.lineItem: [{position: 10 }]
@UI.selectionField: [{ position: 10 }]
@Consumption.valueHelp: '_BucketVH'
key Buckettype,

SAP List Report-Selection Mandatory with default value

SAP List Report-Selection Mandatory with default value

Using ABAP

1. Mark Entity set as ‘Requires Filter’
2. redefine DEFINE method of DPC_EXT class and after call to super->define( ) put following code

DATA : lo_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation,
lo_property   TYPE REF TO /iwbep/if_mgw_odata_property,
lo_entity_set TYPE REF TO /iwbep/if_mgw_odata_entity_set.

TRY .
DATA(lo_entity_type) = model->get_entity_type( iv_entity_name = 'EntityName' ).
lo_property = lo_entity_type->get_property( iv_property_name = 'Fieldname' ).

lo_annotation = lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).
lo_annotation->add( iv_key   = 'required-in-filter'
iv_value = 'true' ).

lo_annotation->add( iv_key   = 'filter-restriction'
iv_value = 'single-value' ).

"lo_annotation->add( iv_key   = 'display-format'
"                    iv_value = 'UpperCase' ).

CATCH /iwbep/cx_mgw_med_exception  .
ENDTRY.

3. Create a local annotation file in UI5 project and insert following annotation on the selected entity. We could possibly write something to insert this annotation in ABAP but I didn’t had enough time when I did it.

<Annotations Target="ZMM_STOCKREQUIREMNT2_SRV.MaterialRequirementPeriod/Buckettype">
<Annotation Term="Common.FilterDefaultValue" String="M"/>
</Annotations>

This is how it looks like in annotation file.

SAP List Report-Selection Mandatory with default value

 

This should do the trick.

Related blogs:

SAP List Report Filter Bar Date Format

How to Implement Value Help using Smartfield and Odata Annotation

 

One Reply to “SAP List Report-Selection Mandatory with default value

  1. Hi Pawan, Nice blog. Thank you! Please can you let me know. I want to make it UOM field with default value like “EA”. and that quantity field is mandt and always with 0 defaultt value but UOM with valueHelp.
    thanks,
    Ranadheer

Leave a Reply