Skip to Content
0
Former Member
May 03, 2016 at 08:03 AM

How to resolve this ICM_HTTP_CONNECTION_FAILED?

129 Views

Hi Experts,

I am new to ICF framework.

I need to captured all the data information from WEB site( http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml ).

for this i have written in ABAP program(SE38) using IF_HTTP_CLENT.

1. CLIENT->SEND request sending is fine. but problem in receiving, i got this error ICM_HTTP_CONNECTION_FAILED.

2. if i missed any technical settings please let me know.

i have written below code.

please check and let me know.

*&---------------------------------------------------------------------*

*& Report YSAT_WEBSERVICE

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT YSAT_WEBSERVICE.

TYPE-POOLS: abap,ixml .

CLASS cl_ixml DEFINITION LOAD.

CONSTANTS: c_url TYPE string VALUE 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml' .

*----------------------------------------------------------------------*

*----------------------------------------------------------------------*

TYPES: BEGIN OF tp_alv_data_1 .

TYPES: time TYPE datum_curc ,

currency TYPE waers_curc ,

rate TYPE p DECIMALS 5 .

TYPES: END OF tp_alv_data_1 .

*

TYPES: tp_alv_data_1_tab TYPE STANDARD TABLE OF tp_alv_data_1 .

*----------------------------------------------------------------------*

*----------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK block04 WITH FRAME .

PARAMETERS: p_url TYPE alk_string NO-DISPLAY .

SELECTION-SCREEN COMMENT /1(79) h_url ..

SELECTION-SCREEN SKIP .

PARAMETERS: p_host TYPE alk_string .

PARAMETERS: p_port TYPE alk_string .

SELECTION-SCREEN SKIP .

PARAMETERS: p_debug TYPE debug_flg .

SELECTION-SCREEN END OF BLOCK block04 .

*----------------------------------------------------------------------*

INITIALIZATION.

PERFORM at_initialization .

AT SELECTION-SCREEN .

PERFORM at_selection_screen_input .

START-OF-SELECTION .

PERFORM at_start_of_selection .

*----------------------------------------------------------------------*

FORM at_initialization .

p_url = c_url .

h_url = c_url .

DATA: it_seltexts TYPE TABLE OF rsseltexts .

DATA: st_seltexts LIKE LINE OF it_seltexts .

st_seltexts-name = 'P_URL' .

st_seltexts-kind = 'P' .

st_seltexts-text = 'URL' .

APPEND st_seltexts TO it_seltexts .

st_seltexts-name = 'P_HOST' .

st_seltexts-kind = 'P' .

st_seltexts-text = 'Proxy host' .

APPEND st_seltexts TO it_seltexts .

st_seltexts-name = 'P_PORT' .

st_seltexts-kind = 'P' .

st_seltexts-text = 'Proxy port' .

APPEND st_seltexts TO it_seltexts .

CALL FUNCTION 'SELECTION_TEXTS_MODIFY'

EXPORTING

program = sy-cprog

TABLES

seltexts = it_seltexts

EXCEPTIONS

program_not_found = 1

program_cannot_be_generated = 2

OTHERS = 3.

ENDFORM . "at_initialization

*----------------------------------------------------------------------*

FORM at_selection_screen_input .

p_url = c_url .

ENDFORM . "at_selection_screen_input

*----------------------------------------------------------------------*

FORM at_start_of_selection .

DATA: response_string TYPE xstring .

PERFORM do_xml_fetch_1

CHANGING

response_string .

DATA: it_alv_data_1 TYPE tp_alv_data_1_tab .

PERFORM do_xml_parse_1

USING

response_string

CHANGING

it_alv_data_1 .

PERFORM display_salv_table

CHANGING

it_alv_data_1 .

ENDFORM . "at_start_of_selection

*----------------------------------------------------------------------*

FORM do_xml_fetch_1

CHANGING

response_string_2 TYPE xstring .

DATA: client TYPE REF TO if_http_client .

TRANSLATE p_url TO LOWER CASE .

TRANSLATE p_host TO LOWER CASE .

TRANSLATE p_port TO LOWER CASE .

CALL METHOD cl_http_client=>create_by_url

EXPORTING

url = p_url

proxy_host = p_host

proxy_service = p_port

IMPORTING

client = client

EXCEPTIONS

argument_not_found = 1

plugin_not_active = 2

internal_error = 3

OTHERS = 4.

CHECK sy-subrc EQ 0 .

CALL METHOD client->send

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2.

CHECK sy-subrc EQ 0 .

CALL METHOD client->receive

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3.

CHECK sy-subrc EQ 0 .

DATA: response_string_1 TYPE string .

response_string_1 = client->response->get_cdata( ).

TRY.

CALL METHOD cl_bcs_convert=>string_to_xstring

EXPORTING

iv_string = response_string_1

RECEIVING

ev_xstring = response_string_2.

CATCH cx_bcs .

ENDTRY.

ENDFORM . "do_xml_fetch_1

*----------------------------------------------------------------------*

FORM do_xml_parse_1

USING

xml_string TYPE xstring

CHANGING

it_alv_data_1 TYPE tp_alv_data_1_tab .

