SAP Function SO_ATTACHMENT_INSERT_API1 - SAPoffice: Create attachment using RFC

Parameter Reference Type Length Default Optional Text
ATTACHMENT_DATA SOATTCHGI1 u 75 Attributes of New Attachment
ATTACHMENT_TYPE SOODK-OBJTP C 3 Document Class for Attachment
DOCUMENT_ID SOFOLENTI1-DOC_ID C 46 ID of Document for Which Attachment Is to Be Created

Parameter Reference Type Length Text
ATTACHMENT_INFO SOATTINFI1 u 407 Complete Attributes After Creation

Parameter Reference Length Optional Text
ATTACHMENT_CONTENT SOLISTI1 255 Attachment Contents
ATTACHMENT_HEADER SOLISTI1 255 Header Data for Attachment (Spec.Header)
CONTENTS_HEX SOLIX 255 X Attachment Contents (Binary)

Exception Text
ATTACHMENT_TYPE_NOT_EXIST Document Type for Attachment Does Not Exist
DOCUMENT_NOT_EXIST Specified Document Does Not Exist
ENQUEUE_ERROR Required Locks Could Not Be Set
OPERATION_NO_AUTHORIZATION No Authorization to Create Attachment
PARAMETER_ERROR Invalid Combination of Parameter Values
X_ERROR Internal Error or Database Inconsistency

Functionality
This function can be used to create a new attachment for an existingdocument.

Import parameters
DOCUMENT_ID
ID of a folder entry of the document which is to have the attachment.It is the connection between the document and the folder in which it iscontained.
ATTACHMENT_TYPE
Type of attachment. Apart from folders ('FOL') and distribution lists('DLI'), all types are allowed.
ATTACHMENT_DATA
This structure must contain the new attributes of the new attachment.

  • 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 newly createdattachment.

          • ATTACH_ID

          • ID of the attachment. This 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 the owner of the attachment.
                                              • OWNER_NAM

                                              • SAPoffice name of the owner of the attachment. The SAPoffice name isunique client-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 the 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
                                                                  DOCUMENT_NOT_EXIST
                                                                  The folder entry specified does not exist. An incorrect ID was probablypassed or the relevant folder entry deleted.
                                                                  ATTACHMENT_TYPE_NOT_EXIST
                                                                  The specified type of attachment does not exist or is not allowed. Itis not possible to have folders ('FOL') or distribution lists ('DLI')as attachments.
                                                                  OPERATION_NO_AUTHORIZATION
                                                                  It was not possible to create the attachment. The reason for this maybe that the document related to the attachment is another user'sprivate document or it is a document in a shared folder for which theactive user does not have a change authorization. It is also notgenerally possible to append an attachment to a document which hasalready 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.
                                                                  ENQUEUE_ERROR
                                                                  A lock involved in the create process could not be set. Processing isprobably being carried out by another user.

                                                                  Example
                                                                  Create a RAW attachment for the document last created in the outbox ofthe active user. The function module SO_USER_READ_API1 is used todetermine the ID of the outbox, the contents of the outbox are readusing the function module SO_FOLDER_READ_API1.
                                                                  DATA: FOL_CONT LIKE SOFOLENTI1 OCCURS 20 WITH HEADER LINE.
                                                                  DATA: ATTHEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
                                                                  DATA: ATTCONT LIKE SOLISTI1 OCCURS 5 WITH HEADER LINE.
                                                                  DATA: USER_DATA LIKE SOUDATAI1.
                                                                  DATA: ATT_CHNG LIKE SOATTCHGI1.
                                                                  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.
                                                                  SORT FOL_CONT BY CREAT_DATE DESCENDING CREAT_TIME DESCENDING.
                                                                  READ FOL_CONT INDEX 1.
                                                                  IF SY_SUBRC <> 0.
                                                                  WRITE: / 'No documents in the outbox !'.
                                                                  EXIT.
                                                                  ENDIF.
                                                                  ATT_CHNG-OBJ_NAME = 'ANLAGE'.
                                                                  ATT_CHNG-OBJ_DESCR = 'A new attachment'.
                                                                  ATT_CHNG-OBJ_LANGU = SY-LANGU.
                                                                  ATTCONT = 'Only single-line, but better than nothing !'.
                                                                  APPEND ATTCONT.
                                                                  ATT_CHNG-DOC_SIZE = STRLEN( ATTCONT ).
                                                                  CALL FUNCTION 'SO_ATTACHMENT_INSERT_API1'
                                                                  EXPORTING
                                                                  DOCUMENT_ID = FOL_CONT-DOC_ID
                                                                  ATTACHMENT_DATA = ATT_CHNG
                                                                  ATTACHMENT_TYPE = 'RAW'
                                                                  TABLES
                                                                  ATTACHMENT_HEADER = ATTHEAD
                                                                  ATTACHMENT_CONTENT = ATTCONT
                                                                  EXCEPTIONS
                                                                  PARAMETER_ERROR = 4
                                                                  OTHERS = 99.
                                                                  CASE SY-SUBRC.
                                                                  WHEN 0.
                                                                  WRITE: / 'Attachment for', FOL_CONT-OBJ_DESCR, 'created !'.
                                                                  WHEN 4.
                                                                  WRITE: / FOL_CONT-OBJ_DESCR, 'of type', FOL_CONT-OBJ_TYPE,
                                                                  '- no attachment possible !'.
                                                                  WHEN OTHERS.
                                                                  WRITE: / 'Attachment for', FOL_CONT-OBJ_DESCR,
                                                                  'could not be created !'.
                                                                  ENDCASE.

                                                                  Notes
                                                                  Creating an attachment for a document is dealt with like changing thedocument, this means that it is not possible to create, change, ordelete an attachment after it has been sent. After an attachment hasbeen created or changed, the last change date of the document and allshared folders containing the document are updated.

                                                                  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.

800368Access method 'M' if you use an external storage system