Skip to Content
Technical Articles
Author's profile photo Ramesh Vodela

SAP BTP CPI iflow end to end integration using RFC Adapter – Part 5

In this blog we will develop an BTP integration suite iflow which will retrieve booking information from a custom RFC FM and then send email about the booking info.  The aim of this blog is to showcase a common scenario we face about triggering integration when a new record is posted using RFC adapater.

To recap my earlier blogs I describe in detail on configuration steps to for CPI and onPrem SAP system which is a trial ABAP system

PART1 https://blogs.sap.com/2021/01/14/send-idoc-from-abap-trail-version-npl-to-cloud-platform-integration/

PART 2  https://blogs.sap.com/2021/01/17/send-idoc-from-cloud-platform-integration-to-ecc-inbound-part2/ 

In part 3 I trigger IDOC creation on SAVE of Flight Booking

Part 3  https://blogs.sap.com/2021/12/30/idoc-to-btp-cpi-from-ecc-on-save-of-flight-booking-part-3/ 

in Part 4 we use odata adapter to invoke the iflow on Save of flight Booking

PART4:https://blogs.sap.com/2022/01/01/sap-btp-cpi-iflow-end-to-end-integration-using-odata-adapter-part-4/

In many use cases we already have RFC FM that can do the required job and we don’t want to create odata service.  To cater of this use case we will show how we can use RFC adapter in BTP is used to  achieve the same result. ( send Booking confirmation email on SAVE in Tcode BC_GLOBAL_SBOOK_CREA.)

