This is a test message to test the length of the message box.
ABAP BOPF Custom query
Created by Software-Heroes

ABAP - BOPF Custom Query

Do you need your own high-performance selection for your BOPF data? Then write your own query for it today.

In some cases you would like to announce interfaces to the outside and give your user the opportunity to perform frequently used queries again and again? There are custom queries that you can define in the BOPF. Today we show you an example of how you can implement something like this.



It all starts with defining the query in the data model. To do this, go back to transaction BOBX to expand the model and create your own query. You store a name and optionally a description and you can have the dictionary object names generated again.


We would like to enable the user to perform a custom and unique query and therefore provide some fields from our data model in a structure, the name of the structure we can also have generated by the system. Before we create the class, we need the complete structure.


Data interface

Let’s take another look at the data interface of the method before we start implementing it. As you will recognize from some older articles, we already know many parameters. There is again the configuration data of the current node and objects for reading and changing data.


For your own query, the selection (IT_SELECTION_PARAMETERS), which contains the value restrictions for the individual fields, the query object (IO_QUERY) with which we can carry out standard queries, and the return fields ET_KEY and ET_DATA are particularly relevant. If something goes wrong, the message object (EO_MESSAGE) should of course be filled.



You now have to process the following steps: Break down the selection into the individual ranges and do a select on the database. From a performance perspective, you can of course also use a database view or CDS view, which would be a bit more powerful than the JOIN.

In the next step you transfer the data to the query object, which will now select and return the correct data based on the settings and keys.

  lt_key       TYPE /bobf/t_frw_key,
  lt_r_create  TYPE RANGE OF crdat,
  lt_r_partner TYPE RANGE OF bu_partner.

eo_message = /bobf/cl_frw_factory=>get_message( ).
CLEAR: et_key, et_data.

LOOP AT it_selection_parameters REFERENCE INTO DATA(lr_param).
  CASE lr_param->attribute_name.
        sign    = lr_param->sign
        option  = lr_param->option
        low     = lr_param->low
        high    = lr_param->high
      ) INTO TABLE lt_r_create.
        sign    = lr_param->sign
        option  = lr_param->option
        low     = lr_param->low
        high    = lr_param->high
      ) INTO TABLE lt_r_partner.

SELECT c~db_key
 FROM ztest_d_contract AS c
 INNER JOIN ztest_d_partner AS p
  ON p~parent_key = c~db_key
 WHERE c~creation_date IN @lt_r_create
   AND p~partner IN @lt_r_partner
 INTO TABLE @lt_key.

IF sy-subrc = 0.
      is_ctx                  = is_ctx
      it_filter_key           = lt_key
      io_query_authorities    = io_query_authorities
      is_query_options        = is_query_options
      io_query                = io_query
      io_read                 = io_read
      io_modify               = io_modify
      iv_fill_data            = iv_fill_data
      it_requested_attributes = it_requested_attributes
      eo_message              = eo_message
      et_key                  = et_key
      es_query_info           = es_query_info
      et_data                 = et_data



You see, for your own implementation of a query, not much is necessary and we have equipped you with the appropriate knowledge today. Try to implement your own query in your data model and test your knowledge.

Included topics:
BOPFCustom queryQuery
Comments (0)

ABAP - BOPF Quick Guide (Update)

Category - ABAP

A little update to our book that we published. For all people who find the paperless office boring.


ABAP - BOPF Quick Guide

Category - ABAP

You need a quick introduction to the SAP Business Object Processing Framework (BOPF), we have the right guide for you here.


ABAP - BOPF Eclipse

Category - ABAP

Can you also develop BOPF in Eclipse? Here we show you how well the search and navigation works in the system.


ABAP - BOPF Performance

Category - ABAP

What about the performance when accessing BOPF? We want to investigate this question today.


ABAP - BOPF Helper methods

Category - ABAP

The framework provides you with various methods and objects that are intended to simplify use.