SAP Function SO_DOCUMENT_DELETE_API1 - SAPoffice: Delete document using RFC

Parameter Reference Type Length Default Optional Text
DOCUMENT_ID SOFOLENTI1-DOC_ID C 46 ID of document to be deleted
PUT_IN_TRASH SONV-FLAG C 1 'X' X Flag: Move document to trash folder
UNREAD_DELETE SONV-FLAG C 1 X Flag: Delete document unviewed

Exception Text
DOCUMENT_NOT_EXIST Specified document does not exist
ENQUEUE_ERROR Required locks could not be set
OPERATION_NO_AUTHORIZATION No authorization to delete document
PARAMETER_ERROR Invalid combination of parameter values
X_ERROR Internal error or database inconsistency

Functionality
This function module is used to delete the folder entry of a document.If required, it is placed in the shared trash or private trash of theactive user depending on the set of folders and can be retrieved fromthere before the trash is next emptied.

Import parameters
DOCUMENT_ID
ID of the folder entry to be deleted. It is the connection between thedocument and folder in which it is located.
UNREAD_DELETE
Default = ' '.
If this flag is set ('X'), the specified folder entry is deleted if ithas not yet been read.
PUT_IN_TRASH
Default = 'X'.
If this flag is set ('X'), the deleted entry is placed in theappropriate trash. It can be retrieved from there before the trash isemptied.

Exceptions
DOCUMENT_NOT_EXIST
The specified folder entry does not exist. An incorrect ID was probablypassed or the relevent folder entry deleted.
OPERATION_NO_AUTHORIZATION
It was not possible to delete the specified folder entry. This may bebecause it is located in the private area of another user or in ashared folder for which the active user does not have a deleteauthorization. Only the SAPoffice administrator can access the sharedtrash. The document may have been received but not yet read, repliedto, or acted upon.
PARAMETER_ERROR
An invalid combination of parameter values was passed to the functionmodule.
X_ERROR
An internal error or database inconsistency occurred.
ENQUEUE_ERROR
A lock involved in the deletion operation could not be set. Processingis probably being carried out by another user.

Example
Deleting all documents which have been read, replied to and acted uponfrom the inbox of the active user. The deleted documents are placed inthe private trash. To determine the ID of the inbox, the functionmodule SO_USER_READ_API1 is used, the list of documents located in theinbox is determined via the function module SO_FOLDER_READ_API1.
DATA: FOL_CONT LIKE SOFOLENTI1 OCCURS 20 WITH HEADER LINE.
DATA: USER_DATA LIKE SOUDATAI1.
CALL FUNCTION 'SO_USER_READ_API1'
IMPORTING
USER_DATA = USER_DATA
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
WRITE: / 'User data could not be read !'.
EXIT.
ENDIF.
CALL FUNCTION 'SO_FOLDER_READ_API1'
EXPORTING
FOLDER_ID = USER_DATA-INBOXFOL
TABLES
FOLDER_CONTENT = FOL_CONT
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
WRITE: / 'Inbox could not be read !'.
EXIT.
ENDIF.
LOOP AT FOL_CONT
WHERE NOT READ IS INITIAL
AND NOT STILL_TODO IS INITIAL
AND ( TO_ANSWER IS INITIAL OR NOT REPLY_SENT IS INITIAL ).
CALL FUNCTION 'SO_FOLDER_DELETE_API1'
EXPORTING
DOCUMENT_ID = FOL_CONT-DOC_ID
PUT_IN_TRASH = 'X'
EXCEPTIONS
OTHERS = 1.
CASE SY-SUBRC.
WHEN 0.
WRITE: / 'Document', FOL_CONT-OBJ_DESCR, 'was deleted !'.
WHEN OTHERS.
WRITE: / 'Error deleting', FOL_CONT-OBJ_DESCR, '!'.
ENDCASE.
ENDLOOP.
IF SY-SUBRC <> 0.
WRITE: / 'No documents in inbox which can be deleted !'.
ENDIF.

Notes
To delete folders or distribution lists, the function modulesSO_FOLDER_DELETE_API1 or SO_DLI_DELETE_API1 must be used.
It is not generally possible to delete documents which have not beenviewed, require a reply or need to be acted upon. However, unvieweddocuments can be removed by setting the UNREAD_DELETE flag, documentswhich have not yet been replied to for a sender which does not exist inthe SAP System.
If a document is deleted from the resubmission folder, all relatedresubmitted documents are also removed from the inbox.

Further information
Information on calling the function modules SO_USER_READ_API1 andSO_FOLDER_READ_API1 can be found in the documentation of the respectivefunction modules.