Skip to Content
Former Member
Oct 25, 2005 at 02:50 PM

Problem with attaching file to Sales Order



In my company we have the possibility to attach files to sales orders, e.g. pdf files with the printing details.

These files are added by the GUI user, this works fine.

Now we have an extra order creation stream in which a pdf file has to be added to the SO without user interaction.

I found a helpful link ( /people/rammanohar.tiwari/blog/2005/10/10/generic-object-services-gos--in-background )

This program creates URL links with no problem, but the file generation is not implemented yet.

I tried to add the file functions to his sample report but still have one problem. The file is uploaded, but not reported as a PDF file in sap. If I select the created attachment SAP allows only the saving of the attachment. After saving the created file is a good PDF file, it opens with PDF-viewers.

Why does SAP not know this is a PDF file and report it as such (and open the pdf viewer when selected).

Thanks, Frank.


REPORT  zzfb_brc                                .
* Written By : Ram Manohar Tiwari
* Function   : We need to maintain links between Business Object and
*              the attachment.Attachment document is basiclally a
*              business object of type 'MESSAGE'.In order to maintain
*              links, first the attachment will be crated as Business
*              Object of type 'MESSAGE' using Message.Create method.
*              Need to check if we can also use FM
*              'SO_DOC_INSERT_WITH_ORIG_API1' or SO_OBJECT_INSERT rather
*              than using Message.Create method.
* I took this program and removed all the parts for adding URL's and
* notes.

* Include for BO macros
INCLUDE : <cntn01>.
* Load class.
CLASS cl_binary_relation DEFINITION LOAD.
CLASS cl_obl_object      DEFINITION LOAD.

*  Object_a
   p_botype LIKE obl_s_pbor-typeid DEFAULT 'BUS2032',    "SO
   p_bo_id  LIKE obl_s_pbor-instid DEFAULT '0000757830', "example number

*  Object_b
   p_docty  LIKE obl_s_pbor-typeid DEFAULT 'MESSAGE' NO-DISPLAY,
   p_msgtyp LIKE sofm-doctp        DEFAULT 'EXT'     NO-DISPLAY,

*  Relationship
   p_reltyp  LIKE mdoblrel-reltype DEFAULT 'ATTA'.

TYPES: BEGIN OF ty_message_key,
        foltp	TYPE so_fol_tp,
        folyr	TYPE so_fol_yr,
        folno	TYPE so_fol_no,
        doctp	TYPE so_doc_tp,
        docyr	TYPE so_doc_yr,
        docno	TYPE so_doc_no,
        fortp	TYPE so_for_tp,
        foryr	TYPE so_for_yr,
        forno	TYPE so_for_no,
       END OF ty_message_key.

DATA : lv_message_key TYPE ty_message_key.
DATA : lo_message TYPE swc_object.
DATA : lt_doc_content TYPE STANDARD TABLE OF soli-line,
       ls_doc_content TYPE soli-line.

* Create an initial instance of BO 'MESSAGE' - to call the
* instance-independent method 'Create'.
swc_create_object lo_message 'MESSAGE' lv_message_key.

* Upload the pdf file, for now from the frontend, in the future from
* the server.
*  dsn(40) TYPE C VALUE '/usr/sap/trans/convert/1.pdf', "server location
l_lines TYPE i. "filelenght

    filename   = 'c:t1.pdf'
    filetype   = 'BIN'
    filelength = l_lines
    data_tab   = lt_doc_content.
* no exceptions, the file is there in this example

break brouwersf.

** the coding for the server input, for later
*IF sy-subrc <> 0.
*  EXIT.
*READ DATASET dsn INTO ls_doc_content.
*WHILE sy-subrc EQ 0.
*  APPEND ls_doc_content TO lt_doc_content.
*  READ DATASET dsn INTO ls_doc_content.
*CLEAR ls_doc_content.

* define container to pass the parameter values to the method call
* in next step.
swc_container lt_message_container.
* Populate container with parameters for method
swc_set_element lt_message_container 'DOCUMENTTITLE' 'Title'.
swc_set_element lt_message_container 'DOCUMENTLANGU' 'E'.
swc_set_element lt_message_container 'NO_DIALOG'     'X'.
swc_set_element lt_message_container 'DOCUMENTNAME' p_docty.
swc_set_element lt_message_container 'DOCUMENTTYPE' p_msgtyp.

swc_set_element lt_message_container 'DocumentSize'    l_lines.
swc_set_element lt_message_container 'DocumentContent' lt_doc_content.

swc_call_method lo_message 'CREATE' lt_message_container.

* Refresh to get the reference of create 'MESSAGE' object for attachment
swc_refresh_object lo_message.

* Get Key of new object
swc_get_object_key lo_message lv_message_key.

* Now we have attachment as a business object instance. We can now
* attach it to our main business object instance.

* Create main BO object_a
DATA: lo_is_object_a TYPE sibflporb.

lo_is_object_a-instid = p_bo_id.
lo_is_object_a-typeid = p_botype.
lo_is_object_a-catid  = 'BO'.

* Create attachment BO object_b
DATA: lo_is_object_b TYPE sibflporb.

lo_is_object_b-instid = lv_message_key.
lo_is_object_b-typeid = p_docty.
lo_is_object_b-catid  = 'BO'.

CALL METHOD cl_binary_relation=>create_link
    is_object_a = lo_is_object_a
    is_object_b = lo_is_object_b
    ip_reltype  = p_reltyp.

* Check if everything OK...who cares!!