This code demonstrates how to write HTML code and raise SAP event in ABAP.
The Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
REPORT z_test_sourav_html.
CLASS lcl_class DEFINITION. PUBLIC SECTION. METHODS: main, on_html_event FOR EVENT sapevent OF cl_gui_html_viewer IMPORTING action frame getdata. PROTECTED SECTION.
PRIVATE SECTION. DATA oref TYPE REF TO cl_gui_html_viewer. ENDCLASS.
CLASS lcl_class IMPLEMENTATION. METHOD main. DATA oref_lcl TYPE REF TO lcl_class. DATA html TYPE w3htmltab. DATA url TYPE c LENGTH 255. CREATE OBJECT oref EXPORTING parent = cl_gui_container=>screen0.
DATA events TYPE cntl_simple_events. DATA event TYPE cntl_simple_event.
event-eventid = oref->m_id_sapevent. event-appl_event = 'X'. APPEND event TO events.
CALL METHOD oref->set_registered_events EXPORTING events = events. SET HANDLER me->on_html_event FOR oref.
APPEND '<html>' TO html. APPEND '<body bgcolor= "#FFFFCC">' TO html. APPEND '<font face="arial" size="2">' TO html. APPEND '<b>Header</b>' TO html. APPEND '<br>' TO html. APPEND 'Text' TO html. APPEND '</font>' TO html. APPEND '<form name= "form1" action="SAPEVENT:save">' TO html. APPEND 'First name:' TO html. APPEND '<input type="text" name="firstname">' TO html. APPEND '<br>' TO html. APPEND 'Last name: ' TO html. APPEND '<input type="text" name="lastname">' TO html. APPEND '<br>' TO html. APPEND '<input type="submit" value="Submit">' TO html. APPEND '</form>' TO html. APPEND '</body>' TO html. APPEND '</html>' TO html. oref->load_data( IMPORTING assigned_url = url CHANGING data_table = html ). oref->show_url( url = url ). ENDMETHOD. METHOD on_html_event. DATA:l_string TYPE string. l_string = getdata.
MESSAGE i001(00) WITH l_string. ENDMETHOD. ENDCLASS.
PARAMETERS: p_dummy TYPE c LENGTH 1. AT SELECTION-SCREEN OUTPUT. DATA:lcl_oref TYPE REF TO lcl_class. IF lcl_oref IS NOT BOUND. CREATE OBJECT lcl_oref. CALL METHOD lcl_oref->main. ENDIF.
|