Skip to Content
Technical Articles
Author's profile photo Gangadhar Rao Bonda

How to use a RFC Function module using RESTful ABAP Programming

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.

5. Bind the service.

6. Activate the service in iwfnd/maint_service and run your URI to get your data from FM.

URI: /sap/opu/odata/sap/Z_BIND_XXXXX_RFC/zce_xxxxx_rfc(im_country=’US’,im_zipcode=’53041′)/Set

We need to use the ‘Set’ at the end of our URI to get the data.

 

Thank you “Julie Plummer” for  writing blog on custom entity. It helped me in achieving my requirement.

Reference: https://developers.sap.com/tutorials/abap-environment-rfc-custom-entity.html

 

Thank you,

Gangadhar

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Matthew Billingham
      Matthew Billingham

      Can I suggest you changed the subject of the blog to something like: "How to call an RFC from  a CDS using RESTful ABAP programming".

      It was very unclear to me initially what you were trying to achieve. And the fact that you can only code CDS using Eclipse isn't really relevant. I could easily write a program that would allow you to create this CDS using SAPGui! (And it will still follow exactly the same course of your blog).

      But aside from that - interesting to know.

      Author's profile photo Sandra Rossi
      Sandra Rossi

      Thank you. I have a collection of RFC-enabled function modules, and I want the customer to be able to choose between RFC and HTTP. So, I am interested in using a CDS Custom Entity with Parameters as you demonstrated.

      But in your demonstration, I don't understand the interest of using RFC (DESTINATION 'XXXXXX') from within the custom class. Differently said, you are using HTTP to call the function module in the SAP server you wish, shouldn't we choose either HTTP or RFC, why using both?

      Thanks 😉

      Author's profile photo Ravi Singh
      Ravi Singh

      An apt title for this blog should be 'How to call RFC in a custom entity'. 😉

      Author's profile photo Jenie Archana Jerald Raja
      Jenie Archana Jerald Raja

      Thanks You.I have a similar requirement to use RFC FM to fetch data from another SAP system and use in custom entity query class. But, can you brief about what type of RFC destination to be created in this case.Because, when I tried the same approach, I'm getting an error saying 'Name or password incorrect(repeat logon) resulting in dump.