Skip to Content

Part 1: Bind SO10 Text To TextEdit area and back…Part 1

It’s time to bind the TextEdit area to the context element..

/wp-content/uploads/2015/08/29_773793.png

/wp-content/uploads/2015/08/30_773794.png

The result should look like this:

/wp-content/uploads/2015/08/31_773804.png

What is left is the code for the Load button.

The LOAD_TEXT event handler can be modified by double-clicking on LOAD_TEXT…

/wp-content/uploads/2015/08/32_773805.png

We need to fill the context element…The wizard can create the code:

/wp-content/uploads/2015/08/33_773806.png

/wp-content/uploads/2015/08/34_773807.png

This is the code…

/wp-content/uploads/2015/08/35_773808.png

Let’s modify it like this:

/wp-content/uploads/2015/08/36_773809.png

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:

/wp-content/uploads/2015/08/37_773810.png

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_node1text1.
* 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 sytabix.
DATA li_strlines TYPE stringtab.
FIELD-SYMBOLS <lfx_strline> TYPE string.

* Open the SO10 text…
CALL FUNCTION ‘READ_TEXT’
EXPORTING
client                              = symandt
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 sysubrc <> 0.
MESSAGE ID symsgid TYPE symsgty NUMBER symsgno
WITH symsgv1 symsgv2 symsgv3 symsgv4.
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 sytabix < 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:

/wp-content/uploads/2015/08/38_773811.png

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_node1text1.
* 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 sytabix.
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       = symandt
header     = lx_header
TABLES
lines        = li_lines
EXCEPTIONS
id            = 1
language  = 2
name      
= 3
object     
= 4
OTHERS   = 5.
IF sysubrc <> 0.
MESSAGE ID symsgid TYPE symsgty NUMBER symsgno
WITH symsgv1 symsgv2 symsgv3 symsgv4.
ENDIF.

ENDMETHOD.

 

Create a Web Dynpro application to test all the hard work…

/wp-content/uploads/2015/08/39_773812.png

/wp-content/uploads/2015/08/40_773816.png

Save the application

Activate the Web Dynpro

 

Test the Web Dynpro

/wp-content/uploads/2015/08/43_773817.png

/wp-content/uploads/2015/08/44_773818.png/wp-content/uploads/2015/08/45_773819.png

Do something crazy (in the text editor…)
/wp-content/uploads/2015/08/46_773820.png

…and press Save…

Clear the textfield..

/wp-content/uploads/2015/08/47_773821.png

Now, if you load the text again:

/wp-content/uploads/2015/08/48_773822.png

SO10 text:

/wp-content/uploads/2015/08/49_773823.png

Result:

Mission Accomplished

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply