Bind SO10 Text To TextEdit area and back…Part 2
Part 1: Bind SO10 Text To TextEdit area and back…Part 1
It’s time to bind the TextEdit area to the context element..
The result should look like this:
What is left is the code for the Load button.
The LOAD_TEXT event handler can be modified by double-clicking on LOAD_TEXT…
We need to fill the context element…The wizard can create the code:
This is the code…
Let’s modify it like this:
Because lv_text1 remains empty, no text is visible in case you’ve tested something already…
We must take care of that:
YES, I know that we do not want to select/update data to the database in the view of the WebDynpro.. but this only a simple example to show how to bind SO10 texts to WebDynpro components…
ONACTIONLOAD_TEXT
We will read the SO10 text, convert it and put it in the context:
Code:
METHOD onactionload_text .
* Variables to set the text to the context
DATA lo_nd_node1 TYPE REF TO if_wd_context_node.
DATA lo_el_node1 TYPE REF TO if_wd_context_element.
DATA ls_node1 TYPE wd_this->element_node1.
DATA lv_text1 LIKE ls_node1–text1.
* Variables to read the so10 texts
DATA li_lines TYPE STANDARD TABLE OF tline.
* Variables to convert the SO10 text to a streamtext…
DATA lv_tabix TYPE sy–tabix.
DATA li_strlines TYPE stringtab.
FIELD-SYMBOLS <lfx_strline> TYPE string.
* Open the SO10 text…
CALL FUNCTION ‘READ_TEXT’
EXPORTING
client = sy–mandt
id = ‘ST’
language = ‘E’
name = ‘YTEST’
object = ‘TEXT’
TABLES
lines = li_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy–subrc <> 0.
MESSAGE ID sy–msgid TYPE sy–msgty NUMBER sy–msgno
WITH sy–msgv1 sy–msgv2 sy–msgv3 sy–msgv4.
ENDIF.
* Convert the SO10 text to a streamtext
CALL FUNCTION ‘CONVERT_ITF_TO_STREAM_TEXT’
EXPORTING
lf = abap_true
IMPORTING
stream_lines = li_strlines
TABLES
itf_text = li_lines.
lv_tabix = LINES( li_strlines ).
* Put all lines in one string line…
LOOP AT li_strlines ASSIGNING <lfx_strline>.
IF sy–tabix < lv_tabix.
CONCATENATE lv_text1 <lfx_strline> cl_abap_char_utilities=>newline INTO lv_text1.
ELSE.
CONCATENATE lv_text1 <lfx_strline> INTO lv_text1.
ENDIF.
ENDLOOP.
* navigate from <CONTEXT> to <NODE1> via lead selection
lo_nd_node1 = wd_context->get_child_node( name = wd_this->wdctx_node1 ).
* get element via lead selection
lo_el_node1 = lo_nd_node1->get_element( ).
* get single attribute
lo_el_node1->set_attribute(
EXPORTING
name = `TEXT1`
value = lv_text1 ).
ENDMETHOD.
ONACTIONSAVE_TEXT
We will read the context transform it and save it to the SO10 text:
Code:
METHOD onactionsave_text .
* Variables to set the text to the context
DATA lo_nd_node1 TYPE REF TO if_wd_context_node.
DATA lo_el_node1 TYPE REF TO if_wd_context_element.
DATA ls_node1 TYPE wd_this->element_node1.
DATA lv_text1 LIKE ls_node1–text1.
* Variables to update the SO10 text
DATA li_lines TYPE STANDARD TABLE OF tline.
* Variables to convert the streamtext to an SO10 text
DATA lv_tabix TYPE sy–tabix.
DATA li_strlines TYPE stringtab.
FIELD-SYMBOLS <lfx_strline> TYPE string.
* Variables to easily fill the HEADER variable of the SAVE_TEXT fm.
DATA lx_stxh TYPE stxh.
DATA lx_header TYPE thead.
* navigate from <CONTEXT> to <NODE1> via lead selection
lo_nd_node1 = wd_context->get_child_node( name = wd_this->wdctx_node1 ).
* get element via lead selection
lo_el_node1 = lo_nd_node1->get_element( ).
* get single attribute
lo_el_node1->get_attribute(
EXPORTING
name = `TEXT1`
IMPORTING
value = lv_text1 ).
* Append the string (from the context) to li_strlines…
APPEND lv_text1 TO li_strlines.
* Convert the li_strlines to an SO10-like text
CALL FUNCTION ‘CONVERT_STREAM_TO_ITF_TEXT’
EXPORTING
stream_lines = li_strlines
lf = abap_true
TABLES
itf_text = li_lines.
* Fill lx_header
SELECT SINGLE *
FROM stxh
INTO lx_stxh
WHERE tdobject = ‘TEXT’
AND tdname = ‘YTEST’
AND tdid = ‘ST’
AND tdspras = ‘E’.
MOVE-CORRESPONDING lx_stxh TO lx_header.
* Save the SO10 text to the database
CALL FUNCTION ‘SAVE_TEXT’
EXPORTING
client = sy–mandt
header = lx_header
TABLES
lines = li_lines
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5.
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.
Create a Web Dynpro application to test all the hard work…
Save the application
Activate the Web Dynpro
Test the Web Dynpro
Do something crazy (in the text editor…)
…and press Save…
Clear the textfield..
Now, if you load the text again:
SO10 text:
Result:
Mission Accomplished