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

change data in CL_GUI_HTML_VIEWER

Former Member
0 Likes
5,749

I want to change html data at runtime, without reloading the transaction.

data int the table ts_data is dynamic and it change based on use input.

below code display the data but not change based on user input. only the first display stay at transaction end.

Pl. help.

   CREATE OBJECT ref_cont

     EXPORTING

       container_name              = 'CONT'

     EXCEPTIONS

       cntl_error                  = 1

       cntl_system_error           = 2

       create_error                = 3

       lifetime_error              = 4

       lifetime_dynpro_dynpro_link = 5

       OTHERS                      = 6.

   IF sy-subrc <> 0.

   ENDIF.

   CREATE OBJECT ref_html

     EXPORTING

       parent             = ref_cont

     EXCEPTIONS

       cntl_error         = 1

       cntl_install_error = 2

       dp_install_error   = 3

       dp_error           = 4

       OTHERS             = 5.

   IF sy-subrc <> 0.

   ENDIF.

   CALL METHOD ref_html->load_data

     EXPORTING

       type                 = 'text'

       subtype              = 'html'

     IMPORTING

       assigned_url         = w_url

     CHANGING

       data_table           = ts_data

     EXCEPTIONS

       dp_invalid_parameter = 1

       dp_error_general     = 2

       cntl_error           = 3

       OTHERS               = 4.

   IF sy-subrc <> 0.

   ENDIF.

   CALL METHOD ref_html->show_url

     EXPORTING

       url                    = w_url

     EXCEPTIONS

       cntl_error             = 1

       cnht_error_not_allowed = 2

       cnht_error_parameter   = 3

       dp_error_general       = 4

       OTHERS                 = 5.

   IF sy-subrc <> 0.

   ENDIF.

   ref_html->set_ui_flag( ref_html->uiflag_no3dborder ).

I want to change html data at runtime, without reloading the transaction.

data int the table ts_data is dynamic and it change based on use input.

below code display the data but not change based on user input. only the first display stay at transaction end.

Pl. help.

   CREATE OBJECT ref_cont

     EXPORTING

       container_name              = 'CONT'

     EXCEPTIONS

       cntl_error                  = 1

       cntl_system_error           = 2

       create_error                = 3

       lifetime_error              = 4

       lifetime_dynpro_dynpro_link = 5

       OTHERS                      = 6.

   IF sy-subrc <> 0.

   ENDIF.

   CREATE OBJECT ref_html

     EXPORTING

       parent             = ref_cont

     EXCEPTIONS

       cntl_error         = 1

       cntl_install_error = 2

       dp_install_error   = 3

       dp_error           = 4

       OTHERS             = 5.

   IF sy-subrc <> 0.

   ENDIF.

   CALL METHOD ref_html->load_data

     EXPORTING

       type                 = 'text'

       subtype              = 'html'

     IMPORTING

       assigned_url         = w_url

     CHANGING

       data_table           = ts_data

     EXCEPTIONS

       dp_invalid_parameter = 1

       dp_error_general     = 2

       cntl_error           = 3

       OTHERS               = 4.

   IF sy-subrc <> 0.

   ENDIF.

   CALL METHOD ref_html->show_url

     EXPORTING

       url                    = w_url

     EXCEPTIONS

       cntl_error             = 1

       cnht_error_not_allowed = 2

       cnht_error_parameter   = 3

       dp_error_general       = 4

       OTHERS                 = 5.

   IF sy-subrc <> 0.

   ENDIF.

   ref_html->set_ui_flag( ref_html->uiflag_no3dborder ).

11 REPLIES 11
Read only

former_member219762
Contributor
0 Likes
3,121

Hi ,

  Did use do_refresh method of html viewer?

Regards,

Sreenivas.

Read only

0 Likes
3,121

dear Sreenivasa,

No effect with do_refresh method.

The method load_data generate same url after data change in ts_data.

Read only

rosenberg_eitan
Active Contributor
0 Likes
3,121

Hi,

Have a look at SAPHTML_DEMO1

Regards.

Read only

0 Likes
3,121

Dear Eitan,

This demo like a browser if we change the url it effect. but the method load_data generate same url after data change in ts_data.

Read only

0 Likes
3,121

Hi,

You are right.

So we change the url.....

DATA: url TYPE sdok_url VALUE .

   CONCATENATE sy-uzeit '.htm' INTO url .

   DATA: it_soli_1 TYPE soli_tab .

   PERFORM get_html_data_1
     CHANGING
       it_soli_1 .

   CALL METHOD ob_gui_html_viewer->load_data
     EXPORTING
       url          = url
     IMPORTING
       assigned_url = url
     CHANGING
       data_table   = it_soli_1[].

   CALL METHOD ob_gui_html_viewer->show_url
     EXPORTING
       url = url.

   CALL METHOD cl_gui_html_viewer=>set_focus
     EXPORTING
       control           = ob_gui_html_viewer
     EXCEPTIONS
       cntl_error        = 1
       cntl_system_error = 2
       OTHERS            = 3.

