SAP ABAP GET HTTP POST method xml tcbm kur çekme

Paylaş.

SAP abap native http fonksiyonları ile SAP ABAP GET HTTP POST method xml tcbm kur çekmek.

SAP Fiori







REPORT  zhttp_get_post.
 
DATA: lv_xml TYPE STRING,
      lv_url TYPE STRING.
 
DATA: lv_client TYPE REF TO if_http_client.
 
lv_url = 'http://www.tcmb.gov.tr/kurlar/today.xml'.


CALL METHOD cl_http_client=>create_by_url
  EXPORTING
    url                = lv_url
  IMPORTING
    CLIENT             = lv_client
  EXCEPTIONS
    argument_not_found = 1
    plugin_not_active  = 2
    internal_error     = 3
    OTHERS             = 4.
IF sy-subrc NE 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
 
lv_client->request->set_header_field( NAME  = '~request_method'
                                        VALUE = 'GET' ).
 

CALL METHOD lv_client->send
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3
    OTHERS                     = 4.
IF sy-subrc NE 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
 

CALL METHOD lv_client->receive
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3
    OTHERS                     = 4.
 

lv_xml = lv_client->response->get_cdata( ).
 
break serkanozc.
DATA: l_ixml            TYPE REF TO if_ixml,
      l_streamfactory   TYPE REF TO if_ixml_stream_factory,
      l_istream         TYPE REF TO if_ixml_istream,
      l_parser          TYPE REF TO if_ixml_parser,
      l_document        TYPE REF TO if_ixml_document,
      lv_xml_x          TYPE XSTRING.
 
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
  EXPORTING
    text           = lv_xml
*   MIMETYPE       = ' '
*   ENCODING       =
 IMPORTING
   buffer         = lv_xml_x
 EXCEPTIONS
   failed         = 1
   OTHERS         = 2
          .
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
 
 

l_ixml = cl_ixml=>create( ).
 

l_streamfactory = l_ixml->create_stream_factory( ).
 

l_istream = l_streamfactory->create_istream_xstring( STRING = lv_xml_x ).
 

l_document = l_ixml->create_document( ).
 
 

l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
                                  istream        = l_istream
                                  document       = l_document ).
 

IF l_parser->parse( ) NE 0.
  MESSAGE 'today.xml parse problemi' TYPE 'E'.
  EXIT.
ENDIF.
 
DATA: curr_node_collection  TYPE REF TO if_ixml_node_collection,
      curr_node_iterator    TYPE REF TO if_ixml_node_iterator,
      curr_node             TYPE REF TO if_ixml_node,
      curr_nodemap          TYPE REF TO if_ixml_named_node_map,
      curr_attr             TYPE REF TO if_ixml_node,
      curr_node_list        TYPE REF TO if_ixml_node_list,
      lv_val                TYPE STRING,
      lv_length             TYPE i,
      lv_indx               TYPE i.
 
curr_node_collection = l_document->get_elements_by_tag_name( NAME = 'Currency' ).
curr_node_iterator = curr_node_collection->create_iterator( ).
curr_node = curr_node_iterator->get_next( ).
 
WHILE curr_node IS NOT INITIAL.
 
  curr_nodemap = curr_node->get_attributes( ).
  curr_attr = curr_nodemap->get_named_item( NAME = 'CurrencyCode' ).
 
  CLEAR lv_val.
  IF curr_attr IS NOT INITIAL.
    lv_val = curr_attr->get_value( ).
    WRITE 'CurrencyCode' COLOR COL_GROUP.
    WRITE: lv_val.
  ENDIF.
 
  curr_node_list = curr_node->get_children( ).
  CLEAR lv_length.
  lv_length = curr_node_list->get_length( ).
  DO lv_length TIMES.
    lv_indx = sy-INDEX - 1.
    curr_attr = curr_node_list->get_item( lv_indx ).
 
    CLEAR lv_val.
    IF curr_attr IS NOT INITIAL.
      lv_val = curr_attr->get_name( ).
      WRITE: lv_val COLOR COL_GROUP.
      lv_val = curr_attr->get_value( ).
      WRITE: lv_val.
    ENDIF.
 
  ENDDO.
 
  curr_node = curr_node_iterator->get_next( ).
 
 break-point.
  WRITE: /.
ENDWHILE.
VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
SAP ABAP GET HTTP POST method xml tcbm kur çekme, 10.0 out of 10 based on 1 rating