cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Custom ABAP Class using SO_DOCUMENT_READ_API1

GeorgeOk
Explorer
0 Likes
1,220

Hello,

I thought of creating a custom class in order to call the function 'SO_DOCUMENT_READ_API1' to read the SOFM text from a user's comment and then implement it as text in an email notification task.
I don't want to create a custom object and add this method inside for now so I thought of creating an ABAP Class and calling the method from here.
The code I used is:

method EXTRACT.
DATA: lt_object_content TYPE TABLE OF soli,
lv_document_text TYPE string,
ls_content TYPE soli.

" Call the function module to extract the text from the SOFM object
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = iv_document_id
TABLES
object_content = lt_object_content
EXCEPTIONS
no_authorization = 1
document_not_found = 2
others = 3.

" Check for the return value of the function module
IF sy-subrc = 0.
" Concatenate the text into a single string (using APPEND for better performance)
LOOP AT lt_object_content INTO ls_content.
" Append the line to the final text variable
lv_document_text = lv_document_text && ls_content-line && cl_abap_char_utilities=>newline.
ENDLOOP.

" Set the extracted text to the output parameter
rv_document_text = lv_document_text.

ELSE.
" Handle error scenario with more specific messages
CASE sy-subrc.
WHEN 1.
rv_document_text = 'No authorization to read the document'.
WHEN 2.
rv_document_text = 'Document not found'.
WHEN OTHERS.
rv_document_text = 'Error reading SOFM object'.
ENDCASE.
ENDIF.

endmethod.

with two insert and export parameters 
import: IV_DOCUMENT_ID
export: RV_DOCUMENT_TEXT
I dont know if this code works because it is still in process mode when I test, the status doesnt go in completion (yes its a background job, I think a terminating event has to be raised).
What are all the necessary steps I should do? thank you very much in advance!

Accepted Solutions (0)

Answers (2)

Answers (2)

GeorgeOk
Explorer
0 Likes

Hello thanks for the reply,
i have this error in the workflow

  • Exception CX_SY_REF_IS_INITIAL raised by CL_SWF_UTL_RUN_CLIF_METHOD====CCIMP in line 86 with text - Message no. SWF_RUN647
Sandra_Rossi
Active Contributor
0 Likes
SWF_RUN647: "Exception &1 raised by &2 in line &3 with text: &4". What are the values of &1, etc.? You have searched the Web, right, so what did you do? https://www.google.com/search?q=CX_SY_REF_IS_INITIAL+raised+by+CL_SWF_UTL_RUN_CLIF_METHOD%20site:sap...
GeorgeOk
Explorer
0 Likes

Hello thanks for the reply,
I have this error in the workflow when trying to use the function

  • Exception CX_SY_REF_IS_INITIAL raised by CL_SWF_UTL_RUN_CLIF_METHOD====CCIMP in line 86 with text - Message no. SWF_RUN647
Sandra_Rossi
Active Contributor
0 Likes
Please don't post an answer for comments, asking or giving additional details. Answer is reserved to propose a solution. Instead, use Replies > Comment (on the question or on a proposed answer).