Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

code to call url in abap program

Former Member
0 Likes
1,955

code to call url in abap program using cl_http requests and save the outcome to a location in a file

5 REPLIES 5
Read only

Former Member
0 Likes
968

See the below program

REPORT zbrowser .

TABLES : sscrfields.

INCLUDE .

CONSTANTS: htmlcntl_eventid_on_navigate TYPE i VALUE 1.

CONSTANTS: htmlcntl_eventid_navigate_com TYPE i VALUE 2.

DATA : h_html_ctrl TYPE cntl_handle,

repid TYPE sy-repid,

dynnr TYPE sy-dynnr,

cmd TYPE sy-ucomm,

flag,disp.

DATA : it_exclude LIKE TABLE OF rsexfcode WITH HEADER LINE.

SELECTION-SCREEN : FUNCTION KEY 1,

FUNCTION KEY 2,

FUNCTION KEY 3,

FUNCTION KEY 4,

FUNCTION KEY 5.

General Browser to View

Files/Pictures & WebPages

© 2005 SAP AG 2

SELECTION-SCREEN COMMENT 45(50) comment1.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 2(28) comment2 FOR FIELD url.

SELECTION-SCREEN POSITION 31.

PARAMETERS : url(1064) LOWER CASE .

SELECTION-SCREEN PUSHBUTTON 79(4) open USER-COMMAND open.

SELECTION-SCREEN END OF LINE.

INITIALIZATION.

comment1 = 'ABAP INTERNET EXPLORER'.

comment2 = 'Enter URL/Filename To Open :'.

open = icon_transfer .

sscrfields-functxt_05 = icon_sap.

sscrfields-functxt_04 = icon_booking_stop.

sscrfields-functxt_03 = icon_refresh.

sscrfields-functxt_02 = icon_arrow_right.

sscrfields-functxt_01 = icon_arrow_left.

repid = sy-repid.

dynnr = '1000'.

it_exclude-fcode = 'ONLI'.

APPEND it_exclude.

it_exclude-fcode = 'INFO'.

APPEND it_exclude.

*Changing GUI status

CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'

EXPORTING

p_status = sy-pfkey

  • p_program = repid

TABLES

p_exclude = it_exclude.

CALL FUNCTION 'CONTROL_INIT' .

IF sy-subrc <> 0.

EXIT.

ENDIF.

CALL FUNCTION 'HTMLCNTL_CREATE'

EXPORTING

owner_repid = repid

link_repid = repid

dynnr = dynnr

handle = h_html_ctrl

EXCEPTIONS

control_install_error = 1

create_error = 2

General Browser to View

Files/Pictures & WebPages

© 2005 SAP AG 3

OTHERS = 3

.

IF sy-subrc <> 0.

EXIT.

ENDIF.

CALL FUNCTION 'HTMLCNTL_INIT'

EXPORTING

h_control = h_html_ctrl

left = 1

top = 2

width = 143

height = 37

register_event_on_navigate = 'X'

cb_form_navigate_complete = 'ON_CONTROL_EVENT'

EXCEPTIONS

cntl_system_error = 1

cntl_error = 2

dp_create_error = 3

dp_install_error = 4

dp_error = 5

create_browser_error = 6

init_error = 7

OTHERS = 8

.

IF sy-subrc <> 0.

EXIT.

ENDIF.

CALL FUNCTION 'CONTROL_FLUSH'.

AT SELECTION-SCREEN.

cmd = sscrfields-ucomm.

CASE cmd.

WHEN 'OPEN'.

PERFORM load_html_page.

CALL FUNCTION 'CONTROL_FLUSH'.

WHEN 'FC01'. "BACK

CALL FUNCTION 'HTMLCNTL_GO_BACK'

EXPORTING

h_control = h_html_ctrl.

IF sy-subrc <> 0.

EXIT.

ENDIF.

General Browser to View

Files/Pictures & WebPages

© 2005 SAP AG 4

PERFORM get_current_url.

WHEN 'FC02'. "FORWARD

CALL FUNCTION 'HTMLCNTL_GO_FORWARD'

EXPORTING

h_control = h_html_ctrl.

IF sy-subrc <> 0.

EXIT.

ENDIF.

PERFORM get_current_url.

WHEN 'FC03'. "REFRESH

CALL FUNCTION 'HTMLCNTL_DO_REFRESH'

EXPORTING

h_control = h_html_ctrl.

IF sy-subrc <> 0.

EXIT.

ENDIF.

PERFORM get_current_url.

WHEN 'FC04'. "STOP

CALL FUNCTION 'HTMLCNTL_STOP'

EXPORTING

h_control = h_html_ctrl.

