Skip to Content
author's profile photo Former Member
Former Member

Send e SAP office with attachments

Hy

I'm running on 46.C

I want to send a SAP office with attacments that are on the client machine

by a function module

Do you know any Function

that does this?

Thank

Domenico

Add comment
10|10000 characters needed characters exceeded

1 Answer

  • Posted on Dec 15, 2003 at 07:10 PM

    In the past I have just used CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD to read the binary file from the frontend to an internal table. We will eventually call SO_NEW_DOCUMENT_ATT_SEND_API1. The attributes about this file can fill a table of type sopcklsti1 and be passed to parameter packing_list. The binary data that was read in gets copied to a table of type SOLISTI1 and passed into parameter contents_bin. The following is a sinipet of code that does this to give you a better example. In this example we can upload one or many files in a loop. All the binary data is stored together in the single binary table. It is the packing list that tells the SAP function module how to break this up into its original components.

    ...Some Loop of a list of files

    ****UPLOAD THE FILE

    call method cl_gui_frontend_services=>gui_upload

    exporting

    filename = filename

    filetype = 'BIN'

    * HAS_FIELD_SEPARATOR = SPACE

    * HEADER_LENGTH = 0

    * IMPORTING

    * FILELENGTH =

    * HEADER =

    changing

    data_tab = html_tab[]

    exceptions

    file_open_error = 1

    file_read_error = 2

    no_batch = 3

    gui_refuse_filetransfer = 4

    invalid_type = 5

    no_authority = 6

    unknown_error = 7

    bad_data_format = 8

    header_not_allowed = 9

    separator_not_allowed = 10

    header_too_long = 11

    unknown_dp_error = 12

    access_denied = 13

    dp_out_of_memory = 14

    disk_full = 15

    dp_timeout = 16

    others = 17.

    if sy-subrc ne 0.

    message i010 with filename.

    else.

    filename_len = strlen( filename ).

    ****PULL THE EXTENTION OFF THE FILE

    filename_len = filename_len - 3.

    move filename+filename_len(3) to extention.

    if sy-subrc = 0.

    clear fullname.

    clear splitname.

    ****PULL THE FILENAME OUT OF THE FULL PATH

    move filename to fullname.

    call function 'SO_SPLIT_FILE_AND_PATH'

    exporting

    full_name = fullname

    importing

    stripped_name = splitname

    exceptions

    x_error = 1

    others = 2.

    describe table html_tab lines tab_lines.

    move splitname to objhead.

    condense objhead no-gaps.

    append objhead.

    if body_counter is initial.

    add 1 to body_counter.

    endif.

    ****LOAD THE ATTACHMENT INTO THE PACKING LIST OF THE EMAIL

    objpack-transf_bin = 'X'.

    objpack-head_start = body_counter.

    objpack-head_num = 1.

    objpack-body_start = body_counter.

    objpack-body_num = tab_lines.

    objpack-doc_type = extention.

    objpack-obj_name = objhead.

    move objhead to

    objpack-obj_descr.

    body_counter = body_counter + tab_lines.

    objpack-doc_size = tab_lines * 255.

    append objpack.

    loop at html_tab.

    move html_tab to attc_tab.

    append attc_tab.

    endloop.

    endif.

    endif.

    .... End the Loop of the list of files.

    ****SEND THE EMAIL TO SAP OFFICE FOR OUTPUT PROCESSING

    call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    exporting

    document_data = doc_chng

    put_in_outbox = 'X'

    * IMPORTING

    * SENT_TO_ALL =

    * NEW_OBJECT_ID =

    tables

    packing_list = objpack

    object_header = objhead

    contents_bin = attc_tab

    contents_txt = objtxt

    * CONTENTS_HEX =

    * OBJECT_PARA =

    * OBJECT_PARB =

    receivers = reclist

    exceptions

    too_many_receivers = 1

    document_not_sent = 2

    document_type_not_exist = 3

    operation_no_authorization = 4

    parameter_error = 5

    x_error = 6

    enqueue_error = 7

    others = 8

    Add comment
    10|10000 characters needed characters exceeded

    • Actually the example code is used to process 1 or more file attachements. All you would have to do is process this block within a loop that has a list of filenames. I have two lines in the code that begin with .... that show where this loop would begin and end. All the binary data gets concatenated together into a single table. That is why you have the packing list table (OBJPACK in this example). This tell the SAP processing program how to break up this single table back into the multiple attachments. For every attchment you have a new record in the objpack that tells you the number of line in the binary table that belong to that attachment.