IF xml_string IS INITIAL .

RETURN .

ENDIF .

DATA: ob_ixml TYPE REF TO if_ixml.

ob_ixml = cl_ixml=>create( ).

DATA: streamfactory TYPE REF TO if_ixml_stream_factory.

streamfactory = ob_ixml->create_stream_factory( ).

DATA: istream TYPE REF TO if_ixml_istream.

istream = streamfactory->create_istream_xstring( string = xml_string ).

DATA: document TYPE REF TO if_ixml_document.

document = ob_ixml->create_document( ) .

DATA: parser TYPE REF TO if_ixml_parser.

parser = ob_ixml->create_parser( stream_factory = streamfactory

istream = istream

document = document ).

parser->parse( ).

DATA: length TYPE i .

DATA: index TYPE i .

DATA: nodes TYPE REF TO if_ixml_node_collection.

DATA: node TYPE REF TO if_ixml_node .

nodes = document->get_elements_by_tag_name( name = 'Cube' ).

length = nodes->get_length( ) .

WHILE index LT length .

node = nodes->get_item( index ).

* Parse a node .

PERFORM do_xml_parse_2

USING

node

CHANGING

it_alv_data_1 .

index = index + 1.

ENDWHILE.

ENDFORM . "do_xml_parse_1

*----------------------------------------------------------------------*

FORM do_xml_parse_2

USING

node_i TYPE REF TO if_ixml_node

CHANGING

it_alv_data_1 TYPE tp_alv_data_1_tab .

STATICS: st_alv_data_1 LIKE LINE OF it_alv_data_1 .

DATA: attributes TYPE REF TO if_ixml_named_node_map .

DATA: attribute TYPE REF TO if_ixml_attribute .

attributes = node_i->get_attributes( ) .

CHECK attributes IS NOT INITIAL.

DATA: node TYPE REF TO if_ixml_node .

DATA: index TYPE i .

DATA: length TYPE i .

DATA: name TYPE string .

DATA: value TYPE string .

FIELD-SYMBOLS: <value> TYPE ANY .

length = attributes->get_length( ) .

WHILE index LT length .

node = attributes->get_item( index ) .

attribute ?= node->query_interface( ixml_iid_attribute ) .

name = attribute->get_name( ) .

value = attribute->get_value( ) .

IF p_debug EQ abap_true .

WRITE: / , name , ' = ' , value .

ENDIF .

TRANSLATE name TO UPPER CASE .

ASSIGN COMPONENT name OF STRUCTURE st_alv_data_1 TO <value> .

* If the fields name are the same we can use this approach

IF sy-subrc EQ 0 .

CASE name .

WHEN 'TIME' .

REPLACE ALL OCCURRENCES OF '-' IN value WITH ''.

ENDCASE .

<value> = value .

ENDIF .

* Explicit mapping of fields

* CASE name .

* WHEN 'CURRENCY' .

* st_alv_data_1-currency = value .

* WHEN 'RATE' .

* st_alv_data_1-rate = value .

* WHEN 'TIME' .

* st_alv_data_1-time = value .

* ENDCASE .

index = index + 1.

ENDWHILE .

* Time to add a line ?

IF st_alv_data_1-currency IS NOT INITIAL AND

st_alv_data_1-rate IS NOT INITIAL .

APPEND st_alv_data_1 TO it_alv_data_1 .

CLEAR: st_alv_data_1-currency,st_alv_data_1-rate .

ENDIF .

ENDFORM . "do_xml_parse_2

*----------------------------------------------------------------------*

FORM display_salv_table

CHANGING

it_table TYPE table .

DATA: ob_salv_table TYPE REF TO cl_salv_table .

TRY.

cl_salv_table=>factory( IMPORTING r_salv_table = ob_salv_table

CHANGING t_table = it_table ) .

CATCH cx_salv_msg .

ENDTRY.

DATA: ob_salv_columns TYPE REF TO cl_salv_columns_table .

ob_salv_columns = ob_salv_table->get_columns( ) .

DATA: it_column_ref TYPE salv_t_column_ref .

FIELD-SYMBOLS: <st_column_ref> LIKE LINE OF it_column_ref .

it_column_ref = ob_salv_columns->get( ) .

DATA: st_dd04v TYPE dd04v .

LOOP AT it_column_ref ASSIGNING <st_column_ref> .

* Get some headings...

IF <st_column_ref>-columnname EQ 'RATE' .

CALL FUNCTION 'DDIF_DTEL_GET'

EXPORTING

name = 'UKURS_CURR'

langu = 'E'

IMPORTING

dd04v_wa = st_dd04v

EXCEPTIONS

illegal_input = 1

OTHERS = 2.

<st_column_ref>-r_column->set_short_text( value = st_dd04v-scrtext_s ) .

<st_column_ref>-r_column->set_medium_text( value = st_dd04v-scrtext_m ) .

<st_column_ref>-r_column->set_long_text( value = st_dd04v-scrtext_l ) .

ENDIF .

ENDLOOP .

ob_salv_table->display( ) .

ENDFORM . "display_alv


Regards

Shankar B