Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Function for Adding Attachment to invoice post.

Former Member
0 Kudos

I have a report to read txt files, and post vendor or customer invoice documents with BAPI_ACC_DOCUMENT_POST.

now with the txt file i have a pdf file to attach .

how can i do that?

thanks ,

pd.: sorry my english.

1 REPLY 1

Former Member
0 Kudos

Hi,

Don´t know if this is what you want..but i had put some attachments using this code...


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.

and


    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.

This is just a scratch but i think it will help..