cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP RAP Custom-Entity - Call External URL

0 Likes
5,766

Dear experts,

We are using Custom-entity to create an application that retrieves backend data and displays in List report page. One of the column is a URL field, that needs to redirect to the website once clicked. But we are getting a binding error, which is not back traceable. Since we are not doing any binding from RAP side, we are unsure on how to achieve this. SAP documentation referred : URL in CDS

Metadata:


Output:

Issue:


Could you please help to resolve this or suggest any alternate methods to achieve this.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

For me it works with a custom entity.

I see as a difference that I used the data type abap.char(256); for my URL.

I used the following custom entity

@EndUserText.label: 'Test creation of custom entity'


@ObjectModel: {
    query: {
        implementedBy: 'ABAP:ZCL_MY_CLASS'
    }
}
define custom entity ZDEVXXX_I_CE_BOOKING_0012
{
      // key client        : abap.clnt;
      @UI.lineItem  : [{
          position  : 10
      }]
  key travel_id     : /dmo/travel_id;
      @UI.lineItem  : [{
         position   : 20
      }]
  key booking_id    : /dmo/booking_id;
      @UI.lineItem  : [{
           position : 30
       }]
      booking_date  : /dmo/booking_date;
      customer_id   : /dmo/customer_id;
      carrier_id    : /dmo/carrier_id;
      connection_id : /dmo/connection_id;
      flight_date   : /dmo/flight_date;
      @Semantics.amount.currencyCode: 'currency_code'
      flight_price  : /dmo/flight_price;
      currency_code : /dmo/currency_code;




      url           : abap.char(256);
      @UI.lineItem  : [ {
      position      : 40,
      type          : #WITH_URL,
      url           : 'url'   -- Reference to element
      } ]


      name          : abap.char(10);




}


<br>

I used the following class as implementation:

CLASS zcl_my_class DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .


  PUBLIC SECTION.
    INTERFACES if_rap_query_provider.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.






CLASS zcl_my_class IMPLEMENTATION.


  METHOD if_rap_query_provider~select.


    IF io_request->is_data_requested( ).


*      TRY.
          "get and add filter
          DATA(lt_filter_cond) = io_request->get_filter( )->get_as_ranges( ). "  get_filter_conditions( ).


*       CATCH cx_rap_query_filter_no_range INTO DATA(lx_no_sel_option).


          "@todo :
          " raise an exception that the filter that has been provided
          " cannot be converted into select options
          " here we just continue


*   ENDTRY.


      DATA(lv_top)     = io_request->get_paging( )->get_page_size( ).
      DATA(lv_skip)    = io_request->get_paging( )->get_offset( ).
      DATA(lt_fields)  = io_request->get_requested_elements( ).
      DATA(lt_sort)    = io_request->get_sort_elements( ).


    ENDIF.


    DATA lt_response_in TYPE STANDARD TABLE OF  zdevxxx_i_ce_booking_0012.
 DATA lt_response_out TYPE STANDARD TABLE OF  zdevxxx_i_ce_booking_0012.
    lt_response_in = VALUE #( (   travel_id ='00000001' booking_id ='0001' booking_date ='20210106' customer_id ='000594' carrier_id ='UA' connection_id ='1537' flight_date ='20210123' flight_price ='438.00 ' currency_code ='USD'
      url = 'http://www.google.com' name = 'Google' )
     (   travel_id ='00000001' booking_id ='0002' booking_date ='20210123' customer_id ='000594' carrier_id ='AA' connection_id ='0322' flight_date ='20210125' flight_price ='438.00 ' currency_code ='USD'
      url = 'http://www.bing.com' name = 'Bing' )
     (   travel_id ='00000001' booking_id ='0003' booking_date ='20211031' customer_id ='000594' carrier_id ='UA' connection_id ='1537' flight_date ='20211119' flight_price ='438.00 ' currency_code ='USD'  )
     (   travel_id ='00000001' booking_id ='0004' booking_date ='20211104' customer_id ='000594' carrier_id ='AA' connection_id ='0322' flight_date ='20211121' flight_price ='438.00 ' currency_code ='USD'  )
     (   travel_id ='00000002' booking_id ='0001' booking_date ='20210121' customer_id ='000099' carrier_id ='UA' connection_id ='1537' flight_date ='20210123' flight_price ='438.00 ' currency_code ='USD'  )
     (   travel_id ='00000002' booking_id ='0002' booking_date ='20210121' customer_id ='000660' carrier_id ='UA' connection_id ='1537' flight_date ='20210123' flight_price ='438.00 ' currency_code ='USD'  )


     ).


                 DATA(dyn_clause) =  io_request->get_filter( )->get_as_sql_string( ).


            SELECT * FROM @lt_response_in AS products
            WHERE (dyn_clause)
            ORDER BY travel_id
            INTO CORRESPONDING FIELDS OF TABLE @lt_response_out
            UP TO @lv_top ROWS
            OFFSET @lv_skip .


    io_response->set_total_number_of_records( lines( lt_response_out ) ).
    io_response->set_data( lt_response_out ).




  ENDMETHOD.


ENDCLASS.
0 Likes

Thanks Andre. It works.!

How do we open it in new tab by default. Currently it opens in same tab.

Answers (2)

Answers (2)

BhargavaTanguturi
Active Participant

Just try without @Semantics.url annotation and @UI.lineitem with a single entry.

like, @UI.lineitem: [{ position: 90, importance: #HIGH, type: #WITH_URL, url: 'URL' }]

0 Likes

Hi Bhargava, Thanks for the suggestion.

But still the same binding error after these changes.