Application Development and Automation 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: 
Read only

Send email with attachment

jayanchembada
Explorer
0 Likes
949

Hi All,

How to send send an email attachment in excel format having more than 255 characters in each record. The total length of all the fields in the attachment is greater than 255 charactes. The function module SO_NEW_DOCUMENT_ATT_SEND_API1 allows maximum 255 character length in one row of the attachment.(CONTENTS_BIN STRUCTURE SOLISTI1) . Is there any other way to send attachment having more than 255 characters in each raw.

The data is not populating in the excel if the record exceeds 255 charactes.

Eg: 0|----


|255

6000001 ABDCSGJJK BGFSDS LTREC GHJGFD JJFDFJIK

Suppose if have some more fields, those data is not populating in the excel since the total length of the record fields exceeds 255 characted. This is because SOLISTI1 structure has only 255 character length.

Please advice.

Regards

Jayan C

Regards

Jayan c

Hi All,

How to send send an email attachment in excel format having more than 255 characters in each record. The total length of all the fields in the attachment is greater than 255 charactes. The function module SO_NEW_DOCUMENT_ATT_SEND_API1 allows maximum 255 character length in one row of the attachment.(CONTENTS_BIN STRUCTURE SOLISTI1) . Is there any other way to send attachment having more than 255 characters in each raw.

The data is not populating in the excel if the record exceeds 255 charactes.

Eg: 0|----


|255

6000001 ABDCSGJJK BGFSDS LTREC GHJGFD JJFDFJIK

Suppose if have some more fields, those data is not populating in the excel since the total length of the record fields exceeds 255 characted. This is because SOLISTI1 structure has only 255 character length.

Please advice.

Regards

Jayan C

Regards

Jayan c

5 REPLIES 5
Read only

Former Member
0 Likes
901

This message was moderated.

Read only

Former Member
0 Likes
901

Hi Jayan,

we have a solution for this check this link..

Here is the code guys:

function z_send_email.

*"----


""Local interface:

*" IMPORTING

*" VALUE(SUBJECT) TYPE STRING

*" VALUE(MESSAGE) TYPE STRING OPTIONAL

*" EXPORTING

*" REFERENCE(RETURN) TYPE BAPIRET2

*" TABLES

*" RECIPIENTS

*" MAILBODY STRUCTURE SOLI OPTIONAL

*" ATTACHMENTS OPTIONAL

*" EXCEPTIONS

*" NO_BODY

*" BCS_ERROR

*"----


----


  • CLASS-DEFINITIONS *

----


data: send_request type ref to cl_bcs.

data: document type ref to cl_document_bcs.

data: sender type ref to if_sender_bcs.

data: recipient type ref to if_recipient_bcs.

data: exception_info type ref to if_os_exception_info,

bcs_exception type ref to cx_bcs.

data: l_dset type string,

l_attach type solix,

l_attname type sood-objdes,

l_attext type soodk-objtp,

l_lines type i,

l_file type string,

wa_attach type solix, " Attachment

l_size type sood-objlen. " Size of Attachmen

----


  • INTERNAL TABLES *

----


data: l_mailtext type soli_tab.

data: i_attach type solix_tab.

if message is initial and mailbody[] is initial.

return-type = 'E'.

return-message = 'No MESSAGE or MAILBODY'.

raise no_body.

endif.

try.

  • Create persistent send request

send_request = cl_bcs=>create_persistent( ).

  • Move the Subject from string to BCS subject type

data: l_subject type so_obj_des.

l_subject = subject.

  • Move the message from string to internal table

if mailbody[] is initial.

call function 'SCMS_STRING_TO_FTEXT'

exporting

text = message

tables

ftext_tab = l_mailtext.

else.

l_mailtext[] = mailbody[].

endif.

  • Create the Document

document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = l_mailtext

i_subject = l_subject ).

  • Add document to send request

call method send_request->set_document( document ).

  • Get sender object

sender = cl_sapuser_bcs=>create( sy-uname ).

  • Add sender

call method send_request->set_sender

exporting

i_sender = sender.

  • Get Recipient Object

data: l_recipient type ad_smtpadr.

loop at recipients into l_recipient.

recipient = cl_cam_address_bcs=>create_internet_address(

l_recipient ).

  • Add recipient with its respective attributes to send request

call method send_request->add_recipient

exporting

i_recipient = recipient.

endloop.

  • Set that you don't need a Return Status E-mail

call method send_request->set_status_attributes

exporting

i_requested_status = 'E'

i_status_mail = 'E'.

*Add attachments

loop at attachments into l_dset.

open dataset l_dset in binary mode for input.

do.

read dataset l_dset into wa_attach.

append wa_attach to i_attach.

if sy-subrc ne 0.

exit.

endif.

clear wa_attach.

enddo.

close dataset l_dset.

describe table i_attach lines l_lines.

l_size = l_lines * 255.

call function 'SO_SPLIT_FILE_AND_PATH'

exporting

full_name = l_dset

importing

stripped_name = l_file

exceptions

x_error = 1

others = 2.

if sy-subrc <> 0.

endif.

split l_file at '.' into l_attname l_attext.

  • Adding Attachment

call method document->add_attachment

exporting

i_attachment_type = l_attext

i_attachment_size = l_size

i_attachment_subject = l_attname

i_att_content_hex = i_attach[].

endloop.

  • set send immediately flag

send_request->set_send_immediately( 'X' ).

  • Send document

call method send_request->send( ).

commit work.

if sy-subrc eq 0.

return-type = 'S'.

return-message = 'Message sent.'.

endif.

catch cx_bcs into bcs_exception.

data: l_message type string.

l_message = bcs_exception->get_text( ).

return-type = 'E'.

return-message = l_message.

raise bcs_error.

endtry.

endfunction.

Thanks & Regards,

Dileep .C

Edited by: Dileep Kumar Chinnaiah on Apr 3, 2009 3:28 PM

Read only

jayanchembada
Explorer
0 Likes
901

Hi Dileep,

The link which u provided is not accessible. Iam getting error message 'The requested document was not found on this server. ' .

Read only

0 Likes
901

Hi Jayan,

No worries, I copied the code which was available there.

Let me try onemore time.

[LINK|http://www.sapfans.com/forums/viewtopic.php?f=13&t=322733#p979442]

Thanks & regards,

Dileep .C

Read only

0 Likes
901

Thankd Dileep.