Skip to Content
Technical Articles
Author's profile photo Chau Nguyen Phuc

Read data from attachment List

1.Introduction
Normally, we use READ_TEXT to read data text from header or item. But in some case, specially in Fiori app, text data will be saved in attachment list.
So, how to read data from attachment List?
Don’t worry, I will show you step by step to get data by using abap program

2.Check data in SAP

Suppose we have a FI document as follows

and I created note in attachment list

Please note that: If you want create new note in attachment list, please click create.

Then, you can see note is displayed as below, it includes title and content

You can check data in table SRGBTBREL.

Because this is FI document, so Object Type is BKPF, and we are using note in attachment list, Ref Type is Note as well.

Instance ID is follow by format: <Company Code> + <Document_ID> + <Fiscal Year>

3.ABAP program

We will use function module SO_DOCUMENT_READ_API1 to get data from attachment list

*Declare data
TYPES:
   BEGIN OF TY_LINE,
     INSTID_B TYPE SOFOLENTI1-DOC_ID,
   END OF TY_LINE.
DATA:
  L_DATA     TYPE SOFOLENTI1,
  L_TEXT     TYPE SO_TEXT255,
  L_TBL_LINE TYPE TABLE OF TY_LINE,
  L_DOCID    TYPE SOFOLENTI1-DOC_ID,
  LT_CONTENT TYPE TABLE OF SOLISTI1.

FIELD-SYMBOLS:
  <L_WA_TEXT>  TYPE TY_LINE,
  <LS_CONTENT> TYPE SOLISTI1.


*fetch data from SRGBTBREL
SELECT INSTID_B FROM SRGBTBREL
       WHERE TYPEID_A = 'BKPF'
       AND RELTYPE = 'NOTE'
       AND INSTID_A = 'C00101000000102021'
       AND CATID_A = 'BO'
       INTO TABLE @L_TBL_LINE
       UP TO 1 ROWS.

LOOP AT L_TBL_LINE ASSIGNING <L_WA_TEXT>.
  L_DOCID = <L_WA_TEXT>-INSTID_B.
ENDLOOP.

*call function to get text
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
  EXPORTING
    DOCUMENT_ID                = L_DOCID           " ID of folder entry to be viewed
  IMPORTING
    DOCUMENT_DATA              = L_DATA
  TABLES
    OBJECT_CONTENT             = LT_CONTENT             " Document Content
  EXCEPTIONS
    DOCUMENT_ID_NOT_EXIST      = 1                " Specified folder entry does not exist
    OPERATION_NO_AUTHORIZATION = 2                " No authorization to view folder entry
    X_ERROR                    = 3                " Internal error or database inconsistency
    OTHERS                     = 4.
IF SY-SUBRC = 0.
  WRITE:'TITLE IS: ', L_DATA-obj_descr,/.

  WRITE:'CONTENT IS: '.
  LOOP AT LT_CONTENT ASSIGNING <LS_CONTENT>.
    L_TEXT = <LS_CONTENT>-LINE.
    WRITE:L_TEXT,/.
  ENDLOOP.
ENDIF.

and data will be fetched in report

data%20display

This is a simple ways to get data from attachment List. I hope this article will provide the background knowledge so that you can deal with the problems you encounter in the future

Hope this help!!

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.