Friday, February 29, 2008

Calling a Browser from ABAP

Calling a Browser from ABAP
The following function modules can be used to call a browse from ABAP.
  • WS_EXECUTE
  • cl_gui_frontend_services=>execute
  • CALL_BROWSER

Please see the cod below.

REPORT ZBROWSER1 .
DATA: BEGIN OF URL_TABLE OCCURS 10,
d(50),
END OF URL_TABLE.
data: d_url1(100),
d_url2(100).
move: 'http://www.sap.com' to d_url1,
'http://abaplovers.blogspot.com' to d_url2.
URL_TABLE-d = 'http://www.abaplovers.blogspot.com'.
APPEND URL_TABLE.
URL_TABLE-d = d_url1.
APPEND URL_TABLE.
URL_TABLE-d = d_url2.
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.


REPORT ZBROWSER .
call method cl_gui_frontend_services=>execute
exporting
document = 'http://www.sap.com'
exceptions
others = 1.


REPORT ZBROWSER2 .
CALL FUNCTION 'CALL_BROWSER'
EXPORTING
URL = 'http://www.abaplovers.blogspot.com'
WINDOW_NAME = 'New '
NEW_WINDOW = 'X'
* BROWSER_TYPE =
* CONTEXTSTRING =
* EXCEPTIONS
* FRONTEND_NOT_SUPPORTED = 1
* FRONTEND_ERROR = 2
* PROG_NOT_FOUND = 3
* NO_BATCH = 4
* UNSPECIFIED_ERROR = 5
* OTHERS = 6
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.