Summary:

The purpose of this document is to explain and provide a step-by-step walkthrough to implement Exchange rate files (CSV) Scenario using ABAP code in PI. Also this would give a clear picture how to write the ABAP code in PI.

Introduction: This document will gives clear idea about How to get a CSV file from Web page using ABAP Code in SAP PI. At sender side Customer bank team is updating Exchange rate file in their web page then PI will pick the data and send to ECC.

For this interface, there is no need of creating any sender adapter while there is a need of creation of receiver XI (Proxy) adapter..

Business Scenario: We need to retrieve daily exchange rates from the web page and upload them into
SAP ECC using Proxy communication

Fi.png

Pre-Requisites:

Basic knowledge of XI/PI, XML and ABAP etc…

Assumption      SLD configuration is with Technical System and Business System is done. Product and SWC is created in SLD.

  •     SWC is imported in ESR.
  •     Communication between webpage to ABAP Program and ABAP program to PI need to create.
  •   Create the RFC destination to connect to Web page:

Using Tr Code: SM58 to create the RFC Destination (BANK to PI)

              Provide the details below:

    •   Connection type: G
    • Target host: specify the bank host name
    • Path prefix: Specify the bank path prefix

/wp-content/uploads/2014/09/fo1_546028.png

  • Create the one more RFC Destination to connect to ABAP program to PI and specify the below details
    • Connection type: G
    • Target Host: SAP PI host
    • Service No  : SAP PI Service No
    • Path perfix : /sap/xi/adapter_plain?namespace=XXXXXXXXX&interface=XXXX&service=XXXX&qos=EO       

/wp-content/uploads/2014/09/fo2_546030.png

ABAP Code


REPORT ZTRIGGER_CNB_INTERFACE.

tables RFCDES.data w_rc like sysubrc.data w_message type string.data w_client type ref to if_http_client.data w_subrc type sysubrc.data w_wsubrc(10).data w_sytabix(4).data w_errortext type string.data w_timeout type i.data w_response type ref to cl_HTTP_RESPONSE.data w_xrdata type xstring.data w_pclient type ref to if_http_client.
PARAMETERS: p_dest  like rfcdesrfcdest  obligatory default ‘RFC Destination
                               
matchcode object HTTPDESTINATION.PARAMETERS: p_ldest like rfcdesrfcdest  obligatory default ‘RFC Destination’
                               
matchcode object HTTPDESTINATION.
*at selection-screen on p_dest.
 
select single * from RFCDES where RFCDEST = p_dest
                               
and RFCTYPE = ‘G’.
 
if sysubrc <> 0.
   
message i001(am) with ‘HTTP destination’ p_dest ‘is not correct!’.
 
endif.
at selection-screen on p_ldest.
 
select single * from RFCDES where RFCDEST = p_ldest
                               
and RFCTYPE = ‘G’.
 
if sysubrc <> 0.
    message i001(am) with ‘HTTP destination’ p_ldest ‘is not correct!’.

 
endif.
*start-of-selection.
  w_timeout
= 300.
* If the HTTP connection to CNB website failes, try again => max 10 times
 
do 10 times.
   
write syindex to w_sytabix.
   
concatenate ‘GETTING DATA FROM CNB WEBSITE. Attempt:-‘ w_sytabix
   
into w_message.
   
write:/ w_message.
   
perform get_data_from_CNB.
   
IF w_rc = 0.
      w_message
= ‘XML data from CNB web is fetched successfully’.
     
write:/ w_message.
     
exit.
   
else.
      w_message
= ‘XML data from CNB web could not be fetched’.
     
write:/ w_message color col_negative.
     
exit.
   
ENDIF.
 
enddo.

    write syindex to w_sytabix.
   
concatenate ‘POSTING DATA TO HTTP ADAPTER. Attempt:-w_sytabix
   
into w_message.
   
write:/ w_message.
   
perform send_data_to_http.
   
IF w_rc = 0.
      w_message
= ‘XML data is successfully sent to HTTP adapter’.
     
write:/ w_message.
     
exit.
   
else.
      w_message
= ‘XML data could not be sent to HTTP adapter’.
     
write:/ w_message color col_negative.
     
exit.
   
ENDIF.
 
enddo.

form get_data_from_CNB.

  clear w_rc.* open connection
 
call method cl_http_client=>create_by_destination
   
EXPORTING
      destination             
= p_dest
   
IMPORTING
     
client                  = w_client
   
EXCEPTIONS
      destination_not_found   
= 1
      internal_error         
= 2
      argument_not_found     
= 3
      destination_no_authority
= 4
      plugin_not_active       
= 5
     
others                  = 6.

  if sysubrc <> 0.
    w_rc
= sysubrc.
   
write sysubrc to w_wsubrc.
   
concatenate
   
‘HTTP Connection with CNB website failed. Return code = w_wsubrc
     
into w_message separated by space.
   
write:/ w_message color col_negative.
   
exit.
 
else.
    w_message
= ‘HTTP Connection with CNB website established’.
   
write:/ w_message.
 
endif.
* Send request – empty
 
call method w_client->send
   
EXPORTING
      timeout                   
= w_timeout
   
EXCEPTIONS
      http_communication_failure
= 1
      http_invalid_state       
= 2
      http_processing_failed   
= 3
     
others                    = 4.

  if sysubrc <> 0.
   
call method w_client->get_last_error
     
IMPORTING
       
code    = w_subrc
       
message = w_errortext.

    write w_subrc to w_wsubrc.
   
concatenate
   
‘Communication error while sending request. Return code = ‘ w_wsubrc
     
‘message: w_errortext
     
