Generic Object Services (GOS) Toolbar Part 4 : Get Attachements

By | February 3, 2009 | Generic Object Services (GOS) | 33,746 | 12

Shows how to get the Attachement details attached to the GOS toolbar

You can find all of these discussions at Tutorials > Generic Object Services (GOS).

Today, we will see how to get the attachement details.

We will use the static method READ_LINKS from the class CL_BINARY_RELATION. We have to pass what kind of the objects we want to get back from the all the attachements like Notes, Attachment, External document etc.

This code will show how to get the NOTES attachments from the GOS toolbar.

*&---------------------------------------------------------------------*
*& Report  ZTEST_NP_GOS_ATT
*&
*&---------------------------------------------------------------------*
*& Read the GOS attachments
*&
*&---------------------------------------------------------------------*
*
REPORT  ztest_np_gos_note.
*
* Selection Screen
PARAMETERSp_matnr TYPE mara-matnr.
*
*
START-OF-SELECTION.
*
*---------
* Get all the NOTE attached to Business object
*---------
*
* buseinss object key
  DATAgs_lpor TYPE sibflporb.
*
  gs_lpor-instid p_matnr.
  gs_lpor-typeid 'BUS1001006'.
  gs_lpor-catid  'BO'.
*
* attachment type selection
  DATAlt_relat TYPE obl_t_relt,
        la_relat LIKE LINE OF lt_relat.
*
  la_relat-sign 'I'.
  la_relat-option 'EQ'.
  la_relat-low 'NOTE'"For notes
  APPEND la_relat TO lt_relat.
*
* Read the links
  DATAt_links TYPE obl_t_link,
        la_links LIKE LINE OF t_links.
*
  DATAlo_root TYPE REF TO cx_root.
*
  TRY.
      CALL METHOD cl_binary_relation=>read_links
        EXPORTING
          is_object           gs_lpor
          it_relation_options lt_relat
        IMPORTING
          et_links            t_links.
    CATCH cx_root INTO lo_root.
  ENDTRY.
*

To test this program:
Go to MM02
Enter Material and go to Basic data view 1
In GOS toolbar, Create > Note

Now, run the above program to get the attachment details.

The same way we can select attachements by adding the relation option ATTA.
Like:

*&---------------------------------------------------------------------*
  la_relat-sign 'I'.
  la_relat-option 'EQ'.
  la_relat-low 'ATTA'.     "Attachements
  APPEND la_relat TO lt_relat.

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

12 Comments

  • Anonymous

    Hi Naimesh,

    my problems start after I read the List of attachments. I searched for notes and after that I have troubles to display the note exactly like it is displayed in SAP. I tried to use SGOS_NOTE_DISPLAY, but it did’nt work … is this the wrong FM?

    thanks
    Dieter

  • Hello Dieter,

    You asked:
    I tried to use SGOS_NOTE_DISPLAY, but it did’nt work … is this the wrong FM?
    Try to use the FM SO_OBJECT_READ. Check the post http://help-abap.blogspot.com/2009/02/generic-object-services-gos-toolbar_09.html

    Regards,
    Naimesh Patel

  • Hi Naimesh,

    You have been posting wonderful and very useful information about GOS.
    I need help on the below.
    I would like to know the type of document attached wheather PDF, JPG, text file etc. how could i find out for the attachments!
    Ideally i could see these as an icons on the Attachment List window.
    Here my requirement is i need to create a report program which lists title of the attachement and
    type of the attachment.

    Regards
    Lokesh

  • Gautam

    Hi Naimesh:
    Nice blog about GOS….

    Here is what I am trying to do.
    I would like to attach a picture (.GIF) to a Delivery as an attachment using an RFC. I developed a BAPI which would be triggered by an external program. The BAPI works just fine when tested in SE37 and I can see the pictures in the attachment list for the Delivery. But, when I trigger it from my external program, I get a "CNTL_ERROR". After a lot of debugging, I found that the function SO_DOCUMENT_REPOSITORY_MANAGER works only in frontend mode. Can you tell me if there exists a RFC version for the above function. Thanks.

    Gautam

  • Hello Gautam,

    You can try with FMs SO_DOCUMENT_INSERT_API1, SO_DOCUMENT_UPDATE_API1. I haven't used them.

    Regards,
    Naimesh Patel

  • Anonymous

    Naimesh,

    Thanks for the very useful examples.
    I used your code to create attachments for a new BOR object and unique objectID. Now I want to display the attachment list popup in another program.

    BOR object type = 'ZGOS'
    Object key = 'My_unique_key_000000000000…1'

    Your code can get me to the individual attachments for that key.

    I want to display the standard popup list. I want to pop up the entire list of attachments, notes, and URLs so that they can be deleted or added to, by the person looking at the list.

    How do I do that?

    Thanks
    Bruce

  • Hi Naimesh,

    On a related topic, I need to upload a file to the material using a function module/prog. Can you pls help me on how to do this?

  • Khanh Nguyen

    Hi Naimesh,

    Your blog is very helpful to me. Thanks.
    I have a requirement to get the attachment (GOS) from a particular Quality Notification.
    Could you please guide me how to define gs_lpor?

    Thanks,
    Khanh

  • Archana Raje

    Hello Naimesh,

    I want to copy URL link from object to another object ..
    I hve written following code but it is not copying the link
    REPORT ztest_np_copy_gos_att.
    *
    *
    DATA: lt_services TYPE tgos_sels. ” Services table typ
    DATA: ls_service TYPE sgos_sels. ” Services structure type
    DATA: ls_source TYPE sibflporb, ” Source
    ls_target TYPE sibflporb. ” Target
    *
    START-OF-SELECTION.
    *
    * Service needs to be performed
    ls_service-sign = ‘I’.
    ls_service-option = ‘EQ’.
    ls_service-low = ‘URL_CREA’.

    APPEND ls_service TO lt_services.
    *
    * Source
    ls_source-instid = ‘ATESTLNG01’.
    ls_source-typeid = ‘BUS1019’.
    ls_source-catid = ‘BO’.
    *
    * Target
    ls_target-instid = ‘000080032378’.
    ls_target-typeid = ‘BUS2007’.
    ls_target-catid = ‘BO’.
    *
    * Copy the objects between Source and Target
    cl_gos_service_tools=>copy_linked_objects(
    is_source = ls_source
    is_target = ls_target
    it_service_selection = lt_services
    ).
    *
    COMMIT WORK.

  • Naimesh Patel

    Hello Archana,

    It works well for me. I tried moving the URL from one Customer (Object Type: KNA1) to another Customer.

    BUS1019 would have the key by concatenating the values of PLNTY, PLNNR & PLNAL. In your example, the value of Source INSTID looks 1 char off. Please check that.

    If you need to concatenate, use the addition RESPECTING BLANKS of the CONCATENATE.

    CONCATENATE fld1 fld2 fld3 INTO lv_instid RESPECTING BLANKS.
    

    Regards,
    Naimesh Patel

  • gopi

    Hi Naimesh,
    I want to download the attachments from FB03. I tries to replicate ur code but unfortunatley i am using 4.6 version . could u pls help me how to download the attachments for 4.6 version

  • Sudharshan

    Hi Friends,

    I would like to restrict the users from uploading the document using create attachment option while creating PR and PO’s. Can you kindly let me know how to achieve this.

    Rgds,
    SM

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.