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

SAP BTP CPI iflow end to end integration using odata Adapter – Part 4

In this blog we will develop an BTP integration suite iflow which will retrieve booking information from a custom odata service and then 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.

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/ 

However there are many use cases which don’t use IDOCS – so cater for this situation this blog describes in detail on how we can invoke CPI inflow that will retrieve the Current Booking information using a custom odata and then send he Flight Booking information by email.

To achieve this we have to do the following

  1. Custom odata service to query SBOOK records
  2. Create BTP  Integration Suite iflow which has inbound http request with Json data with SBOOK key information and all transformations required to invoke odata service created in step 1
  3. A custom FM to invoke the iflow using HTTP client  from ABAP
  4. Invoke the custom FM from an implicit enchantment when a new booking is saved in the tcode BC_GLOBAL_SBOOK_CREA
  5. Test the end to end integration and check the email that will be sent by the iflow showing booking confirmation details

Let us now see in detail each of the above steps and test the final end to end secnerio.

  1. Custom odata service to query SBOOK records                                                                      In Eclipse create new CDS view as shown below@AbapCatalog.sqlViewName: ‘ZSBOOKTEST6’
    @AbapCatalog.compiler.compareFilter: true
    @AbapCatalog.preserveKey: true
    @EndUserText.label: ‘Get Booking data’
    @OData.publish: true
    define view ZFL_SBOOK_DATA2
    as select from sbook
    {key carrid as Carrid,
    key connid as Connid,
    key fldate as Fldate,
    key bookid as Bookid,
    customid as Customid,
    custtype as Custtype,
    smoker as Smoker,
    luggweight as Luggweight,
    wunit as Wunit,
    invoice as Invoice,
    class as Class,
    forcuram as Forcuram,
    forcurkey as Forcurkey,
    loccuram as Loccuram,
    loccurkey as Loccurkey,
    order_date as OrderDate,
    counter as Counter,
    agencynum as Agencynum,
    cancelled as Cancelled,
    reserved as Reserved,
    passname as Passname,
    passform as Passform,
    passbirth as Passbirth

    }

    Activate the service and in tcode /IWFND/MAINT_SERVICE add the above using using add service option.

  2. create a BTP integration suite iflow as shown belowAs show in the above image we have an inbound HTTP that gets json data which is converted into XML.  We add content modifiers that stores the SBOOK key information in header and then we invoke the odata service passing the key information and send the query result by email.  The configuration details are shown as below                                                                     A) HTTP configuration

B)  Content Modifier Configuration

we store the SBOOK key information passed by HTTP request in the header variables as shown

 

C) Invoke odata service based on SBOOK and rederive  the booking based on the key provided.  In Integration suite we have to create security material key pair with SAP ECC username and password(I named this odata). In my cloud connector I have create cloud to SAP connection that maps virtual host  http://s4h2:8000 to trail ABAP system NPL.

 

 

D) Email Adapter configuration is as shown below

 

Save and deploy the integration.  Note the IFLOW url which we will invoke from an implicit enhancement when a flight booking is saved.

3) Custom ABAP FM to invoke the iflow is as shown below.

In the code we have Standard SAP ABAP to JSON serializer.  To make this work correctly with leading zeros for  NUMC and integers I changed the data type to CHARS.

FUNCTION zcall_cpi_bookingconfirm.
*”———————————————————————-
*”*”Local Interface:
*”  IMPORTING
*”     VALUE(I_CARRID) TYPE  S_CARR_ID
*”     VALUE(I_CONNID) TYPE  S_CONN_ID
*”     VALUE(I_FLDATE) TYPE  CHAR30
*”     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,
lr_json_serializer TYPE REF TO cl_trex_json_serializer,
lv_encode          TYPE char20 VALUE ‘T00%3A00%3A00’,
lv_newdate         TYPE char30.

IF strleni_fldate 8.
CONCATENATE i_fldate+0(4‘-‘ i_fldate+4(2‘-‘ i_fldate+6(2)    lv_encode  INTO lv_newdate  .
ELSE.
lv_newdate i_fldate.
ENDIF.
TYPESBEGIN OF record,
i_carrid TYPE s_carr_id,
i_connid TYPE char4,
i_fldate TYPE char30,
i_bookid TYPE char8,
END OF record.

DATAlv_bookrec  TYPE record.

lv_bookreci_carrid  i_carrid.
lv_bookreci_connid  i_connid.
lv_bookreci_fldate lv_newdate.
lv_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             ).

DATA(lv_body/ui2/cl_json=>serializedata          lv_bookrec
pretty_name   /ui2/cl_json=>pretty_modecamel_case
compress      abap_true
).

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.

4) invoke the integration from an implicit enhancement  in the include BC_GLOBAL_SBOOK_CREATEF01 and in FORM SAVE as shown below

I_MAINURL = url of the deployed iflow ending with .com

I_EXTURL  = the last of url after .com

I_USERNAME = the client id from  configuration file of Auth service

I_PASSWORD = the client secret from  configuration file of Auth service.

 

Activate the enhancement.

5) Test the integration by creating a new booking using the TCODE BC_GLOBAL_SBOOK_CREA and check the email

 

 

Email sent by the filow

 

 

We have shown an end to end process using BTP Integration suite using implicit enhancement invoking iflow that calls odata and sends email

 

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.