Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member186052
Active Participant

The business documents like Purchase orders/ Purchase requisitions/Material master/ Sales orders can have service attachments stored in the documents.

The list of service attachments saved for this document will be shown when we hit this icon.

We can open this attachments/print/email/fax... based on the requirement.

But if we want to do the same using a report, we have to know how to extract these documents based on the document number.

This is how we do it..

First we need to call the below method

cl_binary_relation=>read_links

CALL METHOD cl_binary_relation=>read_links

         EXPORTING

           is_object           = lo_is_object_a

           it_relation_options = lt_rel

         IMPORTING

           et_links            = lt_links.

the first parameter

lo_is_object_a should be of type declared as below.

DATA: lo_is_object_a TYPE sibflporb,

We should populate below fields into the lo_is_object_a.

   lo_is_object_a-typeid = p_botype.

  lo_is_object_a-catid = 'BO'.

The second parameter lt_rel.

DATA: lt_rel TYPE obl_t_relt,

       wa_rel LIKE LINE OF lt_rel.

wa_rel should be populated with below fields and then should be appended to the lt_rel  as shown below.

wa_rel-sign = 'I'.

wa_rel-option = 'EQ'.

wa_rel-low = p_reltyp.   "the value of p_reltype = 'ATTA' which means it fetches attachments."

APPEND wa_rel TO lt_rel.

The p_reltype is for type breltyp-reltype.

We also need other variables like

  p_botype LIKE borident-objtype,   " Business object ID table TOJTT

p_bo_id  LIKE borident-objkey,    " Document number

The value of the p_botype depends on the type of business document we will be using.

for example: for purchase order we use

p_botype = 'BUS2012'.

The list of business objects and their list is maintained in table TOJTT

the field p_bo_id should be the document number.

Now if it is purchase order then

p_bo_id = wa_ekko-ebeln.  " Consider wa_ekko as ekko structure with some purchase order value.

This po_bo_id value is moved to lo_is_object_a-instid field

lo_is_object_a-instid = p_bo_id..

Once this fields are filled and we call the method

CALL METHOD cl_binary_relation=>read_links

         EXPORTING

           is_object           = lo_is_object_a

           it_relation_options = lt_rel

         IMPORTING

           et_links            = lt_links.

The table lt_links of type obl_t_link, will be filled with the values.

The field instid_b of the above table will have an encrypted value which will help us fetch the document attachments.

We have to check if the typeid_b field of the table is 'MESSAGE' and fetch only records with that value.

now we have to call the function module

SO_DOCUMENT_READ_API1

And the document_id field that we pass to this function module should have the value of it_links-instid_b.

Once the function module is executed we will get the data into either object_content or contents_hex tables of the FM.

The object_content returns the value if the attachment is of 'text' or '.txt' type for all other file types we get the hex data in contents_hex table.

So from below

CALL FUNCTION 'SO_DOCUMENT_READ_API1'

       EXPORTING

         document_id                      = lv_document_id

      IMPORTING

        document_data                    = wa_data

      TABLES

        object_content                   = it_content

        contents_hex                     = it_solix

      EXCEPTIONS

        document_id_not_exist            = 1

        operation_no_authorization       = 2

        x_error                          = 3

        OTHERS                           = 4.

it_content has data if the attachment is text type

it_solix has data if the attachment is non text type and is convertible to hex type.

this table is passed to GUI_DOWNLOAD table to download the file to local desktop and then it can be processed as per the requirement.

If you want to use frontend GUI services on the file you can use the below method

CALL METHOD cl_gui_frontend_services=>execute

           EXPORTING

             document               = gv_path1

             operation              = 'PRINT'

where GV_PATH1 will be the file path.

operation can be any of the frontend GUI services like 'PRINT' or 'OPEN' or 'DELETE' etc.,

Hope this helps.

1 Comment
Labels in this area