Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

READ Method is not triggering for SAP RAP Service Read Web API Call

AlokKumar
Discoverer
0 Kudos
2,613
Hi Experts,
I have a requirement to implement Read Method for SAP RAP Web API Service. In the Read call I need to send message-based condition. I created Behavioral Definition for the same with unmanaged scenario  but the READ method is not triggering Read Web API Call .
Please let me know what I am missing ?

I tried to execute with read call, data is coming but no error message https://1374dadc-372f-46e3-a692-b2bd57ae0ee4.abap-web.us10.hana.ondemand.com/sap/opu/odata4/sap/yap_....

unmanaged;
//strict ( 2 );

define behavior for YAP_CDS_VIEW_NEW1 alias Testview
 implementation in class zbp_ap_cds_view_new1 unique
//persistent table zfe_atrav_001031
//lock master
authorization master ( instance )
//etag master <field_name>
{


}



CLASS lhc_YAP_CDS_VIEW_NEW1 DEFINITION INHERITING FROM cl_abap_behavior_handler.
  PRIVATE SECTION.

  data: keys TYPE TABLE FOR READ IMPORT yap_cds_view_new1,
       result TYPE TABLE FOR READ RESULT yap_cds_view_new1.

    METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
      IMPORTING keys REQUEST requested_authorizations FOR yap_cds_view_new1 RESULT result.

    METHODS read FOR READ
        IMPORTING keys FOR READ yap_cds_view_new1
        RESULT result.

ENDCLASS.

CLASS lhc_YAP_CDS_VIEW_NEW1 IMPLEMENTATION.

  METHOD get_instance_authorizations.

  READ ENTITIES OF yap_cds_view_new1 IN LOCAL MODE
    ENTITY Testview
    ALL FIELDS WITH CORRESPONDING #( keys )
    RESULT DATA(results).

    DATA(lresult) =  results[ 1 ].

    APPEND VALUE #(  %tky = lresult-%tky ) TO failed-Testview.

    APPEND VALUE #( %tky        = lresult-%tky
                    %msg        = new_message_with_text(

                         severity = if_abap_behv_message=>severity-error
                         text = 'No Data Found' )
                          )
            TO reported-Testview.
  ENDMETHOD.

  METHOD read.

  READ ENTITIES OF yap_cds_view_new1 IN LOCAL MODE
    ENTITY Testview
    ALL FIELDS WITH CORRESPONDING #( keys )
    RESULT DATA(results).

    DATA(lresult) =  results[ 1 ].

    APPEND VALUE #(  %tky = lresult-%tky ) TO failed-Testview.

    APPEND VALUE #( %tky        = lresult-%tky
                    %msg        = new_message_with_text(

                         severity = if_abap_behv_message=>severity-error
                         text = 'No Data Found' )
                          )
            TO reported-Testview.

  ENDMETHOD.

ENDCLASS.

Thanks in advance Alok

7 REPLIES 7

AlokKumar
Discoverer
0 Kudos
2,508

Any update on this . Pls let me know .

hannavanvliet
Associate
Associate
0 Kudos
2,264

Did you manage to solve this?

ajaymukundan1981
Explorer
0 Kudos
2,023

@AlokKumar we're facing same issue. during GET method, the READ method is not getting triggered. 

Could you let me know how you resolved it?

holm
Participant
0 Kudos
1,963

Read requests will be directly executed as queries on the underlying CDS entities. 
And your read implementation won’t work, since that EML statement would result in a read again… you have to implement the transaction buffer by yourself.

Former Member
0 Kudos
1,236

Hello all,

I'm facing an issue with data storage in an unmanaged scenario. While I understand that reads are executed as queries on the underlying CDS entity, I'm unable to store the data in the behavior implementation since I'm using a service consumption model.

I would like to be able to store the data as it is read. The tutorials (like this one) suggest that the read operation should be triggered automatically. I've tried removing the "@ObjectModel.query.implementedBy:" annotation, but this results in an error indicating that data cannot be extracted from the database in a custom entity model. I've also attempted to create a database and set up an unmanaged scenario, but the read operation is still not being triggered.

If anyone has experience with getting read operations to work in an unmanaged scenario, I would greatly appreciate your guidance.

Best regards,
Rafael

Former Member
0 Kudos
1,163

Hello,

So I've looked into this and, if you've implemented an unmanaged BO (this is NOT QUERY), the "READ" method will only be triggered after Create / Update / Delete operation is executed, as the "Read modified entities" phase. A query scenario would trigger a "Select" method of our API if_rap_query_provider. The READ method of the BDef implementation, however, belongs to the transactional scenarios, not to the query case.

Basically, despite its name suggesting general read functionality, it does not handle initial data retrieval or general query operations.

Best regards,
Rafael

gurmukh_a
Explorer
0 Kudos
798
Remember

The GO button on the UI does not call the <method> FOR READ (the transactional READ) in the behavior pool. Instead, the GO button executes a query via the RAP runtime engine and reads data directly from the database.

The READ operation provides read access to the application buffer. It is used to retrieve data for further processing during the interaction phase. This is necessary, for example, for ETag comparison when executing an UPDATE