2

Read data from attachment List

 2 years ago
source link: https://blogs.sap.com/2021/10/26/read-data-from-attachment-list/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
October 26, 2021 2 minute read

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

1-67.png

and I created note in attachment list

2-32.png

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

3-27.png

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>

4-27.png

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!!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK