Thursday, December 14, 2006

HTML control used as a web browser

This is an interesting piece of development. This uses the HTML control to create a web browser. I've used the HTML related function modules in this example shown below. In order for this example to work, you need to create a WWW document Id and then call it in your main program. In this example, I've created a document id ZSIVA_BLOG.

1. Go to transaction SMW0
2. click on the HTML template for WebRFC applications and execute
3. Create new entries and enter the attributes
4. The entry will be created as below:
5. Then click on the detail function and assign the basic HTML page that needs to be loaded when your HTML control loads:
6. Instead you can use the import/export parameters as well from the menu.

7. Then click on the glasses (to display), you can see the base page in a browser.

To enable the web browser, copy the following code into a new executable program:
*&---------------------------------------------------------------------*
*& Report ZNUT_WEB_BROWSER_NEW *
*&---------------------------------------------------------------------*
* Sample program to demonstrate the HTML Control be used as a WEB BROWSER
* Siva Thiagarajan

REPORT ZNUT_WEB_BROWSER_NEW.

INCLUDE .
INCLUDE CNHTINCL.

DATA: H_HTML_CONTROL TYPE CNTL_HANDLE.
DATA: B_INIT TYPE C.
DATA: PROG_REPID LIKE SY-REPID.
DATA: FCODE LIKE SY-UCOMM.
DATA: URL(1024).

SET SCREEN 100.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'TESTHTM1'.
SET TITLEBAR '001'.

IF B_INIT IS INITIAL.
CALL FUNCTION 'CONTROL_INIT'.
PROG_REPID = SY-REPID.
CALL FUNCTION 'HTMLCNTL_CREATE'
EXPORTING
OWNER_REPID = PROG_REPID
LINK_REPID = PROG_REPID
DYNNR = '0100'
CONTAINER = 'HTML_CONTAINER'
CHANGING
HANDLE = H_HTML_CONTROL.

B_INIT = 'x'.
CALL FUNCTION 'HTMLCNTL_INIT'
EXPORTING
H_CONTROL = H_HTML_CONTROL
REGISTER_EVENT_ON_NAVIGATE = 'x'
CB_FORM_NAVIGATE_COMPLETE = 'ON_CONTROL_EVENT'.

PERFORM LOAD_HOME_PAGE.

CALL FUNCTION 'CONTROL_FLUSH'.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT

*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE FCODE.
WHEN 'BACK'.
IF NOT B_INIT IS INITIAL.
CALL FUNCTION 'HTMLCNTL_DESTROY'
CHANGING
H_CONTROL = H_HTML_CONTROL
EXCEPTIONS
OTHERS = 1.
CALL FUNCTION 'CONTROL_FLUSH'.
ENDIF.
LEAVE PROGRAM.

WHEN 'HHOM'. " show the home page
CALL FUNCTION 'HTMLCNTL_GO_HOME'
EXPORTING
H_CONTROL = H_HTML_CONTROL.
CALL FUNCTION 'HTMLCNTL_GET_CURRENT_URL'
EXPORTING
H_CONTROL = H_HTML_CONTROL
IMPORTING
URL = URL.

WHEN 'HBAK'.
CALL FUNCTION 'HTMLCNTL_GO_BACK'
EXPORTING
H_CONTROL = H_HTML_CONTROL.
CALL FUNCTION 'HTMLCNTL_GET_CURRENT_URL'
EXPORTING
H_CONTROL = H_HTML_CONTROL
IMPORTING
URL = URL.

WHEN 'HFWD'.
CALL FUNCTION 'HTMLCNTL_GO_FORWARD'
EXPORTING
H_CONTROL = H_HTML_CONTROL.
CALL FUNCTION 'HTMLCNTL_GET_CURRENT_URL'
EXPORTING
H_CONTROL = H_HTML_CONTROL
IMPORTING
URL = URL.

WHEN 'HRFR'.
CALL FUNCTION 'HTMLCNTL_DO_REFRESH'
EXPORTING
H_CONTROL = H_HTML_CONTROL.
CALL FUNCTION 'HTMLCNTL_GET_CURRENT_URL'
EXPORTING
H_CONTROL = H_HTML_CONTROL
IMPORTING
URL = URL.

WHEN 'HNAV'.
CALL FUNCTION 'HTMLCNTL_SHOW_URL'
EXPORTING
H_CONTROL = H_HTML_CONTROL
URL = URL.

WHEN OTHERS.
CALL FUNCTION 'CONTROL_DISPATCH'
EXPORTING
FCODE = FCODE.
ENDCASE.
CLEAR FCODE.
ENDMODULE. " USER_COMMAND_0100 INPUT

* Callback form for the event 'NavigateComplete'
callback on_control_event.
CALL FUNCTION 'CONTROL_GET_EVENT_PARAM'
EXPORTING
H_CONTROL = H_HTML_CONTROL
PARAM_ID = 0
CHANGING
RETURN = URL.

endcallback.

* Homepage form
FORM LOAD_HOME_PAGE.
DATA: DOC_URL(80).

CALL FUNCTION 'HTMLCNTL_LOAD_HTML_DOCUMENT'
EXPORTING
H_CONTROL = H_HTML_CONTROL
DOCUMENT_ID = 'ZSIVA_BLOG'
IMPORTING
ASSIGNED_URL = DOC_URL
EXCEPTIONS
OTHERS = 1.

IF SY-SUBRC EQ 0.
CALL FUNCTION 'HTMLCNTL_SHOW_DATA'
EXPORTING
H_CONTROL = H_HTML_CONTROL
URL = DOC_URL.
ENDIF.
ENDFORM. " LOAD_HOME_PAGE

Fine print:

1. Please create a pf-status TESTHTM1

2. Create a screen 100 like this:
3. The PBO and PAI modules are already handled in the main program.




3 comments:

Amina said...

I have 2 questions.
1. I tried creating the object in SMW0. when i click on the create button and put in the object name and descp, it only has an import button which leads to file open dialog box. What do i do there? Do i need to create some file for this in my C drive?
2. In attributes for zsiva_blg, you have entered the value 'C:\blog\default.html'. Where do you get this value from?
Thanks.

Unknown said...

Hello Shiva,

Nice blog :).

I have implemented some application using HTML control and I was wondering which web browser does SAP use for it. Is it IE or something else?
It would be great if you have any document which talks about it.

Thanks.

Unknown said...

Hi,The type of Web Design Cochin program can cut your time in half and keep your cost for each web page down to a minimum.thanks.........