I got a requirement to use RFC function module to get the data third party system. Using ABAP programming it is a cake walk for any ABAP developer. But, my client asked to use Eclipse and CDS to achieve this functionality. As many of us are new to Eclipse and CDS views. After doing R&D and found one reference to achieve my requirement. I hope this blog helps to all those who are going to start using Eclipse ADT for their developments.
1. Create a CDS view using templet “Custom entity with parameters”.
2. Create custom entity as per your required output and make sure to give the Class name “ABAP:ZCL_RFC_DETERMINE_JURISDICTION” where you are going to call your function module.
EndUserText.label: 'XXXXXXX RFC for tax'
@ObjectModel.query.implementedBy: 'ABAP:ZCL_RFC_DETERMINE_JURISDICTION'
@UI: {
headerInfo: {
typeName: 'xxxxxx',
typeNamePlural: 'xxxxx RFC'
}
}
define custom entity zce_xxxxxx_rfc
with parameters im_country : land_tax,
im_zipcode : ort02_bas
{
key COUNTRY : land_tax;
STATE : regio;
CITY : ort01_gp;
COUNTY : ort02_bas;
ZIPCODE : pstlz;
TXJCD_L1 : lengx_txd;
TXJCD_L2 : lengx_txd;
TXJCD_L3 : lengx_txd;
TXJCD_L4 : lengx_txd;
TXJCD : txjcd;
OUTOF_CITY : outcity;
}
3. Create a class to use the custom entity using the interface “if_rap_query_provider”.
CLASS zcl_rfc_determine_jurisdiction DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_rap_query_provider.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_rfc_determine_jurisdiction IMPLEMENTATION.
METHOD if_rap_query_provider~select.
DATA lt_result TYPE STANDARD TABLE OF zce_xxxxxx_rfc.
DATA: lv_cntry TYPE land_tax,
lv_zipcode TYPE ort02_bas.
TRY.
TRY.
TRY.
IF io_request->is_data_requested( ).
io_request->get_paging( ).
DATA(lt_filter_cond) = io_request->get_parameters( ).
DATA(lt_filter_cond2) = io_request->get_filter( )->get_as_ranges( ).
lv_cntry = VALUE #( lt_filter_cond[ parameter_name = 'IM_COUNTRY' ]-value OPTIONAL ). "Fetching the parameter value
lv_zipcode = VALUE #( lt_filter_cond[ parameter_name = 'IM_ZIPCODE' ]-value OPTIONAL ). "Fetching the parameter value
"Initialize values
DATA(ls_error) = VALUE com_err( ).
"Build Location Data
DATA(ls_locdata) = VALUE com_jur(
country = lv_cntry
zipcode = lv_zipcode ).
CALL FUNCTION 'RFC_DETERMINE_JURISDICTION'
DESTINATION 'XXXXXX'
EXPORTING
location_data = ls_locdata
IMPORTING
location_err = ls_error
TABLES
location_results = lt_result
EXCEPTIONS
OTHERS = 1.
DATA(lv_offset) = io_request->get_paging( )->get_offset( ).
DATA(lv_page_size) = io_request->get_paging( )->get_page_size( ).
io_response->set_total_number_of_records( lines( lt_result ) ).
io_response->set_data( lt_result ).
ENDIF.
CATCH cx_rap_query_provider INTO DATA(lx_exc).
ENDTRY.
CATCH cx_rfc_dest_provider_error INTO DATA(lx_dest).
ENDTRY.
CATCH cx_rap_query_filter_no_range.
ENDTRY.
ENDMETHOD.
ENDCLASS.
4. Definition your service as show below.
No comments:
Post a Comment