I add the whole show.


Read only

Former Member
0 Likes
3,121

Does the following piece of code get executed every time PAI is triggered?

   CREATE OBJECT ref_cont

     EXPORTING

       container_name              = 'CONT'

     EXCEPTIONS

       cntl_error                  = 1

       cntl_system_error           = 2

       create_error                = 3

       lifetime_error              = 4

       lifetime_dynpro_dynpro_link = 5

       OTHERS                      = 6.

   IF sy-subrc <> 0.

   ENDIF.

   CREATE OBJECT ref_html

     EXPORTING

       parent             = ref_cont

     EXCEPTIONS

       cntl_error         = 1

       cntl_install_error = 2

       dp_install_error   = 3

       dp_error           = 4

       OTHERS             = 5.

   IF sy-subrc <> 0.

   ENDIF.

If yes, then try putting the above code in the following block

IF ref_cont IS NOT BOUND.

"The create object code

ENDIF.

"The load and refresh code

Read only

0 Likes
3,121

Dear Edwin,

Your solution is not working.

Read only

0 Likes
3,121

Probably the full code might help you understand.

REPORT  zhtml_example.
DATA: ref_cont TYPE REF TO cl_gui_custom_container,
       ref_html TYPE REF TO cl_gui_html_viewer,
         ts_data TYPE TABLE OF char255.
CALL SCREEN 100.
FORM display_html.
   DATA: w_url TYPE char255.

   IF ref_cont IS NOT BOUND.
     APPEND '<html><body>hello world<br />' TO ts_data.
     CREATE OBJECT ref_cont
        EXPORTING
          container_name              = 'CONT'
        EXCEPTIONS
          cntl_error                  = 1
          cntl_system_error           = 2
          create_error                = 3
          lifetime_error              = 4
          lifetime_dynpro_dynpro_link = 5
          OTHERS                      = 6.
     IF sy-subrc <> 0.
     ENDIF.

     CREATE OBJECT ref_html
       EXPORTING
         parent             = ref_cont
       EXCEPTIONS
         cntl_error         = 1
         cntl_install_error = 2
         dp_install_error   = 3
         dp_error           = 4
         OTHERS             = 5.
     IF sy-subrc <> 0.
     ENDIF.
   ELSE.
     APPEND 'hello world<br />' TO ts_data.
   ENDIF.

   CALL METHOD ref_html->load_data
     IMPORTING
       assigned_url         = w_url
     CHANGING
       data_table           = ts_data
     EXCEPTIONS
       dp_invalid_parameter = 1
       dp_error_general     = 2
       cntl_error           = 3
       OTHERS               = 4.
   IF sy-subrc <> 0.
   ENDIF.

   CALL METHOD ref_html->show_url
     EXPORTING
       url                    = w_url
     EXCEPTIONS
       cntl_error             = 1
       cnht_error_not_allowed = 2
       cnht_error_parameter   = 3
       dp_error_general       = 4
       OTHERS                 = 5.
   IF sy-subrc <> 0.
   ENDIF.
   ref_html->set_ui_flag( ref_html->uiflag_no3dborder ).
ENDFORM.
MODULE status_0100 OUTPUT.
   SET PF-STATUS 'S0100'.
   PERFORM display_html.
ENDMODULE.
MODULE user_command_0100 INPUT.
   IF sy-ucomm EQ 'BACK'.
     LEAVE TO SCREEN 0.
   ENDIF.
ENDMODULE.

Additional Information on the code:

1. Create screen 100 and place a custom container named CONT

2. Create two modules. (The status_0100 is in PBO and the other one in PAI)

3. Create a status and set BACK as the function code for back button.

4. Every time you click on the Continue button beside the command box the HTML content will get updated.

Read only

Former Member
0 Likes
3,121

Thank you all,

I got the answer myself.

at the change of data call the below method before create object ref_html.

    IF ref_html IS NOT INITIAL.

      CALL METHOD ref_html->free.

      clear ref_html.

    ENDIF.

Read only

0 Likes
3,121

Hi,

I think that this is not the best solution .

In my opinion if recreating an object can be avoided then avoid it.

And this is what I did in my program.

regards.

Read only

Former Member
3,121

Hi Experts,

i know that is an old topic, but i believe that i found the solution.

I solved this problem testing whether object already exist, like this:


     if ref_html is initial.

          CREATE OBJECT ref_html
            EXPORTING
              parent             = ref_cont
            EXCEPTIONS
              cntl_error         = 1
              cntl_install_error = 2
              dp_install_error   = 3
              dp_error           = 4
              OTHERS             = 5.
          IF sy-subrc <> 0.
          ENDIF.

     endif.


I believe that happens because when we call the "CREATE OBJECT", SAP creates another reference link for that object, losing the original one (that created in the first call) then when we call "SHOW_URL" the new object (that is not shown in the screen) that makes the call.


Testing whether object was already instantiated prevents SAP system of creating a new object in memory, losing the orignal reference.


Please try this.

This theory worked fine for me.