This is a test message to test the length of the message box.
Login
ABAP RAP Multiple Filter, Sort, Group
Created by Software-Heroes

RAP - Multiple filters and settings

1049

What happens if we want to set several filters and fields as default in RAP and also need a default sorting?



In this article, we'll look at how we can use variants to pre-populate multiple fields with different filters and sort and group our output.

 

Introduction

In the last article, we looked at how we can assign a default value to a field to pre-populate a filter. In this article, we'll look at how we can do this for multiple fields and with multiple selections. To do this, we'll use selection and presentation variants to influence the list report. To do this, we'll expand our Report Pattern to include the new variants.

 

Preparation

Before we begin with the examples, we need to prepare the view. For this, we need a field as a selection for the following examples. To do this, we'll add the metadata extension "ZBS_C_DRPCurrency".

@UI.selectionField: [{ position: 20 }]
Decimals;

 

After our customization, the app initially looks like this: we have two additional filters in the upper part of the application. Nothing has changed in the list at first.

 

Presentation

In this chapter, we'll look at the presentation variants and their effects.

 

Basics

The presentation variant is about grouping and sorting the output. We can influence the various fields when loading the list. To do this, we define a "qualifier" for the variant, which we can use to identify the variant. As a basis, we now define the following annotations in the header.

@UI.presentationVariant: [ {
  qualifier: 'pVariant',
  visualizations: [{ type: #AS_LINEITEM }]    
} ] 

@UI.selectionPresentationVariant: [ { 
  presentationVariantQualifier: 'pVariant'
} ]

 

We define a variant named "pVariant" and a row-level visualization. Since we could create multiple variants, we'll assign the active variant at the end.

 

Sorting

After the basic definition, there are no changes to the list. If we now want to introduce a new sorting, we define the fields and order via the variant.

sortOrder: [{ by: 'Currency', direction: #DESC }],

 

In this case, we create a descending sort using the "Currency" field. If we now load our app preview, we get the following change. The sorting can also be identified by the icon on the column.

 

Grouping

If we now want to create groups, for example, we use the "groupBy" addition in the variant and can store a list of columns there. In our example, we create a group based on the last changer.

groupBy: [ 'EditorName' ],

 

If we now load the app again, this time without sorting, we get a grouped view.

 

Selection

The selection variant influences the selection of our list. This allows us to set a complex filter upon loading, for example.

 

Basis

The basis is similar to that of the presentation variant. For the selection variant, we also create a new variant with its own ID. We then assign this ID as the active variant.

@UI.selectionVariant: [{  
  qualifier: 'sVariant',
  filter: ''
}]   

@UI.selectionPresentationVariant: [ { 
  selectionVariantQualifier: 'sVariant'
} ] 

 

Multiple Values

If we now want to define multiple values, we can do this, for example, using the free filter. To do this, we define a filter for four currencies. Here, we must use the old version of the comparison operator (EQ).

filter: 'Currency EQ AED OR Currency EQ AFN OR Currency EQ EUR OR Currency EQ USD'

 

If we then look at the filter bar in the application, the four currencies have been adopted as the default filters.

 

Multiple Fields

If we want to fill multiple fields with default values, we can simply predefine a correspondingly complex filter. In this case, we enclose our logic in parentheses and add a filter for the decimal places.

filter: '( Currency EQ AED OR Currency EQ AFN OR Currency EQ EUR OR Currency EQ USD ) AND Decimals EQ 2'

 

Both filters should now be pre-assigned in the application and the data volume should be correspondingly small.

 

Complete example

You can find the changes in our GitHub repository and again specifically in this commit. Overall, we have added these two default variants to the Metadata Extension.

@UI.presentationVariant: [ {
  qualifier: 'pVariant',
  sortOrder: [{ by: 'Currency', direction: #DESC }],
  groupBy: [ 'EditorName' ],
  visualizations: [{ type: #AS_LINEITEM }]    
} ] 

@UI.selectionVariant: [{  
  qualifier: 'sVariant',
  filter: '( Currency EQ AED OR Currency EQ AFN OR Currency EQ EUR OR Currency EQ USD ) AND Decimals EQ 2'
}]   

@UI.selectionPresentationVariant: [ { 
  presentationVariantQualifier: 'pVariant',
  selectionVariantQualifier: 'sVariant'
} ] 

 

If both variants are fully active, our list now changes to the following output. Only the four entries are determined, the sorting is descending, and the grouping is displayed.

 

Conclusion

By default, multiple filters can be set using the variants, and the sorting or grouping can be changed. In principle, the user can do the same thing using the app variants and even save new views. Here the list of ALV variants behaves.


Included topics:
RAPBTPMehrere FilterSortierungGruppierung
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


RAP - API Pattern

Category - ABAP

In this article, we look at the API pattern for RAP and how you can use it flexibly in ABAP development to provide interfaces.

06/20/2025

RAP - Message Length

Category - ABAP

Is your message truncated when outputting with RAP? Let's look at the problem and a solution.

05/13/2025

RAP - Optimize Search and Keys

Category - ABAP

In this article, we will optimize our search help in the custom pattern, use the additional binding, and make our RAP application fit for the end user.

05/06/2025

RAP - Fixed Value Filter

Category - ABAP

How do you use fixed values from a domain for a filter and customize it to your needs in RAP? Learn more here.

05/02/2025

RAP - Custom Pattern (Behavior)

Category - ABAP

In this article, we extend the Custom Pattern in RAP with additional data and behavior, allowing us to create added value in the implementation.

04/29/2025