2019 Jul 19 10:50 AM
Hi experts.
I have the requirement to create the HTML page in the SAP using ABAP and launch that page in the browser and from the browser
I have to communicate to the backend ( sap ) using the sapevent:SAVE ,( i should not use the rest service ) .
I use the savevent:SAVE event the page is refreshing in the browser. how to stop the refreshing of the page.
Exaple: create report program( IN SE38 )
*&---------------------------------------------------------------------*
*& Report Z_TEST1234
REPORT Z_TEST1234.
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. "lcl_class DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_class IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_class IMPLEMENTATION.
METHOD main.
DATA oref_lcl TYPE REF TO lcl_class.
DATA html TYPE w3htmltab.
DATA url TYPE c LENGTH 255.
DATA events TYPE cntl_simple_events.
DATA event TYPE cntl_simple_event.
CREATE OBJECT oref
EXPORTING
parent = cl_gui_container=>screen0.
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 '<div id="form_sample"></div>' 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 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 '<script>' to html.
oref->load_data( IMPORTING assigned_url = url
CHANGING data_table = html ).
oref->show_url( url = url ).
if sy-subrc <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
ENDMETHOD. "main
METHOD on_html_event.
DATA:l_string TYPE string.
l_string = getdata.
MESSAGE i001(00) WITH l_string.
ENDMETHOD. "on_html_event
ENDCLASS. "lcl_class IMPLEMENTATION
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.
in the above program, I create a class to handling event and I created the one HTML page where we have the two fields in the form and Form as action="SAPEVENT: SAVE" for raising the event when press submit button .
For this report program create one transaction called "ZCHH" in SE93.
URL look like this = "https://eccad.xyx.net:2020/sap/bc/gui/sap/its/webgui?~TRANSACTION=ZCHH"
I launched this transaction in the browser.
The page will look like this
After enter the First name and last name , if press the Submit button the page will refresh .
How to stop page refresh.
Re grads
Harish
2019 Jul 19 11:47 AM
What means "Refresh"? I run your program, nothing changes. What do you expect?
2019 Jul 22 5:28 AM
Hi Sandra Rossi
Thanks for the reply
"Refresh" means here whole page getting refreshing after submitting the form in the browser.
it is working correctly in the SAP GUI but not in the browser ( i'm using chrome ) .
Let say
We entered the First name : Sandra and
Last name : Rossi
when we press the submit button , the content getting lost.
Check in the first image I entered the first name and last name and i pressed submit button
after pressing submit button
2019 Jul 22 8:51 AM
action="SAPEVENT:something" always triggers a call to the backend, so there's a (transparent) refresh of the page. Can't be avoided (or maybe ICF service or AMC, but then better learn UI5, Web dynpro or BSP).
ADDENDUM: regenerate the HTML page after the refresh, with the form fields with the values from GETDATA.
DELETION (by default the <form> method is GET, I was wrong) --Your code misses the retrieval of form fields entered by the user (parameter POSTDATA of the event, and not GETDATA because the HTML <form> method uses POST by default) and when you regenerate the HTML page, initialize the form fields with the values from POSTDATA (via intermediate attributes, for example).--
2019 Jul 22 10:48 AM
That is an example, so i did not added any parameter .
Thanks for the reply