








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.

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.









You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 27 | |
| 24 | |
| 20 | |
| 19 | |
| 13 | |
| 13 | |
| 12 | |
| 12 | |
| 11 | |
| 10 |