SAP Function SO_DOCUMENT_MOVE_API1 - SAPoffice: Move document to another folder using RFC

Parameter Reference Type Length Default Optional Text
NEW_FOLDER_ID SOFOLENTI1-OBJECT_ID C 17 ID of folder to which entry is moved
OLD_DOCUMENT_ID SOFOLENTI1-DOC_ID C 46 ID of folder entry to be moved

Parameter Reference Type Length Text
NEW_DOCUMENT_ID SOFOLENTI1-DOC_ID C 46 ID of new folder entry

Exception Text
DOCUMENT_ALREADY_IN_FOLDER Document already exists in target folder
DOCUMENT_NOT_EXIST Specified folder entry does not exist
ENQUEUE_ERROR Required locks could not be set
NEW_FOLDER_NOT_EXIST Specified target folder does not exist
OPERATION_NO_AUTHORIZATION No authorization to move document
PARAMETER_ERROR Invalid combination of parameter values
X_ERROR Internal error or database inconsistency

Functionality
This function module allows folder entries belonging to documents ordistribution lists to be moved to another folder. The old folder entryis deleted and a new entry created with the original attributes in thetarget folder.

Import parameters
OLD_DOCUMENT_ID
ID of the folder entry to be moved. It is the connection between thedocument or distribution list and the folder in which it is located.
NEW_FOLDER_ID
Object ID of the folder in which the folder entry is to be placed.

Export parameters
NEW_DOCUMENT_ID
ID of the new folder entry. It is the connection between the documentor distribution list and the folder in which it is located.

Exceptions
NEW_FOLDER_NOT_EXIST
The specified target folder does not exist. An incorrect ID wasprobably passed or the relevant folder was deleted.
DOCUMENT_NOT_EXIST
The specified folder entry does not exist. An incorrect ID was probablypassed or the relevant folder entry deleted.
DOCUMENT_ALREADY_IN_FOLDER
The document could not be moved since the target folder alreadycontains a folder entry belonging to the document.
OPERATION_NO_AUTHORIZATION
The folder entry could not be moved. This may be because an attempt wasmade to move the document from or to the private folder of anotheruser. An area of the shared folders may also have been referenced, forwhich the active user does not have the required authorizations.
PARAMETER_ERROR
An invalid combination of parameter values was passed to the functionmodule. An attempt was probably made to move the folder entry to aninvalid folder. This includes the inbox, resubmission folder, privateor shared trash, and the root folder of the shared folders. It is notpossible to move folder entries between the private area of a user andthe shared folders in either direction.
ENQUEUE_ERROR
A lock required for the move operation could not be set. Processing isprobably being carried out by another user.

Example
Moving documents from the outbox of the active user to a newly createdfolder in the private folders. To determine the ID of the outbox andthe private folders, the function module SO_USER_READ_API1 is used, thecontents of the outbox are read via the function moduleSO_FOLDER_READ_API1. To create the target folder, the function moduleSO_FOLDER_INSERT_API1 is used.
DATA: FOL_CONT LIKE SOFOLENTI1 OCCURS 20 WITH HEADER LINE.
DATA: USER_DATA LIKE SOUDATAI1.
DATA: FOL_CHNG LIKE SOFOLCHGI1.
DATA: NEW_FOLDER_ID LIKE SOFOLDATI1-OBJECT_ID.
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-OUTBOXFOL
TABLES
FOLDER_CONTENT = FOL_CONT
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
WRITE: / 'Outbox could not be read !'.
EXIT.
ENDIF.
FOL_CHNG-OBJ_NAME = 'ABLAGE'.
FOL_CHNG-OBJ_DESCR = 'Documents moved from outbox'.
FOL_CHNG-LANGU = SY-LANGU.
FOL_CHNG-SENSITIVTY = 'O'.
CALL FUNCTION 'SO_FOLDER_INSERT_API1'
EXPORTING
PARENT_FOLDER_ID = USER_DATA-PRIVATFOL
FOLDER_INSERT_DATA = FOL_CHNG
IMPORTING
FOLDER_ID = NEW_FOLDER_ID
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
WRITE: / 'New folder could not be created !'.
EXIT.
ENDIF.
LOOP AT FOL_CONT.
CALL FUNCTION 'SO_DOCUMENT_MOVE_API1'
EXPORTING
OLD_DOCUMENT_ID = FOL_CONT-DOC_ID
NEW_FOLDER_ID = NEW_FOLDER_ID
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
WRITE: / 'Error moving document', FOL_CONT-OBJ_DESCR.
CONTINUE.
ENDIF.
WRITE: / 'Document', FOL_CONT-OBJ_DESCR, 'moved.'.
ENDLOOP.

Notes
The function module SO_FOLDER_MOVE_API1 must be used to movefolders.
To move documents between the shared folders and the private area ofthe user, the function modules SO_DOCUMENT_READ_API1,SO_DOCUMENT_INSERT_API1 and SO_DOCUMENT_DELETE_API1 must be used.

Further information
Information on calling the function modules SO_USER_READ_API1,SO_FOLDER_READ_API1 and SO_FOLDER_INSERT_API1 can be found in thedocumentation of the respective function modules.