2023 Dec 15 11:08 AM
The "pos" parameter of the search and replace method does not specify the values it should take for each of the options. According to the documentation, the options are "global", "up", and "down."
call method wp_wordpro->replace
exporting
flag = 'X'
pos = ¿Value for the 'global' option.?
replace_string = p_valor
search_string = p_search_string
importing
error = l_error
retcode = l_retcode.
Based on the cursor position, it is unable to replace the text.
2023 Dec 15 12:16 PM
The "values it should take for each of the options [...] are "global", "up", and "down."
Correct, what is your question?
2023 Dec 15 12:40 PM
Please use the COMMENT button for comments, asking for complements, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.
Better use Actions > Edit to indicate your question "how to reposition the cursor at the beginning of the document"
2023 Dec 15 12:45 PM
if any of the indicated options are used, the replace method does not work. My question is whether the value 'global' equals 0, 'up' equals 1, or something similar.
2023 Dec 15 1:08 PM
Reposition the cursor at the beginning of the document before each search or replace to make sure.
You may directly access OLE and execute OLE Word methods to reposition the cursor before the texts to search and replace (e.g. at the top) = equivalent to VBA code "Call Selection.HomeKey(Unit:=wdStory)":
DATA doi_control TYPE REF TO I_OI_CONTAINER_CONTROL.
c_oi_container_control_creator=>get_container_control(
IMPORTING
control = doi_control ).
... " MS Word initialization
" direct OLE Call of "Selection.HomeKey(Unit:=wdStory)"
DATA(doi_handle) = doi_control->get_control_handle( ). " type CNTL_HANDLE in type pool CNTL
DATA(ole_handle) = doi_handle-obj. " type OBJ_RECORD
GET PROPERTY OF ole_handle 'Selection' = selection.
CALL METHOD OF selection 'HomeKey' EXPORTING #1 = 6. " Constant wdStory = 6
... " Search or Replace
The code is incomplete, you can find what is missing in the forum.