SAP Function SO_ATTACHMENT_UPDATE_API1 - SAPoffice: Change attachment using RFC

Parameter Reference Type Length Default Optional Text
ATTACHMENT_DATA SOATTCHGI1 u 75 New attributes of attachment to be changed
ATTACHMENT_ID SOATTINFI1-ATTACH_ID C 63 ID of attachment to be changed

Parameter Reference Type Length Text
ATTACHMENT_INFO SOATTINFI1 u 407 Complete attributes after change

Parameter Reference Length Optional Text
ATTACHMENT_CONTENT SOLISTI1 255 New contents of attachment
ATTACHMENT_HEADER SOLISTI1 255 New header data for attachment (spec.header)
CONTENTS_HEX SOLIX 255 X New attachment contents (binary)

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

Functionality
This function module allows the attributes of an existing documentattachment to be changed.

Import parameters
ATTACHMENT_ID
ID of the attachment to be changed. This is the connection between theattachment and the document it belongs to.
ATTACHMENT_DATA
This structure must contain the new attributes of the attachment to bechanged.

  • OBJ_NAME

  • Name of the attachment.
    • OBJ_DESCR

    • Title (short description) of the attachment.
      • OBJ_LANGU

      • Language of the attachment.
        • ATT_SIZE

        • Size of the attachment in bytes. In the case of PC documents, the sizeof the respective file should be entered here, in the case of RAW andSCR documents, the size is calculated from the "length of the lastline" + "number of remaining lines multiplied by 255".

          Export parameters
          ATTACHMENT_INFO
          This structure contains the complete attributes of the attachmentchanged.

          • ATTACH_ID

          • ID of the attachment. It is the connection between the attachment andthe document it belongs to.
            • ATTACH_TYP

            • Type of attachment.
              • ATT_NAME

              • Name of attachment.
                • ATT_DESCR

                • Title (short description) of the attachment.
                  • ATT_LANGU

                  • Language of the attachment.
                    • ATT_SORT

                    • Sort field of the attachment. This term can be searched for in theattribute search.
                      • OBJECT_ID

                      • Object ID of the attachment.
                        • CREATOR_ID

                        • SAPoffice ID of the creator of the attachment.
                          • CREAT_NAME

                          • SAPoffice name of the creator of the attachment. The SAPoffice name isunique client-wide.
                            • CREAT_FNAM

                            • Full name of the creator of the attachment from the address management.
                              • CREAT_DATE

                              • Date the attachment was created.
                                • CREAT_TIME

                                • Time the attachment was created.
                                  • CHANGE_ID

                                  • SAPoffice ID of person who last changed the attachment.
                                    • CHANG_NAME

                                    • SAPoffice name of person who last changed the attachment. The SAPofficename is unique client-wide.
                                      • CHANG_FNAM

                                      • Full name of the person who last changed the attachment from theaddress management.
                                        • CHANG_DATE

                                        • Date of last change.
                                          • CHANG_TIME

                                          • Time of last change.
                                            • OWNER_ID

                                            • SAPoffice ID of owner of attachment.
                                              • OWNER_NAM

                                              • SAPoffice name of owner of attachment. The SAPoffice name is uniqueclient-wide.
                                                • OWNER_FNAM

                                                • Full name of the owner of the attachment from the address management.
                                                  • LAST_ACCES

                                                  • Date attachment was created/changed. Contains the latest of these twovalues.
                                                    • OBJ_EXPDAT

                                                    • Expiration date of the document the attachment is appended to. Thedocument itself cannot expire. However, for each new folder entry ofthe document this date is used for the expiration date of the entry(field EXPIRY_DAT).
                                                      • SENSITIVTY

                                                      • Sensitivity of the document the attachment is appended to.
                                                        A private document can have the following sensitivity:
                                                        'O' : standard, normal sensitivity
                                                        'F' : functional, can be forwarded functionally
                                                        'P' : confidential, not visible to the substitute
                                                        Only sensitivity 'O' is allowed for documents in the shared folders.
                                                        • OBJ_PRIO

                                                        • Recipient priority of the document the attachment is appended to. Thedocument itself does not have a priority. However, for each new folderentry of the document, this value is used for the recipient priority ofthe entry (field PRIORITY).
                                                          • NO_CHANGE

                                                          • If this flag is set ('X'), the attachment can only be changed by theauthor in the shared folders. In the private folders, the author canalso make changes after it has been sent.
                                                            • DOC_SIZE

                                                            • Size of the attachment in bytes. In the case of PC attachments, thesize of the respective file should be entered here, in the case of RAWand SCR attachments, the size is calculated from the "length of thelast line" + "number of remaining lines multiplied by 255".

                                                              Table parameters
                                                              ATTACHMENT_HEADER
                                                              This table must contain the data dependent on the type of attachment.For example, SAPscript documents contain information on the layout setand style, Excel list viewer documents the number of lines and columns,and PC documents their original file name.

                                                              • LINE

                                                              • Requires the type-dependent information of the attachment by the line.
                                                                ATTACHMENT_CONTENT
                                                                This table must contain the actual contents of the attachment.
                                                                • LINE

                                                                • Requires the contents of the attachment by the line.

                                                                  Exceptions
                                                                  ATTACHMENT_NOT_EXIST
                                                                  The specified attachment does not exist. An incorrect ID was probablypassed or the relevant attachment has been deleted.
                                                                  OPERATION_NO_AUTHORIZATION
                                                                  It was not possible to change the specified attachment. This may bebecause it is another user's private attachment or because it is anattachment in a shared folder for which the active user does not have achange authorization. It is also not generally possible to changeattachments of a document which has already been sent.
                                                                  PARAMETER_ERROR
                                                                  An invalid combination of parameter values was passed to the functionmodule. An invalid value was probably entered in a field of thestructure for the attributes of the attachment.
                                                                  X_ERROR
                                                                  An internal error or a database inconsistency occurred.
                                                                  ENQUEUE_ERROR
                                                                  A lock involved in the change process could not be set. Processing isprobably being carried out by another user.

                                                                  Example
                                                                  Changing the names of the attachments of the first document in theoutbox of the active user. The relevant attachments are numberedsequentially. The function module SO_USER_READ_API1 is used todetermine the ID of the outbox, the outbox is read usingSO_FOLDER_READ_API1, and the list of attachments of the documentdetermined provided via SO_DOCUMENT_READ_API1. So that the contents ofeach changed attachment are not lost, they must be read first usingSO_ATTACHMENT_READ_API1.
                                                                  DATA: FOL_CONT LIKE SOFOLENTI1 OCCURS 20 WITH HEADER LINE.
                                                                  DATA: ATTLIST LIKE SOATTLSTI1 OCCURS 5 WITH HEADER LINE.
                                                                  DATA: OBJHEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
                                                                  DATA: OBJCONT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
                                                                  DATA: USER_DATA LIKE SOUDATAI1.
                                                                  DATA: ATT_CHNG LIKE SOATTCHGI1.
                                                                  DATA: ATT_DATA LIKE SOATTINFI1.
                                                                  DATA: ATTACHMENT_COUNTER(2).
                                                                  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'
                                                                  IMPORTING
                                                                  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.
                                                                  LOOP AT FOL_CONT WHERE OBJ_TYPE = 'RAW' OR OBJ_TYPE = 'SCR'.
                                                                  CALL FUNCTION 'SO_DOCUMENT_READ_API1'
                                                                  EXPORTING
                                                                  DOCUMENT_ID = FOL_CONT-DOC_ID
                                                                  TABLES
                                                                  ATTACHMENT_LIST = ATTLIST
                                                                  EXCEPTIONS
                                                                  OTHERS = 1.
                                                                  IF SY-SUBRC <> 0.
                                                                  WRITE: / 'Document found could not be read !'.
                                                                  EXIT.
                                                                  ENDIF.
                                                                  ATTACHMENT_COUNTER = 0.
                                                                  LOOP AT ATTLIST.
                                                                  ADD 1 TO ATTACHMENT_COUNTER.
                                                                  CALL FUNCTION 'SO_ATTACHMENT_READ_API1'
                                                                  EXPORTING
                                                                  ATTACHMENT_ID = ATTLIST-ATTACH_ID
                                                                  IMPORTING
                                                                  ATTACHMENT_DATA = ATT_DATA
                                                                  TABLES
                                                                  ATTACHMENT_HEADER = OBJHEAD
                                                                  ATTACHMENT_CONTENT = OBJCONT
                                                                  EXCEPTIONS
                                                                  OTHERS = 1.
                                                                  IF SY-SUBRC <> 0.
                                                                  WRITE: / 'Attachment', ATTLIST-ATT_DESCR,
                                                                  'could not be read !'.
                                                                  CONTINUE.
                                                                  ENDIF.
                                                                  MOVE-CORRESPONDING ATT_DATA TO ATT_CHNG.
                                                                  ATT_CHNG-OBJ_NAME = 'ANLAGE &'.
                                                                  REPLACE & WITH ATTACHMENT_COUNTER INTO ATT_CHNG.
                                                                  CALL FUNCTION 'SO_ATTACHMENT_UPDATE_API1'
                                                                  EXPORTING
                                                                  ATTACHMENT_ID = FOL_CONT-ATTACH_ID
                                                                  ATTACHMENT_DATA = ATT_CHNG
                                                                  TABLES
                                                                  ATTACHMENT_HEADER = OBJHEAD
                                                                  ATTACHMENT_CONTENT = OBJCONT
                                                                  EXCEPTIONS
                                                                  OTHERS = 1.
                                                                  IF SY-SUBRC <> 0.
                                                                  WRITE: / 'Attachment', ATTLIST-ATT_DESCR,
                                                                  'could not be changed !'.
                                                                  CONTINUE.
                                                                  ENDIF.
                                                                  WRITE: / 'Name of attachment', ATTLIST-ATT_DESCR,
                                                                  'was changed !'.
                                                                  ENDLOOP.
                                                                  IF SY-SUBRC <> 0.
                                                                  WRITE: / 'Document found does not have any attachments !'.
                                                                  ENDIF.
                                                                  EXIT.
                                                                  ENDLOOP.
                                                                  IF SY-SUBRC <> 0.
                                                                  WRITE: / 'No RAW or SCR documents in the outbox !'.
                                                                  ENDIF.

                                                                  Further information
                                                                  Information on calling the function modules SO_USER_READ_API1,SO_FOLDER_READ_API1, SO_DOCUMENT_READ_API1 and SO_ATTACHMENT_READ_API1can be found in the documentation of the respective function modules.