<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Function for Adding  Attachment to invoice post. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/function-for-adding-attachment-to-invoice-post/m-p/7796010#M1586653</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Don´t know if this is what you want..but i had put some attachments using this code...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: d_file type RLGRAP-FILENAME,
      d_objkey type borident-objkey.
select single URL from /cockpit/tmime into d_file
  where invoice_guid = E_STR_HEADER-invoice_guid.

CONCATENATE
E_STR_HEADER-SAP_DOC_NO
E_STR_HEADER-FISCAL_YEAR
into d_objkey.
CONDENSE d_objkey.
submit ZSEND_IMAGE
with f_filena = d_file
with d_objkey = d_objkey
and RETURN.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
    IF wa_thdr-fi_mm_flg EQ 'FI'.
      ls_object-objtype = 'BKPF'.
      CONCATENATE wa_thdr-comp_code  wa_thdr-sap_doc_no INTO ls_object-objkey SEPARATED BY space.

    ELSEIF wa_thdr-fi_mm_flg EQ 'MM'.
      ls_object-objtype = 'BUS2081'.
      ls_object-objkey  = wa_thdr-sap_doc_no.
    ENDIF.

    CALL FUNCTION 'WS_UPLOAD'
      EXPORTING
        filename            = f_filename
        filetype            = 'BIN'
      TABLES
        data_tab            = it_content
      EXCEPTIONS
        conversion_error    = 1
        file_open_error     = 2
        file_read_error     = 3
        invalid_table_width = 4
        invalid_type        = 5
        no_batch            = 6
        unknown_error       = 7
        OTHERS              = 8.

    CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'
      EXPORTING
        it_contents_bin = it_content[]
      IMPORTING
        et_contents_bin = it_content[].

    CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
      EXPORTING
        region    = 'B'"'Q'
      IMPORTING
        folder_id = ls_fol_id
      EXCEPTIONS
        OTHERS    = 1.

    ls_obj_data-objsns = 'O'.
    ls_obj_data-objla = sy-langu.
    CONCATENATE 'Anexo - ' space
                wa_thdr-zeic_data_dig+6(2) '.'
                wa_thdr-zeic_data_dig+4(2) '.'
                wa_thdr-zeic_data_dig(4)
                INTO ls_obj_data-objdes.

    lv_offset = STRLEN( f_filename ) - 3.
    ls_obj_data-file_ext = f_filename+lv_offset(3).
    ls_obj_data-objlen = LINES( it_content ) * 255.

*ALI          X   X Documento de lista ABAP
*ARC          X     Objeto de arquivo (Image)
*BCS              X Arquivo documento externo
*BIN          X     Documento binário
*DLI          X     Lista de distribuição
*EXT          X X   Documento PC
*FOL          X     Pasta
*GRA          X   X Gráfico SAP
*OBJ          X     Business object
*OFO              X Pasta de objeto
*OTF              X Documento OTF
*R3I              X IDoc
*RAW  X       X     Documento editor SAP
*SCR          X     Documento SAPscript
*URL                Link para Inter/Intranet
*WIM              X Work item
*XXL          X   X Documento para Listviewer


    CALL FUNCTION 'SO_OBJECT_INSERT'
      EXPORTING
        folder_id             = ls_fol_id
        object_type           = 'EXT'
        object_hd_change      = ls_obj_data
      IMPORTING
        object_id             = ls_obj_id
      TABLES
        objhead               = it_objhead
        objcont               = it_content
      EXCEPTIONS
        active_user_not_exist = 35
        folder_not_exist      = 6
        object_type_not_exist = 17
        owner_not_exist       = 22
        parameter_error       = 23
        OTHERS                = 1000.

    IF sy-subrc = 0 AND ls_object-objkey IS NOT INITIAL.
      ls_folmem_k-foltp = ls_fol_id-objtp.
      ls_folmem_k-folyr = ls_fol_id-objyr.
      ls_folmem_k-folno = ls_fol_id-objno.
      ls_folmem_k-doctp = ls_obj_id-objtp.
      ls_folmem_k-docyr = ls_obj_id-objyr.
      ls_folmem_k-docno = ls_obj_id-objno.
      lv_ep_note = ls_folmem_k.
      ls_note-objtype = 'MESSAGE'.
      ls_note-objkey = lv_ep_note.
      CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
        EXPORTING
          obj_rolea    = ls_object
          obj_roleb    = ls_note
          relationtype = 'ATTA'
        EXCEPTIONS
          OTHERS       = 1.
      DELETE FROM  zeic_enviar_wf WHERE invoice_guid = wa_wk-invoice_guid.
    ELSE.
      wa_wk-erro_img_doc = 'X'.
      MODIFY it_wk FROM wa_wk INDEX d_tabix.
    ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is just a scratch but i think it will help..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Apr 2011 14:01:39 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2011-04-08T14:01:39Z</dc:date>
    <item>
      <title>Function for Adding  Attachment to invoice post.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/function-for-adding-attachment-to-invoice-post/m-p/7796009#M1586652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a report to read txt files, and post vendor or customer invoice documents with BAPI_ACC_DOCUMENT_POST.&lt;/P&gt;&lt;P&gt;now with the txt file i have a pdf file to attach . &lt;/P&gt;&lt;P&gt;how can i do that?  &lt;/P&gt;&lt;P&gt;thanks , &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pd.: sorry my english.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Apr 2011 12:13:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/function-for-adding-attachment-to-invoice-post/m-p/7796009#M1586652</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-08T12:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: Function for Adding  Attachment to invoice post.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/function-for-adding-attachment-to-invoice-post/m-p/7796010#M1586653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Don´t know if this is what you want..but i had put some attachments using this code...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: d_file type RLGRAP-FILENAME,
      d_objkey type borident-objkey.
