Application Development 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: 

SAP HTML Viewer - GET and POST method

former_member998879
Participant
0 Kudos

Hi gurus,

I'm working with SAP HTML Viewer control. I've seen that with this controller i can load an external html page, such as

in the SAPHTML_DEMO1 example report. I wonder if is possible provide data from the report to html page through the controller, and receive data from the html page, after a page submi, and acquire it from the ABAP side.

Is it possible? Any idea?

Thanks in advance for the help!

Regards

Davide

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Davide ,


CLASS cl_myevent_handler DEFINITION.

  PUBLIC SECTION.
    METHODS: on_sapevent
               FOR EVENT sapevent OF cl_gui_html_viewer
                 IMPORTING action frame getdata postdata query_table.

ENDCLASS.                    "cl_myevent_handler DEFINITION
DATA: evt_receiver TYPE REF TO cl_myevent_handler.


  IF html_control IS INITIAL.
    prog_repid = sy-repid.

    CREATE OBJECT my_container
        EXPORTING
            container_name = 'MAIN'.

    CREATE OBJECT html_control
         EXPORTING
              parent    = my_container.
    IF sy-subrc NE 0.
*
    ENDIF.

* register event
    myevent-eventid = html_control->m_id_sapevent.
    myevent-appl_event = 'x'.
    APPEND myevent TO myevent_tab.
    CALL METHOD html_control->set_registered_events
      EXPORTING
        events = myevent_tab.

    CREATE OBJECT evt_receiver.

    SET HANDLER evt_receiver->on_sapevent
                FOR html_control.

  DATA: doc_url(80).

  CALL METHOD html_control->load_html_document
    EXPORTING
      document_id  = 'ZVTLM1'
    IMPORTING
      assigned_url = doc_url
    EXCEPTIONS
      OTHERS       = 1.

  IF sy-subrc EQ 0.
    CALL METHOD html_control->show_url
      EXPORTING
        url = doc_url.
  ENDIF.

CLASS cl_myevent_handler IMPLEMENTATION.

METHOD on_sapevent.

CLEAR edaction.

CLEAR edframe.

CLEAR edgetdata.

CLEAR edpostdataline.

edaction = action.

edframe = frame.

edgetdata = getdata.

postdata_tab = postdata.

IF NOT postdata_tab IS INITIAL.

READ TABLE postdata_tab INDEX 1 INTO edpostdataline.

ENDIF.

edquery_table = query_table.

  • BREAK-POINT.

CASE action.

WHEN 'VEHICLE'.

PERFORM get_vehicle.

WHEN 'INVOICE'.

PERFORM get_invoice.

WHEN 'REPORTS'.

PERFORM reports.

WHEN 'PRINT'.

PERFORM print_invoice.

WHEN OTHERS.

ENDCASE.

ENDMETHOD. "on_sapevent

ENDCLASS. "cl_myevent_handler IMPLEMENTATION

}

The event mechanism of the Control Framework allows you to use handler methods in your

programs to react to events triggered by the control (for example, a double-click).1. Assume you are working with a custom control that has the ABAP wrapper cl_gui_xyz.

DATA my_control TYPE REF TO cl_gui_xyz.

Registering Events with the Control Framework

2. Define an internal table (type cntl_simple_events) and a corresponding work area (type

cntl_simple_event).

DATA events TYPE cntl_simple_events.

DATA wa_events TYPE cntl_simple_event.

3. Now fill the event table with the relevant events. To do this, you need the event ID

(event_id field). You can find this information in the Class Browser by looking at the

attributes of the class cl_gui_xyz. You must also decide whether the event is to be a

system event (appl_event = ' ') or an application event (appl_event = 'X').

wa_events-eventid = event_id.

wa_events-appl_event = appl_event.

APPEND wa_events TO events.

4. You must now send the event table to the frontend so that it knows which events it has to

direct to the backend.

CALL METHOD my_control->set_registered_events

events = events.

To react to the events of you custom control, you must now specify a handler method for it. This

can be either an instance method or a static method

Hope this will help you.

Please revert to me if you need more help in this.

Regards,

Nikhil

5 REPLIES 5

Former Member
0 Kudos

Hi Davide ,


CLASS cl_myevent_handler DEFINITION.

  PUBLIC SECTION.
    METHODS: on_sapevent
               FOR EVENT sapevent OF cl_gui_html_viewer
                 IMPORTING action frame getdata postdata query_table.

