Mentor SAP

Implementation of a Query Operation

Implementing the methods in the Data Provider Extension Class means overwriting the corresponding methods from the superclass. The most frequently redefined methods are as follows:

 

Code-Based Implementation

The EXECUTE_ACTION method allows you to implement what is known as a function import. A function import is a function resource that can be called on the server. This is to be used for specialized functionality that does not fit within the uniform meaning of CREATE, READ, UPDATE, and DELETE.

 

It is important to note that a function import has to be implemented with the ABAP code, though it can be added to the model using the Service Builder. In the Service Builder, in a dialog box, you specify its name, the result type, a typed parameter set, and the HTTP operation used to call it. The functionality belonging to the function import cannot be implemented with mapping. Instead, you have to use code-based implementation of the EXECUTE_ACTION method of the Data Provider Class.

 

 

productset_get_entityset Code

METHOD productset_get_entityset.
DATA: ls_entity     LIKE LINE OF  et_entityset,
lt_headerdata TYPE TABLE OF bapi_epm_product_header,
ls_headerdata TYPE          bapi_epm_product_header,
lt_return     TYPE TABLE OF bapiret2.

* Get data
CALL FUNCTION 'BAPI_EPM_PRODUCT_GET_LIST'
TABLES
headerdata = lt_headerdata
return     = lt_return.
* Error handling
IF lt_return IS NOT INITIAL.
" Message Container
mo_context->get_message_container( )
->add_messages_from_bapi( lt_return ).
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
textid = /iwbep/cx_mgw_busi_exception=>business_error
message_container = mo_context->get_message_container( ).
ENDIF.
* Fill response data
LOOP AT lt_headerdata INTO ls_headerdata.
MOVE-CORRESPONDING ls_headerdata TO ls_entity.
APPEND ls_entity TO et_entityset.
ENDLOOP.
ENDMETHOD.

 

productset_get_entityset Code Description

The selected data is returned by using the export parameter ET_ENTITYSET.

 

MOVE-CORRESPONDING is used since not all fields of the structure BAPI_EPM_PRODUCT_HEADER have been used for the entity set.

 

By using MOVE-CORRESPONDING, the coding would also work if the underlying DDIC structure is enhanced by an append structure.

 

As a result, the data returned by the BAPI has to be adapted to the export parameter ET_ENTITYSET. The parameter ET_ENTITYSET is based on the type ZCL_Z_GW100_000_MPC=>TT_PRODUCT defined in the model provider class.

 

Errors should be raised by using the exceptions /IWBEP/CX_MGW_BUSI_EXCEPTION for errors in the business logic, while technical exceptions should be raised via /IWBEP/CX_MGW_TECH_EXCEPTION. For example, checks should be implemented if an entity set is marked as non-addressable.

 

A query without query options would generate a result set that is too large, for example, a query of all sales orders or all sales order items in a system without at least specifying the business partner, a time frame, or the net amount.

 

Implementation of a Read Operation

METHOD productset_get_entity.
DATA:
lt_keys       TYPE /iwbep/t_mgw_tech_pairs,
ls_key        TYPE /iwbep/s_mgw_tech_pair,
ls_product_id TYPE bapi_epm_product_id,
ls_headerdata TYPE bapi_epm_product_header,
lt_return     TYPE TABLE OF bapiret2.
* Get key fields from request
CALL METHOD IO_TECH_REQUEST_CONTEXT
->GET_CONVERTED_KEYS
IMPORTING
ES_KEY_VALUES = ls_headerdata.
ls_product_id-product_id=
ls_headerdata-PRODUCT_ID.
* Get data
CALL FUNCTION 'BAPI_EPM_PRODUCT_GET_DETAIL'
EXPORTING
product_id = ls_product_id
IMPORTING
headerdata = ls_headerdata
TABLES
return     = lt_return.
IF lt_return IS NOT INITIAL.
* Raise exception
ENDIF.
* Fill response data
MOVE-CORRESPONDING ls_headerdata TO er_entity.
ENDMETHOD