‎2010 Aug 09 12:15 PM
Hi all,
I have a dynpro application with a HTML-control.
I load a web page into the HTML-control.
Is it possible to fill the fields in the web page automatically?
(For example a javascript file will be executed from ABAP and then a value will be filled into a textfield.)
Or how can I fill the fields in the web page?
regards
‎2010 Aug 09 3:00 PM
Hello,
Yes you can do it with script execution :
CL_GUI_HTML_VIEWER has methods for executing scripts, "set_script" and "execute_script"
but you should use inheritance first because these methods are Protected.
In JavaScript this code used for setting a value in an HTML input :
'document.getElementById('INPUT_FIELD_NAME).value = 'Hello'
As a result of them, Here is my class :
CLASS cl_gui_html_viewer_extend DEFINITION
INHERITING FROM cl_gui_html_viewer.
PUBLIC SECTION.
METHODS:
set_input_value
IMPORTING
ip_input_name TYPE c
ip_value TYPE c.
ENDCLASS.
CLASS cl_gui_html_viewer_extend IMPLEMENTATION.
METHOD set_input_value.
DATA : t_script TYPE TABLE OF char100,
w_script LIKE LINE OF t_script.
CONCATENATE
'document.getElementById(''' ip_input_name ''').value ='
'"' ip_value '"' INTO w_script.
APPEND w_script TO t_script.
CALL METHOD set_script
EXPORTING
script = t_script.
CALL METHOD execute_script.
ENDMETHOD.
ENDCLASS.
Use this class instead of CL_GUI_HTML_VIEWER in your code.
and call method set_input_value to set a value in an HTML input.
I hope it will be useful for u.
‎2010 Aug 09 3:00 PM
Hello,
Yes you can do it with script execution :
CL_GUI_HTML_VIEWER has methods for executing scripts, "set_script" and "execute_script"
but you should use inheritance first because these methods are Protected.
In JavaScript this code used for setting a value in an HTML input :
'document.getElementById('INPUT_FIELD_NAME).value = 'Hello'
As a result of them, Here is my class :
CLASS cl_gui_html_viewer_extend DEFINITION
INHERITING FROM cl_gui_html_viewer.
PUBLIC SECTION.
METHODS:
set_input_value
IMPORTING
ip_input_name TYPE c
ip_value TYPE c.
ENDCLASS.
CLASS cl_gui_html_viewer_extend IMPLEMENTATION.
METHOD set_input_value.
DATA : t_script TYPE TABLE OF char100,
w_script LIKE LINE OF t_script.
CONCATENATE
'document.getElementById(''' ip_input_name ''').value ='
'"' ip_value '"' INTO w_script.
APPEND w_script TO t_script.
CALL METHOD set_script
EXPORTING
script = t_script.
CALL METHOD execute_script.
ENDMETHOD.
ENDCLASS.
Use this class instead of CL_GUI_HTML_VIEWER in your code.
and call method set_input_value to set a value in an HTML input.
I hope it will be useful for u.
‎2010 Aug 12 6:13 AM
Hi,
is there also a method how to read the values from the HTML page back to the ABAP?
I try it this way but the error is: CL_JAVA_SCRIPT, Rcode: ( 600 ), Error at line 1 : ReferenceError: document is not defined
js_processor = cl_java_script=>create( ).
CONCATENATE
'var string = document.getElementById(''' ip_input_name ''').value;'
INTO source.
CONCATENATE source
'function Set_String() '
' { return (string); '
' } '
'Set_String(); '
INTO source SEPARATED BY cl_abap_char_utilities=>cr_lf.
js_processor->compile( script_name = 'HELLO_WORLD.JS'
script = source ).
return_VALUE = js_processor->execute( 'HELLO_WORLD.JS' ).
regards
‎2010 Aug 12 7:27 AM
Hello,
The only way to get values from an HTML page is submitting the HTML form
just like user pressed a button on a web page,
Than page sends a navigation string with field - value pairs
field1=value1&field2=value2 .. like all web navigations.
You can parse field values from this string.
CL_GUI_HTML_VIEWER has an event SAPEVENT for that,
you can activate and set a handler for that event
and trigger submit with small JavaScript execution.
I think the example in link below can be helpful for this :
http://abap-explorer.blogspot.com/2008/08/html-through-abap.html
Let me know further problems if you'd have.
‎2010 Aug 13 6:38 AM
Hi,
can I use this eventing with an existing webpage?
In your example the webpage will be build up in ABAP.
I have a HTML control where I load a webpage and then I want to know which value is specified in a specific field.
regards