This is a test message to test the length of the message box.
Login
ABAP RAP Search
Created by Software-Heroes

RAP - Search

604

In this article we deal with the generic search for RAP objects and how we can also interpret incorrect entries.



So far, in the RAP series, we have mainly dealt with search helps that are linked directly to fields and allow input help to be generated for them. But here the user must know in which field he actually has to search for information and should know the demarcation to some extent.

 

Introduction

In RAP objects we can also activate the generic search. This is a search field that can search 1-n columns for the information entered. With this search field, there are various ways we can design efficient searches:

 

Activate

The generic search can be activated with the help of a header annotation in the corresponding consumption view of the RAP object, so the function is available in the UI. To do this, the following annotation must be inserted somewhere above the definition:

@Search.searchable: true

 

However, the annotation cannot stand alone in the CDS view, the compiler will issue an error message that at least one element must be marked as searchable. In this case, we mark the invoice number and the partner as searchable. To do this, we add the corresponding annotations to the fields:

          @Search.defaultSearchElement: true
  key     Document,
...
          @Search.defaultSearchElement: true
          Partner,

 

The corresponding search is now defined and we can try it once in the application. In the first case, we enter a document number once and get the following result:

 

In the second test case, we enter a partner number once and receive all documents with the corresponding partner number, in this case 35 pieces:

 

Fuzziness

What does not work in the current version of the search is searching for patterns or incorrect entries. The information is not always exactly what you are looking for in the column. Sometimes they deviate by small nuances and are therefore not displayed in the search result. There is fuzziness in the search, which determines how much error tolerance is used in the search. Let's define the rate on the two fields:

          @Search.defaultSearchElement: true
          @Search.fuzzinessThreshold: 1.0
  key     Document,
...
          @Search.defaultSearchElement: true
          @Search.fuzzinessThreshold: 0.9
          Partner,

 

The "Threshold" determines how imprecise the values in the column can be. At 1.0 the value must match 100%, the lower the rate, the broader the search and the more hits the search returns. We set the second field to 0.9 so that we can start a rough search via the partner. If we now enter the value "1234", we get a hit:

 

However, if we search for the value "12347", we get no hit. An error was deliberately built into the string here. Let's set the threshold to 0.8 and try the search again:

 

The fuzziness is now less precise and we also get hits that are actually only similar to what we were looking for. Invoices can also be found that may have received an error during entry and no longer have the information you were looking for.

 

Consumption View

Simply by adapting the annotations in the consumption view, we were able to implement a generic search that can also find deviations. You can find the entire Core Data Service here with the corresponding new annotations:

@EndUserText.label: 'Consumption for ZBS_R_RAPCINVOICE'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.allowExtensions: true
@Search.searchable: true
define root view entity ZBS_C_RAPCInvoice
  provider contract transactional_query
  as projection on ZBS_R_RAPCInvoice as Invoice
{
          @Search.defaultSearchElement: true
          @Search.fuzzinessThreshold: 1.0
  key     Document,
          DocDate,
          DocTime,
          @Search.defaultSearchElement: true
          @Search.fuzzinessThreshold: 0.8
          Partner,
          @ObjectModel.virtualElementCalculatedBy: 'ABAP:ZCL_BS_DEMO_CRAP_VE_EXIT'
  virtual NumberOfPositions : abap.int4,
          _Position : redirected to composition child ZBS_C_RAPCPosition
}

 

Conclusion

Implementing a generic search in Fiori Elements is very easy, requiring little annotation and no great development. The implementation should not be a problem for you and so you do not need a separate search for each field.


Included topics:
RAPBTPSearch
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 - Popup Default values

Category - ABAP

How can you provide the user with default values in the popup of an action in RAP? In this article we will extend our application.

01/21/2025

RAP - Popup Mandatory Fields

Category - ABAP

How can you actually define required fields for a popup in RAP? In this article we will go into the details in more detail.

01/14/2025

RAP - Deep Table Action

Category - ABAP

Is it currently possible to pass tables to actions in RAP? This article is intended to provide a better insight into the topic.

01/07/2025

ABAP Cloud - Programming Model

Category - ABAP

Which programming model is used with ABAP Cloud and what can we learn from its predecessor? More details in the article.

01/03/2025

RAP - Side Effects

Category - ABAP

How can you update parts of the Fiori UI without doing a complete refresh? With Side Effects, this is easily possible in ABAP and RAP.

12/27/2024