Skip to Content

This blog only provides instructions on how to start/stop a communication channel using an ABAP program. All other steps to have a fully functional communication channel are not provided in this blog, go to http://wiki.sdn.sap.com/wiki/display/XI/Step-by-Step+Guides or do a search on SDN to get a guideline on that.

Scenario:-

  1. There is a scheduled job running daily/weekly that creates an outbound file in SAP ECC
  2. There is a communication channel in SAP PI scheduled to pick up the file created and send it to an external system

By following the instructions below, the report can then be included as a step in a job scheduled in SAP ECC and therefore the communication channel scheduling in PI will not be required.

 External Control Off

In the communication channel monitoring, select the relevant commnunication channel and click on External Control Switch to allow the communication channel to be started/stopped externally. When it’s turned on, it should look as below.

External Control On

Goto SE38 to create a report and paste the code below.

report  YTEST_PRGM line-size 1023 message-id Z002.
data: V_URL type STRING,
      CLIENT type ref to IF_HTTP_CLIENT.
data: RESPONSE_CODE type  SYSUBRC,
      RESPONSE_TEXT type  STRING.

data: FIELDS_TAB type TIHTTPNVP,
      STATUS_CODE type STRING,
      STATUS_REASON type STRING,
      NUMBER type I.

data: W_RESULT type STRING,
      RESULT_TAB type table of STRING,
      RESULT_WA like line of RESULT_TAB.

“Get comm channel status
V_URL = ‘/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=Test_CommChannel_ExtCtrl&action=status’. 

“Start comm channel
“v_url = ‘/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=Test_CommChannel_ExtCtrl&action=start’.  

“Stop comm channel
“v_url = ‘/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=Test_CommChannel_ExtCtrl&action=stop’.  

call method CL_HTTP_CLIENT=>CREATE
  exporting
    HOST               = HOST         “PI system name
    SERVICE            = SERVICE      “Port number
*      PROXY_HOST         =
*      PROXY_SERVICE      =
*      SCHEME             = SCHEMETYPE_HTTP
*      SSL_ID             =
*      SAP_USERNAME       =
*      SAP_CLIENT         =
  importing
    CLIENT             = CLIENT
  exceptions
    ARGUMENT_NOT_FOUND = 1
    PLUGIN_NOT_ACTIVE  = 2
    INTERNAL_ERROR     = 3
    others             = 4.

if SY-SUBRC <> 0.
  message E000 with SY-SUBRC.
endif.

*set header fields
call method CLIENT->REQUEST->SET_HEADER_FIELD
  exporting
    NAME  = ‘~request_method’
    VALUE = ‘POST’.

call method CLIENT->REQUEST->SET_HEADER_FIELD
  exporting
    NAME  = ‘Content-Type’
    VALUE = ‘application/xml’. “; charset=UTF-8′ .

*Set request protocol
call method CLIENT->REQUEST->SET_HEADER_FIELD
  exporting
    NAME  = ‘~server_protocol’
    VALUE = ‘HTTP/1.0’.

*Update url
call method CLIENT->REQUEST->SET_HEADER_FIELD
  exporting
    NAME  = ‘~request_uri’
    VALUE = V_URL.

*Disable logon popup
CLIENT->PROPERTYTYPE_LOGON_POPUP = CLIENT->CO_DISABLED.
call method CLIENT->AUTHENTICATE
   exporting
      USERNAME             = USERNAME        “Username
      PASSWORD             = PASSWORD        “Password

CL_HTTP_UTILITY=>SET_REQUEST_URI( REQUEST = CLIENT->REQUEST
                                  URI = RESPONSE_TEXT ).
*Send http request to server
call method CLIENT->SEND
  exceptions
    HTTP_COMMUNICATION_FAILURE = 1
    HTTP_INVALID_STATE         = 2
    HTTP_PROCESSING_FAILED     = 3
    others                     = 4.
if SY-SUBRC <> 0.
  call method CLIENT->GET_LAST_ERROR
    importing
      CODE    = RESPONSE_CODE
      message = RESPONSE_TEXT.

  message I000(SR) with RESPONSE_TEXT.
  exit.
endif.

*Get http response from server
call method CLIENT->RECEIVE
  exceptions
    HTTP_COMMUNICATION_FAILURE = 1
    HTTP_INVALID_STATE         = 2
    HTTP_PROCESSING_FAILED     = 3
    others                     = 4.
if SY-SUBRC <> 0.
  call method CLIENT->GET_LAST_ERROR
    importing
      CODE    = RESPONSE_CODE
      message = RESPONSE_TEXT.

  STATUS_CODE = CLIENT->RESPONSE->GET_HEADER_FIELD( ‘~status_code’ ).
  STATUS_REASON = CLIENT->RESPONSE->GET_HEADER_FIELD( ‘~status_reason’ ).
  concatenate RESPONSE_TEXT ‘(‘ STATUS_CODE STATUS_REASON ‘)’ 

  into STATUS_REASON separated by SPACE.
  message I000(SR) with STATUS_REASON.
  exit.
endif.

*Get header_fields contents such status code, reason etc
“call method client->response->GET_HEADER_FIELDS
”   changing
”     FIELDS             =  Fields_Tab  .

clear: W_RESULT.
W_RESULT = CLIENT->RESPONSE->GET_CDATA( ).

refresh RESULT_TAB.
split W_RESULT at CL_ABAP_CHAR_UTILITIES=>NEWLINE into table RESULT_TAB.
loop at RESULT_TAB into RESULT_WA.
  write / RESULT_WA.
endloop.

The following variables must be assigned with proper valueds:-

Host-PI system name

Service-PI system port number

Username-This must be a user in PI system with the following roles: xi_af_channel_admin_display and xi_af_channel_admin_modify

Password-PI user’s password

“Starting the communication channel
v_url = ‘/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=Test_CommChannel_ExtCtrl&action=start’.

 

“Stopping communication channel
v_url = ‘/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=Test_CommChannel_ExtCtrl&action=stop’. 

 

“Get communication channel status
v_url = ‘/AdapterFramework/ChannelAdminServlet?party=*&service=*&channel=Test_CommChannel_ExtCtrl&action=status’. 

URL Parameters  

http(s)://host:port/AdapterFramework/ChannelAdminServlet?party=party&service=service&channel=channel&action=action

party– Identifies the party of the channel to be administered. You can use an asterisk (*) as a placeholder to administer several channels simultaneously

service– Identifies the communication component of the channel to be administered. You can use an asterisk (*) as a placeholder to administer several channels simultaneously

channel– Identifies the name of the channel to be administered. You can use an asterisk (*) as a placeholder to administer several channels simultaneously.                                                                                                                     

Action– You use the start and stop actions to start and stop the channels. You can use the status action to query the status of one or more channels.

To report this post you need to login first.

6 Comments

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

    1. Sebastian Simon
      Hi Daniel,

      Yes indeed its quite easy, my customer uses it to monitor critical channels with Nagios (simple Http Request) and throws alerts (sms/mail) from it to a support team.

      Best wishes
             Sebastian

      (0) 
  1. Rajesh pasupula
    Hi,

    I know that the Channels can be controlled using http url..but never thought can be called using ABAP stack/reports..Helpful info.

    Regards
    Rajesh

    (0) 

Leave a Reply