Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

How to Easy... Load an HTML Page into Internal Table

$
0
0

here is a simple code to load an HTML page into a internal table:

 

" Local Vars

DATA: lo_client  TYPE REF TO if_http_client,

       lc_url     TYPE string,

       lc_content TYPE string,

       lt_html    TYPE TABLE OF string.

 

" Set html page to load

lc_url = 'http://www.sap.com'.

 

" Create the HTTP client

CALL METHOD cl_http_client=>create_by_url

   EXPORTING

     url    = lc_url

   IMPORTING

     client = lo_client

   EXCEPTIONS

     OTHERS = 1.

IF sy-subrc IS NOT INITIAL.

   " Error

   EXIT.

ENDIF.

 

" Set the Request type to GET

lo_client->request->set_header_field( name  = '~request_method'

                                       value = 'GET' ).

" Make the call

lo_client->send( ).

 

" Receive the Response Object

CALL METHOD lo_client->receive

   EXCEPTIONS

     http_communication_failure = 1

     http_invalid_state         = 2

     http_processing_failed     = 3

     OTHERS                     = 4.

IF sy-subrc IS NOT INITIAL.

   " Error

   EXIT.

ENDIF.

 

" Get the response content in Character format

lc_content = lo_client->response->get_cdata( ).

 

" Split content by lines in an internal table

SPLIT lc_content AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_html.

 

" From here you can parse you html code from table lt_html

 

It´s done.


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>