This is a test message to test the length of the message box.
Login

ABAP - BOPF Queries

2326

After creating the test data, we had some minor difficulties reading the data. Today we will show you the solution for this problem.



In this article, we'll look at how we can easily read data. Because we have already seen in the last article, there are only simple accesses via the key, but this must first be determined.

 

Query

There are queries that we can create and use. The definition of a query takes place in transaction BOBX, where we also create the model. With a right-click on queries, we can define a new query.

 

Without much effort, we can create two basic queries that the system already provides. SELECT_ALL finds all keys from the BOPF and returns them without restrictions. SELECT_BY_ELEMENT adopts the selection criteria and limits the number of keys. For this, the query requires a structure or field to be filtered.

 

 

From experience, we can tell you that depositing the real table is the best way. Although the transient fields from the data are missing, the keys for PARENT can also be queried if, for example, you enter the search via a lower entity.

 

BOBT

After definition and activation in the model, the two new queries are also available in the test environment. These can now be used for the selection. If you just want to read all elements from the tables, the query SELECT_ALL is sufficient.

 

If you want to restrict the elements, you will get a popup again. This time, all fields from the structure are available for input, which should make it easier for you to narrow down the data. Now you can also restrict via the vendor.

 

Technical solution

Surely you are wondering how to perform the query technically? In this section, we'll show you a code example of how to apply the example above.

In the first step, you need an instance of the service manager to perform an action on the BOPF. Then you fill the selection table with the restrictions and in the last step transfer everything to the QUERY method of the service manager. You get back a message object that you should still check for errors, as well as the key table if entries are included. Since you only received the keys, you still need to request the data via the RETRIEVE method.


DATA:
  lt_sel  TYPE /bobf/t_frw_query_selparam,
  lt_data TYPE ztest_t_contract.

" Service Manager Instance
DATA(lo_smgr) = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( zif_tst_bopf_c=>sc_bo_key ).

" Fill selection
APPEND VALUE #(
  attribute_name  = zif_tst_bopf_c=>sc_node_attribute-contract-creditor
  sign            = 'I'
  option          = 'EQ'
  low             = '0000123456'
) TO lt_sel.

" Get the keys
lo_smgr->query(
  EXPORTING
    iv_query_key            = zif_tst_bopf_c=>sc_query-contract-select_by_elements
    it_selection_parameters = lt_sel
  IMPORTING
    eo_message              = DATA(lo_msg_query)
    et_key                  = DATA(lt_key)
).

" Validate errors
IF lo_msg_query->check( ) = abap_true OR lt_key IS INITIAL.
  RETURN.
ENDIF.

" Read data
lo_smgr->retrieve(
  EXPORTING
    iv_node_key             = zif_tst_bopf_c=>sc_node-contract
    it_key                  = lt_key
  IMPORTING
    eo_message              = DATA(lo_msg)
    et_data                 = lt_data
).

 

Hint: As you probably noticed, we use the constant interface of the BOPF model for the creation of the service manager, but also for the accesses. Never store the values as literals in these places, as these could change when the interface is regenerated.

 

Conclusion

Using the queries, you can now access the data and limit the return quantities. From here, the data model can already be used for evaluations. You see, with the standard queries already many things are possible and you do not always need your own logics.


Included topics:
BOPFQueriesRead data
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.


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.

10/23/2020

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.

09/11/2020

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.

03/20/2020

ABAP - BOPF Performance

Category - ABAP

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

03/13/2020

ABAP - BOPF Helper methods

Category - ABAP

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

02/21/2020