select single URL from /cockpit/tmime into d_file
  where invoice_guid = E_STR_HEADER-invoice_guid.

CONCATENATE
E_STR_HEADER-SAP_DOC_NO
E_STR_HEADER-FISCAL_YEAR
into d_objkey.
CONDENSE d_objkey.
submit ZSEND_IMAGE
with f_filena = d_file
with d_objkey = d_objkey
and RETURN.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
    IF wa_thdr-fi_mm_flg EQ 'FI'.
      ls_object-objtype = 'BKPF'.
      CONCATENATE wa_thdr-comp_code  wa_thdr-sap_doc_no INTO ls_object-objkey SEPARATED BY space.

    ELSEIF wa_thdr-fi_mm_flg EQ 'MM'.
      ls_object-objtype = 'BUS2081'.
      ls_object-objkey  = wa_thdr-sap_doc_no.
    ENDIF.

    CALL FUNCTION 'WS_UPLOAD'
      EXPORTING
        filename            = f_filename
        filetype            = 'BIN'
      TABLES
        data_tab            = it_content
      EXCEPTIONS
        conversion_error    = 1
        file_open_error     = 2
        file_read_error     = 3
        invalid_table_width = 4
        invalid_type        = 5
        no_batch            = 6
        unknown_error       = 7
        OTHERS              = 8.

    CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'
      EXPORTING
        it_contents_bin = it_content[]
      IMPORTING
        et_contents_bin = it_content[].

    CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
      EXPORTING
        region    = 'B'"'Q'
      IMPORTING
        folder_id = ls_fol_id
      EXCEPTIONS
        OTHERS    = 1.

    ls_obj_data-objsns = 'O'.
    ls_obj_data-objla = sy-langu.
    CONCATENATE 'Anexo - ' space
                wa_thdr-zeic_data_dig+6(2) '.'
                wa_thdr-zeic_data_dig+4(2) '.'
                wa_thdr-zeic_data_dig(4)
                INTO ls_obj_data-objdes.

    lv_offset = STRLEN( f_filename ) - 3.
    ls_obj_data-file_ext = f_filename+lv_offset(3).
    ls_obj_data-objlen = LINES( it_content ) * 255.

*ALI          X   X Documento de lista ABAP
*ARC          X     Objeto de arquivo (Image)
*BCS              X Arquivo documento externo
*BIN          X     Documento binário
*DLI          X     Lista de distribuição
*EXT          X X   Documento PC
*FOL          X     Pasta
*GRA          X   X Gráfico SAP
*OBJ          X     Business object
*OFO              X Pasta de objeto
*OTF              X Documento OTF
*R3I              X IDoc
*RAW  X       X     Documento editor SAP
*SCR          X     Documento SAPscript
*URL                Link para Inter/Intranet
*WIM              X Work item
*XXL          X   X Documento para Listviewer


    CALL FUNCTION 'SO_OBJECT_INSERT'
      EXPORTING
        folder_id             = ls_fol_id
        object_type           = 'EXT'
        object_hd_change      = ls_obj_data
      IMPORTING
        object_id             = ls_obj_id
      TABLES
        objhead               = it_objhead
        objcont               = it_content
      EXCEPTIONS
        active_user_not_exist = 35
        folder_not_exist      = 6
        object_type_not_exist = 17
        owner_not_exist       = 22
        parameter_error       = 23
        OTHERS                = 1000.

    IF sy-subrc = 0 AND ls_object-objkey IS NOT INITIAL.
      ls_folmem_k-foltp = ls_fol_id-objtp.
      ls_folmem_k-folyr = ls_fol_id-objyr.
      ls_folmem_k-folno = ls_fol_id-objno.
      ls_folmem_k-doctp = ls_obj_id-objtp.
      ls_folmem_k-docyr = ls_obj_id-objyr.
      ls_folmem_k-docno = ls_obj_id-objno.
      lv_ep_note = ls_folmem_k.
      ls_note-objtype = 'MESSAGE'.
      ls_note-objkey = lv_ep_note.
      CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
        EXPORTING
          obj_rolea    = ls_object
          obj_roleb    = ls_note
          relationtype = 'ATTA'
        EXCEPTIONS
          OTHERS       = 1.
      DELETE FROM  zeic_enviar_wf WHERE invoice_guid = wa_wk-invoice_guid.
    ELSE.
      wa_wk-erro_img_doc = 'X'.
      MODIFY it_wk FROM wa_wk INDEX d_tabix.
    ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is just a scratch but i think it will help..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Apr 2011 14:01:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/function-for-adding-attachment-to-invoice-post/m-p/7796010#M1586653</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-08T14:01:39Z</dc:date>
    </item>
  </channel>
</rss>