IF sy-subrc <> 0.

EXIT.

ENDIF.

WHEN 'FC05'. "GO TO HOME

CALL FUNCTION 'HTMLCNTL_GO_HOME'

EXPORTING

h_control = h_html_ctrl.

IF sy-subrc <> 0.

EXIT.

ENDIF.

PERFORM get_current_url.

CALL FUNCTION 'CONTROL_FLUSH'.

WHEN OTHERS.

General Browser to View

Files/Pictures & WebPages

© 2005 SAP AG 5

CALL FUNCTION 'CONTROL_DISPATCH'

EXPORTING

fcode = cmd.

CALL FUNCTION 'CONTROL_FLUSH'.

ENDCASE.

CLEAR cmd.

CALL FUNCTION 'CONTROL_FLUSH'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR url.

PERFORM get_file_name.

PERFORM load_html_page.

*&----

-


*& Form get_page_name

*&----

-


  • Get Page Name

*----

-


FORM get_file_name.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

  • DEF_FILENAME = ' '

def_path = 'C: '

mask = ',.,..'

mode = 'o'

title = 'Browse to Open'

IMPORTING

filename = url

  • RC =

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5

.

IF sy-subrc <> 0.

EXIT.

ENDIF.

ENDFORM. " get_page_name

*&----

-


*& Form load_html_page

*&----

-


  • TO load the file (URL)

General Browser to View

Files/Pictures & WebPages

© 2005 SAP AG 6

*----

-


FORM load_html_page.

CALL FUNCTION 'HTMLCNTL_SHOW_URL'

EXPORTING

h_control = h_html_ctrl

url = url.

IF sy-subrc <> 0.

EXIT.

ENDIF.

flag = 'X'.

ENDFORM. " load_html_page

*&----


*

*& Form get_current_url

*&----


*

  • Get Current URL

*----


*

FORM get_current_url.

CALL FUNCTION 'HTMLCNTL_GET_CURRENT_URL'

EXPORTING

h_control = h_html_ctrl

IMPORTING

url = url.

ENDFORM. " get_current_url

  • Callback form for the event 'NavigateComplete'

callback on_control_event.

CALL FUNCTION 'CONTROL_GET_EVENT_PARAM'

EXPORTING

h_control = h_html_ctrl

param_id = 0

CHANGING

return = url.

PERFORM get_current_url.

endcallback.

Reward Points if it is helpful

Thanks

Seshu

Read only

0 Likes
968

hi EXPERT, thanks for code, is very helpfull.

I have a question for you, if i dont want display data in the screen, but using URL comand line to run instruction on another web server and mange the data in back ground or totaly in SAP via ABAP code.

Thanks

Read only

0 Likes
968

Simply use the CALL_BROWSER function module in your ABAP Program. or

call method cl_gui_frontend_services=>execute
  exporting
    document = 'https://www.sdn.sap.com'
  exceptions
    others   = 1.

~Suresh

Read only

Former Member
0 Likes
968

Hi,

Try with this program:

REPORT ZURL NO STANDARD PAGE HEADING.

DATA: BEGIN OF URL_TABLE OCCURS 10,

L(25),

END OF URL_TABLE.

URL_TABLE-L = 'http://www.lycos.com'.APPEND URL_TABLE.

URL_TABLE-L = 'http://www.hotbot.com'.APPEND URL_TABLE.

URL_TABLE-L = 'http://www.sap.com'.APPEND URL_TABLE.

LOOP AT URL_TABLE.

SKIP. FORMAT INTENSIFIED OFF.

WRITE: / 'Single click on '.

FORMAT HOTSPOT ON.FORMAT INTENSIFIED ON.

WRITE: URL_TABLE. HIDE URL_TABLE.

FORMAT HOTSPOT OFF.FORMAT INTENSIFIED OFF.

WRITE: 'to go to', URL_TABLE.

ENDLOOP.

CLEAR URL_TABLE.

AT LINE-SELECTION.

IF NOT URL_TABLE IS INITIAL.

CALL FUNCTION 'WS_EXECUTE'

EXPORTING

program = 'C:\Program Files\Internet Explorer\IEXPLORE.EXE'

commandline = URL_TABLE

INFORM = ''

EXCEPTIONS

PROG_NOT_FOUND = 1.

IF SY-SUBRC <> 0.

WRITE:/ 'Cannot find program to open Internet'.

ENDIF.

ENDIF.

Regards,

Bhaskar

Read only

0 Likes
968

Hi, i want to manage url command line in back ground without show in a browser, in ana abap module pool i would manage the possibility to run some command to a web server not in sap domain.

i apologize if my technical language is not the best.

Thanks a lot, simone