ENDCLASS.                    "cl_myevent_handler DEFINITION
DATA: evt_receiver TYPE REF TO cl_myevent_handler.


  IF html_control IS INITIAL.
    prog_repid = sy-repid.

    CREATE OBJECT my_container
        EXPORTING
            container_name = 'MAIN'.

    CREATE OBJECT html_control
         EXPORTING
              parent    = my_container.
    IF sy-subrc NE 0.
*
    ENDIF.

* register event
    myevent-eventid = html_control->m_id_sapevent.
    myevent-appl_event = 'x'.
    APPEND myevent TO myevent_tab.
    CALL METHOD html_control->set_registered_events
      EXPORTING
        events = myevent_tab.

    CREATE OBJECT evt_receiver.

    SET HANDLER evt_receiver->on_sapevent
                FOR html_control.

  DATA: doc_url(80).

  CALL METHOD html_control->load_html_document
    EXPORTING
      document_id  = 'ZVTLM1'
    IMPORTING
      assigned_url = doc_url
    EXCEPTIONS
      OTHERS       = 1.

  IF sy-subrc EQ 0.
    CALL METHOD html_control->show_url
      EXPORTING
        url = doc_url.
  ENDIF.

CLASS cl_myevent_handler IMPLEMENTATION.

METHOD on_sapevent.

CLEAR edaction.

CLEAR edframe.

CLEAR edgetdata.

CLEAR edpostdataline.

edaction = action.

edframe = frame.

edgetdata = getdata.

postdata_tab = postdata.

IF NOT postdata_tab IS INITIAL.

READ TABLE postdata_tab INDEX 1 INTO edpostdataline.

ENDIF.

edquery_table = query_table.

  • BREAK-POINT.

CASE action.

WHEN 'VEHICLE'.

PERFORM get_vehicle.

WHEN 'INVOICE'.

PERFORM get_invoice.

WHEN 'REPORTS'.

PERFORM reports.

WHEN 'PRINT'.

PERFORM print_invoice.

WHEN OTHERS.

ENDCASE.

ENDMETHOD. "on_sapevent

ENDCLASS. "cl_myevent_handler IMPLEMENTATION

}

The event mechanism of the Control Framework allows you to use handler methods in your

programs to react to events triggered by the control (for example, a double-click).1. Assume you are working with a custom control that has the ABAP wrapper cl_gui_xyz.

DATA my_control TYPE REF TO cl_gui_xyz.

Registering Events with the Control Framework

2. Define an internal table (type cntl_simple_events) and a corresponding work area (type

cntl_simple_event).

DATA events TYPE cntl_simple_events.

DATA wa_events TYPE cntl_simple_event.

3. Now fill the event table with the relevant events. To do this, you need the event ID

(event_id field). You can find this information in the Class Browser by looking at the

attributes of the class cl_gui_xyz. You must also decide whether the event is to be a

system event (appl_event = ' ') or an application event (appl_event = 'X').

wa_events-eventid = event_id.

wa_events-appl_event = appl_event.

APPEND wa_events TO events.

4. You must now send the event table to the frontend so that it knows which events it has to

direct to the backend.

CALL METHOD my_control->set_registered_events

events = events.

To react to the events of you custom control, you must now specify a handler method for it. This

can be either an instance method or a static method

Hope this will help you.

Please revert to me if you need more help in this.

Regards,

Nikhil

0 Kudos

Hi Nikhil,

thanks for your reply, but i don't understand.

Take for example the report SAPHTML_DEMO1. It simulates a browser into SAP GUI.

My request is:

i load an external html page ( for example www.abcd.xx/page.htm ) which contains some html input field valorized.

Can I pressing a button (application item ) on a GUI ( such as that used for refresh the page,

defined on "user_command_0100" module of the report wih the code HRFR ) get back the value of the html input field?

I hope to have explained it well.

Davide

0 Kudos

Finally i found a solution!

Simply look this report: SAPHTML_EVENTS_DEMO

It shows how variable are passed from ABAP to HTML and vice versa.

Best regards

Davide

former_member998879
Participant
0 Kudos

Thanks everyone, thanks SDN!

0 Kudos

Hello, I was looking for an answer and finally I get it.  please see this link

https://wiki.scn.sap.com/wiki/x/GQx2Gg

I hope this helps.

Regards

Carlos Andres Gonzalez