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.
|
Pretty neat trick! What can we use if for?
ReplyDeleteyou could create nice colorful forms...
ReplyDeleteYes, I could! But in my job usually I create only ALV reports...
ReplyDeleteMaybe we could find something? How about Adobe AIR? It's suppose to use html.
how to run your programm in 46c?
ReplyDeleteI'm using ECC6.0 and it has been a long time since I was on 4.6. Use se16 to check for the class cl_gui_html_viewer. If you don't have that, then you will need to look for the function modules that do the same thing.
ReplyDeleteHope this helps!
Hey Saurav,
ReplyDeleteI am using class cl_gui_html_viewer to display the URL in a dialog box (using custom container). I was wondering if there is any way to append name=value parameters to this URL using HTTP POST method. I am working on ECC 6.0 and preety new to ABAP.
Thanks.
Hello Saurav,
ReplyDeleteWonderful piece of code.. thanks.
I want to know something more, how can I render the same HTML to a subscreen area. basically I want to display say some n form fields in a subscreen area. The requirement is to display some notifications/news kind of info which keeps varying with values. So i was thinking of using HTML to do my job with placeholders in it and keep updating the place holders with values.
Thanks in advance,
raghavenda,
ReplyDeleteAre you calling a R/3 screen? maybe look at SAPHTML_EVENTS_DEMO, or any of the picture controls in transaction DWDM.
Please let us know how it works.
I have a need for it in one of my projects now. The client would be very happy if all the channels displayed the same screen for a grid that is being developed as an extension to ECC6.0/VC and CRM/Ecommerce/IPC channels. It would be nice to have the VC pfunction ABAP/Java dynamically generate the same HTML screen.
ReplyDeleteHi, how did you solved the 512-character bottleneck? Does your implementation work, if somebody enters a value with more than 512 characters?
ReplyDeleteI tried to overcome this using javascript in the html form: https://bitbucket.org/repo/all?name=adsadi
But perhaps there is an ABAP-side solution?
How can i use a dynamic variable int the abap html code?
ReplyDeletehello,
ReplyDeleteSomeone can help me,
I use your example to add some data in DB, but I need to rescue this data in the screen again.
How can I do this?
Nice
ReplyDeleteWeb Development Company