into w_message separated by space.
   
write:/ w_message color col_negative.
    w_rc
= w_subrc.
   
exit.
 
else.
    w_message
= ‘Communication with CNB website established’.
   
write:/ w_message.
 
endif.

  call method w_client->receive
   
EXCEPTIONS
      http_communication_failure
= 1
      http_invalid_state       
= 2
      http_processing_failed   
= 3
     
others                    = 4.

  if sysubrc <> 0.
   
call method w_client->get_last_error
     
IMPORTING
       
code    = w_subrc
       
message = w_errortext.

    write w_subrc to w_wsubrc.
   
concatenate
   
‘Communication error while receiving response from CNB website.’
    ‘ Return code = ‘ w_wsubrc
      ‘message: ‘
w_errortext
     
into w_message separated by space.
   
write:/ w_message color col_negative.
    w_rc
= w_subrc.
   
exit.
 
else.
    w_message = ‘Data from CNB website is fetched’.

   
write:/ w_message.
 
endif.
* access response
 
call method w_client->response->if_http_entity~get_data
    RECEIVING
     
DATA = w_xrdata.
* close connection
 
call method w_client->close
   
EXCEPTIONS
      http_invalid_state
= 1
     
others            = 2.

  if w_xrdata is initial.
    w_rc
= 4.
    w_message
= ‘Exchange rate data from CNB website could not be fetched’.
   
write:/ w_message color col_negative.
   
exit.
 
endif.
endform.                    “get_data_from_CNB
FORM send_data_to_http .

  clear w_rc.
 
call method cl_http_client=>create_by_destination
   
EXPORTING
      destination             
= p_ldest
   
IMPORTING
     
client                  = w_pclient
   
EXCEPTIONS
      destination_not_found   
= 1
      internal_error         
= 2
      argument_not_found     
= 3
      destination_no_authority
= 4
      plugin_not_active       
= 5
     
others                  = 6.

  IF SYSUBRC <> 0.
    w_rc
= sysubrc.
   
write sysubrc to w_wsubrc.
   
concatenate
   
‘HTTP Connection to post data to adapter failed. Return code = ‘ w_wsubrc
     
into w_message separated by space.
   
write:/ w_message color col_negative.
   
exit.
 
else.
    w_message
= ‘Connection with HTTP adapter to post data established’.
   
write:/ w_message.
 
ENDIF.
* request
 
call method w_pclient->REQUEST->if_http_entity~set_data
   
EXPORTING
     
DATA = w_xrdata.
* send data
 
CALL METHOD w_pclient->SEND
   
EXPORTING
      TIMEOUT                   
= w_timeout
   
EXCEPTIONS
      HTTP_COMMUNICATION_FAILURE
= 1
      HTTP_INVALID_STATE       
= 2
      HTTP_PROCESSING_FAILED   
= 3
      HTTP_INVALID_TIMEOUT     
= 4
     
others                    = 5.

  IF SYSUBRC <> 0.
   
call method w_pclient->get_last_error
     
IMPORTING
       
code    = w_subrc
       
message = w_errortext.

    w_rc = w_subrc.
   
write w_subrc to w_wsubrc.
   
concatenate
   
‘Communication error while posting data to HTTP adapter. Return code = ‘ w_wsubrc
     
‘message: ‘ w_errortext
     
into w_message separated by space.
   
write:/ w_message color col_negative.
   
exit.
 
else.

    COMMIT WORK AND WAIT.

    w_message = ‘Data successfully posted to HTTP adapter’.
   
write:/ w_message.
 
ENDIF.
* close connection
 
call method w_pclient->close
   
EXCEPTIONS
      http_invalid_state
= 1
     
others            = 2.
ENDFORM.                    ” send_data_to_http

Integration Repository (IR):

Sender DT: create the DT as per the CSV file

/wp-content/uploads/2014/09/fo3_546031.png

Create the MT and assign the DT type to message type

/wp-content/uploads/2014/09/fo4_546038.png

Create the SI and assign the MT type to Service interface

/wp-content/uploads/2014/09/fo5_546039.png

Create the Target DT, MT and SI

Note: If you need to convert from CSV to XML in the mapping than create the JAVA mapping.

Create the Mapping:

/wp-content/uploads/2014/09/fo6_546042.png

Create the OM

/wp-content/uploads/2014/09/fo7_546043.png

Save and active the IR

ID :

Go to ID part and create the Scenario name and create the Receiver Agreement, Receiver Determination and Interface Determination and receiver channel

Note: no need to create the sender CC ( communication channel and sender agreement ) data is comming directly in to SXMB_MONI inbound messages.

Receiver Agreement: Create this corresponding to Receiver Business service and inbound interface combination and specify communication channel.

Receiver Determination: Configure Receivers for corresponding Sender Service and Outbound Interface combination.

Interface Determination: Specify corresponding Inbound Interface and Interface Mapping for combination of Sender Service and Outbound Interface w.r.t specified Receiver in Receiver Determination.

Go to change list and activate all the ID objects. Integration Directory part is completed

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Peter Jonker

    Can you explain why you want to do this ? Why you do not use the HTTP or SOAP adapter ?

    And how do you trigger the message flow ? Does the program need to be scheduled ?

    I personally am not convinced that there is a valid use case to do this (yet).

    So please try to convince me  🙂

    (0) 
    1. srinu peram Post author

      Exchange rate files are placing in the web page and client in not hitting manually and they caon’t configured the web service, we need to pick the date dircetly from web page, it it is the XML file we need to use SOAP-axis adapter, for CSV files SOAP- axis adapter is not support

      (0) 

Leave a Reply