Skip to Content

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 sysubrc 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 sysubrc 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.

To report this post you need to login first.

1 Comment

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

  1. Jerry Baker

    This was a great help, but I did find that the webpage I was trying to download required one small change. I had to replace ‘cr_lf’ with ‘newline’.

    “Split content by lines in an internal table

    SPLIT lc_content AT cl_abap_char_utilities=>newline INTO TABLE lt_html.

    (0) 

Leave a Reply