Search This Blog

Wednesday, August 3, 2011

Start/Stop a communication channel from an ABAP program using the external control switch

This blog only provides instructions on the way to start/stop a channel using an ABAP program. All other steps to possess a totally functional channel aren't provided during this blog, attend http://wiki.sdn.sap.com/wiki/display/XI/Step-by-Step+Guides or do an enquiry on SDN to urge a suggestion on that.

Scenario:-

 There is a scheduled job running daily/weekly that makes an outbound enter SAP ECC

 There is a channel in SAP PI scheduled to select 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 during a job scheduled in SAP ECC and thus the 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 make 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 should be assigned with proper values:-

Host-PI system name

Service-PI system port number

Username-This must be a user in PI system with the subsequent 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- Recognize the party of the channel to be organized. You can use an asterisk (*) as a placeholder to administer various channels simultaneously

service- Recognizes the communication component of the channel to be administered. You can use an asterisk (*) as a placeholder to administer various channels concurrently

channel- Recognizes the name of the channel to be administered. You can use an asterisk (*) as a placeholder to administer various channels concurrently. 

Action- you utilize the beginning and stop actions to start out and stop the channels. You can use the status action to query the status of 1 or more channels.

No comments:

Post a Comment