SAP Function SO_ATTACHMENT_READ_API1 - SAPoffice: Read attachment using RFC

Parameter Reference Type Length Default Optional Text
ATTACHMENT_ID SOATTLSTI1-ATTACH_ID C 63 ID of attachment to be viewed

Parameter Reference Type Length Text
ATTACHMENT_DATA SOATTINFI1 u 407 Complete attributes of viewed attachment

Parameter Reference Length Optional Text
ATTACHMENT_CONTENT SOLISTI1 255 X Attachment contents
ATTACHMENT_HEADER SOLISTI1 255 X Header data for attachment (spec.header)
CONTENTS_HEX SOLIX 255 X Binary Content

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

Functionality
This function module returns all information on an attachment.
This includes:

  • the attributes of the attachment (e.g. name, description, creator, date
  • created, priority, expiration date, etc.)
    • the contents of the attachment

    • the type-specific information (e.g. the layout set and style used in
    • SAPscript documents)

      Import parameters
      ATTACHMENT_ID
      ID of the attachment to be read. It is the connection between theattachment and the document it belongs to.

      Export parameters
      ATTACHMENT_DATA
      This structure contains the complete attributes of the attachment read.

      • 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 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
                                                              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 read the specified attachment. The reason forthis may be that it is another user's private attachment or it is anattachment for a document in a shared group folder for which the activeuser does not have an access authorization.
                                                              PARAMETER_ERROR
                                                              An invalid combination of parameter values was passed to the functionmodule.
                                                              X_ERROR
                                                              An internal error or a database inconsistency occurred.
                                                              ENQUEUE_ERROR
                                                              A lock involved in the read process could not be set. Processing isprobably being carried out by another user.

                                                              Example
                                                              Output of the contents of the attachment for the newest document in theinbox of the active user. The function module SO_USER_READ_API1 is usedto determine the ID of the inbox, the contents of the inbox are readusing SO_FOLDER_READ_API1. The list of attachments of the document lastreceived is read by SO_DOCUMENT_READ_API1.
                                                              DATA: FOL_CONT LIKE SOFOLENTI1 OCCURS 20 WITH HEADER LINE.
                                                              DATA: ATTLIST LIKE SOATTLSTI1 OCCURS 5 WITH HEADER LINE.
                                                              DATA: ATTHEAD LIKE SOLISTI1 OCCURS 5 WITH HEADER LINE.
                                                              DATA: ATTCONT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
                                                              DATA: USER_DATA LIKE SOUDATAI1.
                                                              DATA: FILTER LIKE SOFILTERI1.
                                                              DATA: ENTRIES LIKE SY-TABIX.
                                                              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.
                                                              SORT FOL_CONT BY REC_DATE DECENDING REC_TIME DECENDING.
                                                              READ TABLE FOL_CONT INDEX 1.
                                                              IF SY-SUBRC <> 0.
                                                              WRITE: / 'No documents in inbox !'.
                                                              EXIT.
                                                              ENDIF.
                                                              FILTER-NO_CONTENT = 'X'.
                                                              CALL FUNCTION 'SO_DOCUMENT_READ_API1'
                                                              EXPORTING
                                                              DOCUMENT_ID = FOL_CONT-DOC_ID
                                                              FILTER = FILTER
                                                              TABLES
                                                              ATTACHMENT_LIST = ATTLIST
                                                              EXCEPTIONS
                                                              OTHERS = 1.
                                                              IF SY-SUBRC <> 0.
                                                              WRITE: / 'Error reading document', FOL_CONT-OBJ_DESCR, '!'.
                                                              EXIT.
                                                              ENDIF.
                                                              DESCRIBE TABLE ATTLIST LINES ENTRIES.
                                                              IF ENTRIES = 0.
                                                              WRITE: / 'No attachments for document', FOL_CONT-OBJ_DESCR, '!'.
                                                              EXIT.
                                                              ENDIF.
                                                              LOOP AT ATTLIST.
                                                              CALL FUNCTION 'SO_ATTACHMENT_READ_API1'
                                                              EXPORTING
                                                              ATTACHMENT_ID = ATTLIST-ATTACH_ID
                                                              TABLES
                                                              ATTACHMENT_HEADER = ATTHEAD
                                                              ATTACHMENT_CONTENT = ATTCONT
                                                              EXCEPTIONS
                                                              ENQUEUE_ERROR = 5
                                                              OTHERS = 99.
                                                              CASE SY-SUBRC.
                                                              WHEN 0.
                                                              WRITE: / 'Attachment :', ATTLIST-OBJ_NAME, ATTLIST-OBJ_DESCR.
                                                              WRITE: / 'ATTACHMENT_HEADER :'.
                                                              LOOP AT ATTHEAD.
                                                              WRITE: / ATTHEAD-LINE.
                                                              ENDLOOP.
                                                              WRITE: / 'ATTACHMENT_CONTENT :'.
                                                              LOOP AT ATTCONT.
                                                              WRITE: / ATTCONT-LINE.
                                                              ENDLOOP.
                                                              WHEN 5.
                                                              WRITE: / 'Attachment', ATTLIST-OBJ_DESCR, 'currently locked !'.
                                                              WHEN OTHERS.
                                                              WRITE: / 'Error reading attachment', ATTLIST-OBJ_DESCR.
                                                              ENDCASE.
                                                              ENDLOOP.

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