The following steps are required to achieve this.

 

  1. Custom RFC FM to fetch the SFLIGHT booking record.
  2. XML transform using Tcode XSLT_TOOL which will convert a custom type we created to match the input parameters of RFC FM..  This generates XML string that maps to the input parameters which are required in sending HTTP request to BTP iflow.
  3. Cloud Connector Settings for RFC
  4. BTP Destination for the RFC
  5. BTP Integration Suite iflow that has inbound XML to invoke the RFC using the RFC adapter and send email.
  6. Custom FM to call the BTP iflow using HTTP client
  7. Implicit enhancement in the include BC_GLOBAL_SBOOK_CREATEF01 in FORM SAVE routine.
  8. Check the end to end integration using TCODE BC_GLOBAL_SBOOK_CREA and email that you have received the booking confirmation record.                                                                     we will now describe the steps in complete detail.

 

  1. Custom RFC to get the booking                                                                                                        FUNCTION zget_flight_booking_data.
    *”———————————————————————-
    *”*”Local Interface:
    *”  IMPORTING
    *”     VALUE(I_CARRID) TYPE  S_CARR_ID
    *”     VALUE(I_CONNID) TYPE  S_CONN_ID
    *”     VALUE(I_FLDATE) TYPE  CHAR10
    *”     VALUE(I_BOOKID) TYPE  S_BOOK_ID
    *”  EXPORTING
    *”     VALUE(E_BOOKDATA) TYPE  SBOOK
    *”———————————————————————-

    DATAlv_date TYPE dats.
    CALL FUNCTION ‘CONVERSION_EXIT_PDATE_INPUT’
    EXPORTING
    input        i_fldate
    IMPORTING
    output       lv_date
    EXCEPTIONS
    invalid_date 1
    OTHERS       2.

    IF sysubrc 0.

    SELECT SINGLE FROM sbook INTO e_bookdata WHERE
    carrid =  i_carrid AND
    connid i_connid AND
    fldate lv_date AND
    bookid =  i_bookid.
    ENDIF.
    ENDFUNCTION.

  2. A) Create XML transform.  For this we create a custom structure as shown belowB) Tcode XSLT_TOOL   use the wizrd button and create a root node as shown below  C) change the source code so that we have the name space as shown below 3 Cloud connector settings should as shown below ( from cloud to onPremise) for the location id that points your BTP sub client instance.Now add the source to the FM created in Step 1 as shown below                                                Check the connection is working                                                                                                   4.  BTP create a destination in BTP->Connectivity=>destinations and create new destination as shown below                                                                                                                              check that the connection is working fine.                                                                                     5  BTP integration suite flow with http inbound invokes the RFC using RFC adapter via the destination created in the previous step and the booking confirmation email as shown below      HTTP sending settings as shown below, RFC and email settings are shown in the order below  NPLRFC is the destination that was created in the earlier step.   Email Adapter settings are as shown          Save and deploy the integration  and note the url                                                                         6  Custom FM to invoke the integration created in the previous step – The code is as show below FUNCTION zcall_cpi_rfcbookingconfirm.
    *”———————————————————————-
    *”*”Local Interface:
    *”  IMPORTING
    *”     VALUE(I_CARRID) TYPE  S_CARR_ID
    *”     VALUE(I_CONNID) TYPE  S_CONN_ID
    *”     VALUE(I_FLDATE) TYPE  DATS
    *”     VALUE(I_BOOKID) TYPE  S_BOOK_ID
    *”     REFERENCE(I_MAINURL) TYPE  STRING
    *”     REFERENCE(I_EXRURL) TYPE  STRING
    *”     REFERENCE(I_USERNAME) TYPE  STRING
    *”     REFERENCE(I_PASSWORD) TYPE  STRING
    *”———————————————————————-

    DATAlo_json        TYPE REF TO cl_clb_parse_json,
    lv_url         TYPE string,
    lo_rest_client TYPE REF TO cl_rest_http_client,
    lo_response    TYPE REF TO if_rest_entity,
    lo_request     TYPE REF TO if_rest_entity,
    lo_sql         TYPE REF TO cx_sy_open_sql_db,
    status         TYPE  string,
    reason         TYPE  string,
    response       TYPE  string,
    content_length TYPE  string,
    location       TYPE  string,
    content_type   TYPE  string,
    lv_status      TYPE  i,
    http_status    TYPE        string,
    lv_xml_string  TYPE xstring,
    lv_body        TYPE string,
    lv_newdate     TYPE char10.

    CALL FUNCTION ‘CONVERSION_EXIT_PDATE_OUTPUT’
    EXPORTING
    input  i_fldate
    IMPORTING
    output lv_newdate.

    DATAls_bookrec  TYPE zrfcboook.

    ls_bookreci_carrid  i_carrid.
    ls_bookreci_connid  i_connid.
    ls_bookreci_fldate lv_newdate.
    ls_bookreci_bookid i_bookid.

    TRY.

    cl_http_client=>create_by_url(
    EXPORTING
    url                i_mainurl
    IMPORTING
    client             DATA(lo_http_client)
    EXCEPTIONS
    argument_not_found 1
    plugin_not_active  2
    internal_error     3
    OTHERS             ).

    CALL TRANSFORMATION  ztr_sbook_key
    SOURCE zget_flight_booking_data =  ls_bookrec
    RESULT XML lv_xml_string.

    CALL METHOD cl_abap_conv_in_ce=>create
    EXPORTING
    input lv_xml_string
    RECEIVING
    conv  DATA(lr_conv).

    lr_conv->read(
    IMPORTING
    data    lv_body ).

    lo_http_client->propertytype_logon_popup lo_http_client->co_disabled.

    CALL METHOD lo_http_client->authenticate
    EXPORTING
    username i_username
    password i_password.

    lo_http_client->request->set_methodif_http_request=>co_request_method_post ).

    CREATE OBJECT lo_rest_client
    EXPORTING
    io_http_client lo_http_client.
    lo_http_client->request->set_versionif_http_request=>co_protocol_version_1_0 ).

    IF lo_http_client IS BOUND AND lo_rest_client IS BOUND.
    lv_url i_exrurl.
    “lv_url = ‘/http/BookingConfirm’.
    cl_http_utility=>set_request_uri(
    EXPORTING
    request lo_http_client->request    ” HTTP Framework (iHTTP) HTTP Request
    uri     lv_url
    ).

    lo_request lo_rest_client->if_rest_client~create_request_entity).
    lo_request->set_content_typeiv_media_type if_rest_media_type=>gc_appl_json ).
    lo_request->set_string_datalv_body ).

    lo_rest_client->if_rest_resource~postlo_request ).

    lo_response lo_rest_client->if_rest_client~get_response_entity).
    http_status lv_status lo_response->get_header_field‘~status_code’ ).
    reason lo_response->get_header_field‘~status_reason’ ).
    content_length lo_response->get_header_field‘content-length’ ).
    location lo_response->get_header_field‘location’ ).
    content_type lo_response->get_header_field‘content-type’ ).
    response lo_response->get_string_data).

    ENDIF.

    CATCH cx_root INTO DATA(lr_exc).
    DATA(lv_messagelr_exc->get_text).
    WRITE:/ lv_message.
    ENDTRY.
    ENDFUNCTION.                                                                                                                            7 Create the implicit enhancement that is invoked on Flight Booking Tcode as shown below. The code is very similar to the code  in Part 4 odata adapter except for 2 parameters name FLDATE and I_extrul which now points to the new iflow to invoke the RFC  8 Create a new Booking using the TCODE BC_GLOBAL_SBOOK_CREA and check the email showing the booking confirmation details from the RFC as shown below    Email showing the booking confirmation    As seen we can use the existing RFC FM that are already in the SAP System or convert FM to RFC FM and use the RFC adapter to provide efficiency in processing

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Mio Yasutake
      Mio Yasutake

      Thanks for these blog series.

      Explaining CPI basics with simple examples is very helpful!