Problem in SO_DOCUMENT_SEND_API1
Dear all
I have used SO_DOCUMENT_SEND_API1 to send mail ,im getting sy-subrc = 0 after Fm , i can see the mail sent request in SOST in DEV server ,but the same program in QAS , SO_DOCUMENT_SEND_API1 gives sy-subrc = 0 but i cannt see the sent request in SOST.
Please help me in this
Thanks n Regards
Hi peter ,
Pre-Requisites for sending mail is SAP Exchange Connector needs to be configured.
t-code SCOT
Talk to your Basis guy , he will help you out.
Regards,
Yogendra Bhaskar
Similar Messages
-
Problem with SO_DOCUMENT_SEND_API1 Function module
Hi Experts,
Is it anyway possible that If we are sending excel attachment through email using SO_DOCUMENT_SEND_API1, column width in excel get adjusted as per the field content without any manual interaction.
Looking forward towards your valuable suggestions!!!
Regards
VJhi,
please see the following
[alignment problem with SO_NEW_DOCUMENT_SEND_API1 FM;
[Problem with function module SO_NEW_DOCUMENT_SEND_API1;
hope these helps you
Regards
Ritesh -
Problem with SO_DOCUMENT_SEND_API1
Using below code i want to send email body(t_body) as well html attachment(so_ali), But am receiving only attachment,
email body is missing, plz suggest where is the mistake in my code ASAP.
Thanks a lot in advance
Prepare the data.
plist-transf_bin = 'X'.
plist-head_start = 0.
plist-head_num = 0.
plist-body_start = 0.
plist-body_num = 0.
plist-doc_type = 'RAW'.
plist-obj_descr = 'Sairam'.
APPEND plist.
plist-transf_bin = 'X'.
plist-head_start = 0.
plist-head_num = 0.
plist-body_start = 1.
plist-doc_type = real_type.
DESCRIBE TABLE so_ali LINES plist-body_num.
Get the size.
READ TABLE so_ali INDEX plist-body_num.
plist-doc_size = ( plist-body_num - 1 ) * line_size
+ STRLEN( so_ali ).
APPEND plist.
plist-transf_bin = 'X'.
plist-head_start = 0.
plist-head_num = 0.
plist-body_start = 1.
plist-doc_type = 'RAW'.
wa_body-line = 'This is first line of email'.
append wa_body to t_body.
wa_body-line = 'This is second line of email'.
append wa_body to t_body.
DESCRIBE TABLE t_body LINES plist-body_num.
Get the size.
READ TABLE t_body into wa_body INDEX plist-body_num.
plist-doc_size = ( plist-body_num - 1 ) * line_size
+ STRLEN( wa_body ).
Move the receiver address.
MOVE: p_email TO rec_tab-receiver,
'U' TO rec_tab-rec_type.
APPEND rec_tab.
IF NOT sp_lang IS INITIAL.
document_data-obj_langu = sp_lang.
ELSE.
document_data-obj_langu = sy-langu.
ENDIF.
v_name = emailid
Subject.
document_data-obj_descr = 'Subject '.
Send the email.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
sender_address = v_name
sender_address_type = 'SMTP'
commit_work = 'X'
TABLES
packing_list = plist
contents_bin = so_ali
contents_txt = t_body
receivers = rec_tab
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.Hi,
For email body please pass transf_bin as blank. plist is basically like a header information which contains the details of the data you are sending in the email, both body and attachment. When the transf_bin field is X it is interpreted as info on attachment .. when space it is info on body.
Also you have to pass the number of lines in the email body in the field plist-body_num.
plist-transf_bin = 'X'. -> need to make this blank
plist-head_start = 0.
plist-head_num = 0.
plist-body_start = 1.
plist-doc_type = 'RAW'.
wa_body-line = 'This is first line of email'.
append wa_body to t_body.
wa_body-line = 'This is second line of email'.
append wa_body to t_body. -
Empty mail content problem in so_document_send_api1
of the function, mail and the content delivers properly. But when I try to send the mail to another friend of my in the same network but different address, mail still delivers but the content bec omes empty. I try to send both of us at the same time and he got the empty mail and I got the proper mail. what can be the reason for this problem ? if anyone enligths me about this unusual situa tion I will be preciated. thanks in advance..
Edited by: Aselsan IT Department on Mar 23, 2009 9:39 AMHi,
Please check with the Basis person.
Some settings might not be done.
Best Regards,
Suresh -
Output formatting problems with SO_DOCUMENT_SEND_API1
Hi,
I am sending an output file via email using the function module SO_DOCUMENT_SEND_API1.
The tlines table which I am passing into this function has 66 lines in it and I expect there to be 66 lines in the output file attached in the email. However, everything seems to be output into a single line.
If I send the output directly to the server it is fine.
Has anyone seen anything like this before or have any suggestions on what might be causing this?
Thanks,
RubyHere is the another program which Converts the spool into PDF and sends as attach file .
*& Report ZSPOOLTOPDF *
*& Converts spool request into PDF document and emails it to *
*& recipicant. *
*& Execution *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on *
*& screen *
REPORT zspooltopdf.
PARAMETER: p_email1 LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_sender LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_delspl AS CHECKBOX.
*DATA DECLARATION
DATA: gd_recsize TYPE i.
* Spool IDs
TYPES: BEGIN OF t_tbtcp.
INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
wa_tbtcp TYPE t_tbtcp.
* Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
gd_eventparm LIKE tbtcm-eventparm,
gd_external_program_active LIKE tbtcm-xpgactive,
gd_jobcount LIKE tbtcm-jobcount,
gd_jobname LIKE tbtcm-jobname,
gd_stepcount LIKE tbtcm-stepcount,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA: w_recsize TYPE i.
DATA: gd_subject LIKE sodocchgi1-obj_descr,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
gd_sender_type LIKE soextreci1-adr_typ,
gd_attachment_desc TYPE so_obj_nam,
gd_attachment_name TYPE so_obj_des.
* Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
gd_destination LIKE rlgrap-filename,
gd_bytecount LIKE tst01-dsize,
gd_buffer TYPE string.
* Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
c_no(1) TYPE c VALUE ' ',
c_device(4) TYPE c VALUE 'LOCL'.
*START-OF-SELECTION.
START-OF-SELECTION.
* Write statement to represent report output. Spool request is created
* if write statement is executed in background. This could also be an
* ALV grid which would be converted to PDF without any extra effort
WRITE 'Hello World'.
new-page.
commit work.
new-page print off.
IF sy-batch EQ 'X'.
PERFORM get_job_details.
PERFORM obtain_spool_id.
*** Alternative way could be to submit another program and store spool
*** id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
* to sap-spool
* spool parameters %_print
* archive parameters %_print
* without spool dynpro
* and return.
* Get spool id from program called above
* IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
PERFORM convert_spool_to_pdf.
PERFORM process_email.
if p_delspl EQ 'X'.
PERFORM delete_spool.
endif.
IF sy-sysid = c_dev.
wait up to 5 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ELSE.
SKIP.
WRITE:/ 'Program must be executed in background in-order for spool',
'request to be created.'.
ENDIF.
* FORM obtain_spool_id *
FORM obtain_spool_id.
CHECK NOT ( gd_jobname IS INITIAL ).
CHECK NOT ( gd_jobcount IS INITIAL ).
SELECT * FROM tbtcp
INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname
jobcount
stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
message s004(zdd) with gd_spool_nr.
gd_spool_nr = wa_tbtcp-listident.
MESSAGE s004(zdd) WITH gd_spool_nr.
ELSE.
MESSAGE s005(zdd).
ENDIF.
ENDFORM.
* FORM get_job_details *
FORM get_job_details.
* Get current job details
CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
IMPORTING
eventid = gd_eventid
eventparm = gd_eventparm
external_program_active = gd_external_program_active
jobcount = gd_jobcount
jobname = gd_jobname
stepcount = gd_stepcount
EXCEPTIONS
no_runtime_info = 1
OTHERS = 2.
ENDFORM.
* FORM convert_spool_to_pdf *
FORM convert_spool_to_pdf.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CHECK sy-subrc = 0.
* Transfer the 132-long strings to 255-long strings
LOOP AT it_pdf_output.
TRANSLATE it_pdf_output USING ' ~'.
CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
ENDLOOP.
TRANSLATE gd_buffer USING '~ '.
DO.
it_mess_att = gd_buffer.
APPEND it_mess_att.
SHIFT gd_buffer LEFT BY 255 PLACES.
IF gd_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
ENDFORM.
* FORM process_email *
FORM process_email.
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
PERFORM send_email USING p_email1.
* perform send_email using p_email2.
ENDFORM.
* FORM send_email *
* --> p_email *
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH it_mess_bod.
* Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = 'Attachname'.
* CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
it_mess_bod = 'Message Body text, line 1'.
APPEND it_mess_bod.
it_mess_bod = 'Message Body text, line 2...'.
APPEND it_mess_bod.
* If no sender specified - default blank
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
* Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using p_email
'Example .xls documnet attachment'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
ENDFORM.
* FORM delete_spool *
FORM delete_spool.
DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
ld_spool_nr = gd_spool_nr.
CHECK p_delspl <> c_no.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = ld_spool_nr.
ENDFORM.
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
* Send email
FORM send_file_as_email_attachment tables it_message
it_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_receivers like somlreci1 occurs 0 with header line,
t_attachment like solisti1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
* Fill the document data.
w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = it_attach[].
* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
* Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
* Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
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.
* Populate zerror return code
ld_error = sy-subrc.
* Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
reward points if it is usefull ...
Girish -
Problem in mailing smartforms output using SO_DOCUMENT_SEND_API1
Hi all,
Iam using the function module SO_DOCUMENT_SEND_API1 to email purchase order through driver program.
the code goes like this:
first iam calling the function module of smartform
CALL FUNCTION lv_fm_name
where iam passing the desired paramets.
from where iam taking the otfdata returned from the fm
like:
IMPORTING
job_output_info = w_return
where w_return is declared as TYPE ssfcrescl.
then iam writing this code
i_otf[] = w_return-otfdata[].
DELETE w_return-otfdata WHERE tdprintcom = '//'.
READ TABLE i_otf WITH KEY tdprintcom = 'EP'.
my_tabix = sy-tabix + 1.
INSERT lines of w_return-otfdata INTO i_otf INDEX my_tabix.
then iam calling the fm
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = v_len_in
TABLES
otf = i_otf
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
then converting it to 255 using
DATA: gd_buffer TYPE string.
DATA: w_cnt TYPE i,
i_record LIKE solix OCCURS 0 WITH HEADER LINE.
LOOP AT i_tline.
TRANSLATE i_tline USING ' ~'.
CONCATENATE gd_buffer i_tline INTO gd_buffer.
ENDLOOP.
TRANSLATE gd_buffer USING '~ '.
DO.
i_record-line = gd_buffer.
APPEND i_record.
SHIFT gd_buffer LEFT BY 255 PLACES.
IF gd_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
the to test whether its converting into pdf iam using the fm
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = bin_filesize
filename = 'C:\TESTPDF.PDF'
filetype = 'BIN'
TABLES
data_tab = i_record.
then calling my main fm
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_chng
put_in_outbox = 'X'
sender_address = sender
sender_address_type = 'INT'
commit_work = 'X'
TABLES
packing_list = it_packing_list
object_header = w_objhead
CONTENTS_BIN = I_OBJBIN
contents_txt = i_objtxt
contents_hex = i_objbin
receivers = it_receivers
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
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
all the parametrs for the above fm are passed correctly like populating it_packing_list,w_objhead, i_objtxt, i_objbin,it_receivers.iam using this fm because i need to pass sender email id.
the first problem iam facing is when iam using the fm gui_download iam not able to view the smartform
the error is "adobe reader could not open "test.pdf" as it is not supported etc..."
second is same problem iam facing while trying to open the attachment in pdf which is emailed to reciever.
i think there is some problem in converting 132 to 255 characters.
can some one please help on this.(might be a problem where iam passing DO
i_record-line = gd_buffer.)
thanks in advance.
regards
sunilCALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = <b>255 "132</b>
IMPORTING
bin_filesize = v_len_in
TABLES
otf = i_otf
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
I guess it will solve your problem.
CLose the thread if your question is answered.
Regards,
SaiRam -
Problem using function SO_DOCUMENT_SEND_API1,
Dear All,
I used this function for attach the txt file and send the e-mail to relate user.
Now, My output file print out all the data in the same line.
how i can split the data line by line ?
below is my coding.
Please kindly to help me.
Regards,
Luke
PERFORM send_file_as_email_attachment
TABLES it_mess_bod
it_mess_att
USING P_TITLE
'FIX'
gd_attachment_name
gd_attachment_desc
p_FROM
'INT'
CHANGING gd_error
gd_reciever.
*& Form send_file_as_email_attachment
text
-->IT_MESSAGE text
-->IT_ATTACH text
-->P_MTITLE text
-->P_FORMAT text
-->P_FILENAME text
-->P_ATTDESCRIPTION text
-->P_SENDER_ADDRESS text
-->P_SENDER_ADDRES_TYPE text
-->P_ERROR text
-->P_RECIEVER text
FORM send_file_as_email_attachment TABLES it_message
it_attach
USING p_email
USING p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
CHANGING p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = it_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
LOOP AT itab_mailto.
t_receivers-receiver = itab_mailto-smtp_addr.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
t_receivers-copy = ''.
APPEND t_receivers.
ENDLOOP.
LOOP AT S_CC.
t_receivers-receiver = S_CC-low.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
t_receivers-copy = 'X'.
APPEND t_receivers.
ENDLOOP.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM. "send_file_as_email_attachmentHi,
Try This ....
DATA: l_tab_lines TYPE i,
l_error TYPE string.
CONSTANTS : l_c_name(13) TYPE c VALUE 'HC Error File', "#EC NOTEXT
l_c_255(255) TYPE c VALUE '255',
l_c_txt(3) TYPE c VALUE 'TXT'.
DATA: lt_reclist TYPE STANDARD TABLE OF somlreci1, "Recipients
lt_objpack TYPE STANDARD TABLE OF sopcklsti1,
lt_objhead TYPE STANDARD TABLE OF solisti1,
lt_objtxt TYPE STANDARD TABLE OF solisti1, "Body of EMail
lt_objbin TYPE STANDARD TABLE OF solisti1."Attachment of EMail
DATA: l_wa_doc_chng TYPE sodocchgi1, "attributes of document to send
l_wa_reclist LIKE LINE OF lt_reclist,
l_wa_objpack LIKE LINE OF lt_objpack,
l_wa_obj LIKE LINE OF lt_objhead.
Begin of Insert CHRK941885
DATA :
l_hex LIKE solix,
lt_contents_hex LIKE STANDARD TABLE OF solix ,
conv TYPE REF TO cl_abap_conv_out_ce,
l_buffer TYPE xstring,
l_hexa(510) type x.
End of Insert CHRK941885
Fill attachment contents: body of email message
CONCATENATE 'Click on attachment to view the extract file :'(t01)
l_c_name INTO l_wa_obj-line SEPARATED BY space.
APPEND l_wa_obj TO lt_objtxt. CLEAR l_wa_obj.
APPEND l_wa_obj TO lt_objtxt. CLEAR l_wa_obj.
DESCRIBE TABLE lt_objtxt LINES l_tab_lines.
Information about the email body data
CLEAR l_wa_objpack-transf_bin. "Attachment not binary
l_wa_objpack-head_start = 1.
l_wa_objpack-head_num = 0.
l_wa_objpack-body_start = 1.
l_wa_objpack-body_num = l_tab_lines * l_c_255.
l_wa_objpack-doc_type = 'TXT'.
APPEND l_wa_objpack TO lt_objpack.
CLEAR :l_wa_objpack.
Move error records to the file, semi-colon delimited
LOOP AT e_error INTO g_error.
CONCATENATE g_error-pernr ';'
g_error-nachn ';'
g_error-vorna ';'
g_error-werks ';'
g_error-persg ';'
g_error-eligr ';'
g_error-msg INTO l_error.
APPEND l_error TO lt_objbin.
ENDLOOP.
Document type is TXT
l_wa_objpack-doc_type = l_c_txt.
APPEND object_header.
CALL FUNCTION 'SO_RAW_TO_RTF'
TABLES
objcont_old = lt_objbin
objcont_new = lt_objbin.
Begin of Insert CHRK941885
LOOP AT lt_objbin into l_error.
conv = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' endian = 'B').
CALL METHOD conv->write( data = l_error ).
l_buffer = conv->get_buffer( ).
move l_buffer to l_hexa.
move l_hexa to l_hex-line.
APPEND l_hex to lt_contents_hex.
ENDLOOP.
End of Insert CHRK941885
File name for attachment
l_wa_obj = l_c_name.
APPEND l_wa_obj TO lt_objhead.
CLEAR l_wa_obj.
DESCRIBE TABLE lt_objbin LINES l_tab_lines.
Creation of the entry for the compressed attachment
l_wa_objpack-transf_bin = 'X'.
l_wa_objpack-head_start = 1.
l_wa_objpack-head_num = 1.
l_wa_objpack-body_start = 1.
l_wa_objpack-obj_name = l_c_name.
l_wa_objpack-obj_descr = l_c_name.
l_wa_objpack-body_num = l_tab_lines.
l_wa_objpack-doc_size = l_tab_lines * l_c_255.
APPEND l_wa_objpack TO lt_objpack.
CLEAR l_wa_objpack.
Completing the recipient list
LOOP AT s_email.
l_wa_reclist-receiver = s_email-low.
l_wa_reclist-express = 'X'.
l_wa_reclist-rec_type = 'U'.
APPEND l_wa_reclist TO lt_reclist.
CLEAR l_wa_reclist.
ENDLOOP.
Document to send
MOVE 'Health Risk Assessment Batch extract'(h01)
TO l_wa_doc_chng-obj_descr.
Send mail as a confidential
l_wa_doc_chng-sensitivty = 'P'.
Send the document
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = l_wa_doc_chng
put_in_outbox = ' '
commit_work = 'X'
TABLES
packing_list = lt_objpack
object_header = lt_objhead
contents_bin = lt_objbin " Comment CHRK941885
contents_txt = lt_objtxt
contents_hex = lt_contents_hex " Insert CHRK941885
receivers = lt_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.
IF sy-subrc = 0.
MESSAGE s000(oo) WITH 'Email sent to recipients'(s12).
To refresh SAP Work Office so that mail can be recieved immediataly.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = ''
AND RETURN.
ELSE.
MESSAGE e000(oo) WITH 'Problem sending Email.'(e02).
ENDIF. -
Problem in FM SO_DOCUMENT_SEND_API1
Dear All
I am using FM SO_DOCUMENT_SEND_API1 to send excel attachment in a mail.
The data is coming correctly but data in one column is coming in distorted format with lot of spaces that are not given at any point. I used 'CONDENSE' in all fields but it didnt help.
Kindly advice where can be the problem or any alternative FM.
Thanks in advance.
Regards
Dineshhi,
use the procedure given below it will definately solve your problem:
*Firstly export the data to memory using the FM LIST_FROM_MEMORY.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = t_listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc 0.
MESSAGE e000(su) WITH text-001.
ENDIF.
then i converted it into ASCII using LIST_TO_ASCI,
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = t_xlstab
listobject = t_listobject
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE e003(yuksdbfzs).
ENDIF.
This gives the data in ASCII format separated by '|' and the header has '-', dashes. If you use this internal table directly without any proccesing in SO_NEW_DOCUMENT_ATT_SEND_API1, then you will not get a good excel sheet attachment. To overcome this limitation, i used cl_abap_char_utilities=>newline and cl_abap_char_utilities=>horizontal_tab to add horizontal and vertical tabs to the internal table, replacing all occurences of '|' with
cl_abap_char_utilities=>horizontal_tab.
Set the doc_type as 'XLS', create the body and header using the packing_list and pass the data to be downloaded to SO_NEW_DOCUMENT_ATT_SEND_API1 as contents_bin.
This will create an excel attachment.
Sample code for formatting the data for the attachment in excel format.
u2022 Format the data for excel file download
LOOP AT t_xlstab INTO wa_xlstab .
DESCRIBE TABLE t_xlstab LINES lw_cnt.
CLEAR lw_sytabix.
lw_sytabix = sy-tabix.
u2022 If not new line then replace '|' by tabs
IF NOT wa_xlstab EQ cl_abap_char_utilities=>newline.
REPLACE ALL OCCURRENCES OF '|' IN wa_xlstab
WITH cl_abap_char_utilities=>horizontal_tab.
MODIFY t_xlstab FROM wa_xlstab .
CLEAR wa_xlstab.
wa_xlstab = cl_abap_char_utilities=>newline.
IF lw_cnt NE 0 .
lw_sytabix = lw_sytabix + 1.
u2022 Insert new line for the excel data
INSERT wa_xlstab INTO t_xlstab INDEX lw_sytabix.
lw_cnt = lw_cnt - 1.
ENDIF.
CLEAR wa_xlstab.
ENDIF.
ENDLOOP.
Sample code for creating attachment and sending mail:
FORM send_mail .
u2022 Define the attachment format
lw_doc_type = 'XLS'.
u2022 Create the document which is to be sent
lwa_doc_chng-obj_name = 'List'.
lwa_doc_chng-obj_descr = w_subject. "Subject
lwa_doc_chng-obj_langu = sy-langu.
u2022 Fill the document data and get size of message
LOOP AT t_message.
lt_objtxt = t_message-line.
APPEND lt_objtxt.
ENDLOOP.
DESCRIBE TABLE lt_objtxt LINES lw_tab_lines.
IF lw_tab_lines GT 0.
READ TABLE lt_objtxt INDEX lw_tab_lines.
lwa_doc_chng-doc_size = ( lw_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
lwa_doc_chng-obj_langu = sy-langu.
lwa_doc_chng-sensitivty = 'F'.
ELSE.
lwa_doc_chng-doc_size = 0.
ENDIF.
u2022 Fill Packing List For the body of e-mail
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lw_tab_lines.
lt_packing_list-doc_type = 'RAW'.
APPEND lt_packing_list.
u2022 Create the attachment (the list itself)
DESCRIBE TABLE t_xlstab LINES lw_tab_lines.
u2022 Fill the fields of the packing_list for creating the attachment:
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lw_tab_lines.
lt_packing_list-doc_type = lw_doc_type.
lt_packing_list-obj_name = 'Attach'.
lt_packing_list-obj_descr = w_docdesc.
lt_packing_list-doc_size = lw_tab_lines * 255.
APPEND lt_packing_list.
u2022 Fill the mail recipient list
lt_reclist-rec_type = 'U'.
LOOP AT t_recipient_list.
lt_reclist-receiver = t_recipient_list-address.
APPEND lt_reclist.
ENDLOOP.
u2022 Finally send E-Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lwa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = lw_sent_to_all
TABLES
packing_list = lt_packing_list
object_header = lt_objhead
contents_bin = t_xlstab
contents_txt = lt_objtxt
receivers = lt_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.
Hope it will help you
Regards
Rahul sharma -
Problems sending mail with txt attachtment using SO_DOCUMENT_SEND_API1 MF
Hi gurus,
I allready tried to search in the forum some threads related with my problem, but i couldnt found any with the same problem that im having.
My problem it's when attachting an txt file, using MF SO_DOCUMENT_SEND_API1 MF, the mail attachtment it's coming with the txt file but instead of coming with the all lines in the contents_bins table the file it's coming with a few lines. I think the problem it's that the txt file should come with 80 characters per line, like it's on the contents_bin table, buu instead that the MF it's filling me each line of the file with 1024 characters.
Does anyone has ideas what im doing wrong?
Ps - Below goes my code.
Thanks in Advance,
Best Regards,
João Martins.
CLEAR contents_bin.
REFRESH contents_bin.
PERFORM get_attachment TABLES tab_movimentos contents_bin
USING linha_inicial
linha_final.
CLEAR: document_data, tab_lines.
MOVE 'Aviso Ficheiro Retorno' TO document_data-obj_descr.
MOVE 'Aviso Ficheiro de Retorno TU' TO document_data-obj_name.
DESCRIBE TABLE contents_txt LINES tab_lines.
READ TABLE contents_txt INDEX tab_lines.
document_data-doc_size = ( tab_lines - 1 ) * 255
+ STRLEN( contents_txt ).
CLEAR packing_list.
REFRESH packing_list.
packing_list-transf_bin = space.
packing_list-head_start = 1.
packing_list-head_num = 0.
packing_list-body_start = 1.
DESCRIBE TABLE contents_txt LINES packing_list-body_num.
packing_list-doc_type = 'RAW'.
APPEND packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 1.
packing_list-head_num = 1.
ADD 1 TO tab_lines.
packing_list-body_start = tab_lines.
CLEAR: lv_filename, tab_lines.
CONCATENATE 'Fich Retorno -' nome_ficheiro INTO lv_filename.
DESCRIBE TABLE contents_bin LINES tab_lines.
packing_list-doc_type = 'TXT'.
packing_list-obj_descr = 'Ficheiro Retorno'.
packing_list-obj_name = lv_filename.
packing_list-doc_size = tab_lines * 255.
APPEND packing_list.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
put_in_outbox = 'X'
sender_address = 'SIFJOB'
sender_address_type = 'B'
IMPORTING
sent_to_all = sent_to_all
TABLES
packing_list = packing_list
contents_bin = contents_bin
contents_txt = contents_txt
receivers = tab_receiver
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.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = SPACE
AND RETURN.
FORM get_attachment TABLES p_tab_movimentos STRUCTURE
zlinha_movimentos_fich_retorno
p_contents_bin STRUCTURE contents_bin
USING p_linha_inicial STRUCTURE
zlinha_inicial_ps2
p_linha_final STRUCTURE
zlinha_final_ps2.
DATA: lv_valor(14).
DATA : line(80) TYPE x.
CONCATENATE p_linha_inicial-referencia p_linha_inicial-tipo_registo
p_linha_inicial-tipo_operacao p_linha_inicial-situacao_conta
p_linha_inicial-situacao_registo p_linha_inicial-iban+4(21)
p_linha_inicial-moeda p_linha_inicial-data_pag
p_linha_inicial-ref_ordenante p_linha_inicial-filler
INTO p_contents_bin-line.
CLEAR line.
conv_bin p_contents_bin-line line.
MOVE line TO p_contents_bin-line.
APPEND p_contents_bin.
CLEAR p_contents_bin.
LOOP AT p_tab_movimentos.
CLEAR: lv_valor.
WRITE p_tab_movimentos-montante TO lv_valor.
PERFORM normalize_value USING lv_valor.
CONCATENATE p_tab_movimentos-referencia
p_tab_movimentos-tipo_registo p_tab_movimentos-tipo_operacao
p_tab_movimentos-sit_conta_retor p_tab_movimentos-situacao_registo
p_tab_movimentos-nib lv_valor
p_tab_movimentos-ref_ordenante p_tab_movimentos-filler
INTO p_contents_bin-line.
CLEAR line.
conv_bin p_contents_bin-line line.
MOVE line TO p_contents_bin-line.
APPEND p_contents_bin.
CLEAR p_contents_bin.
ENDLOOP.
CLEAR: lv_valor.
WRITE p_linha_final-mont_total TO lv_valor.
PERFORM normalize_value USING lv_valor.
CONCATENATE p_linha_final-referencia p_linha_final-tipo_registo
p_linha_final-tipo_operacao p_linha_final-filler_1
p_linha_final-situacao_registo p_linha_final-filler_2
p_linha_final-total_reg lv_valor
p_linha_final-filler INTO p_contents_bin-line.
CLEAR line.
conv_bin p_contents_bin-line line.
MOVE line TO p_contents_bin-line.
APPEND p_contents_bin.
CLEAR p_contents_bin.
ENDFORM. " get_attachmentHi,
I've solved this problem. The problem was because i was using the
* Anexo - Descrição
packing_list-transf_bin = 'X'.
packing_list-head_start = 1. "Here it must be 0 because i wasn't using any table header
packing_list-head_num = 0.
ADD 1 TO tab_lines.
packing_list-body_start = 1.
CLEAR: lv_filename, tab_lines.
CONCATENATE nome_ficheiro 'TB' INTO lv_filename.
* CONCATENATE 'Fich Retorno -' nome_ficheiro INTO lv_filename.
DESCRIBE TABLE contents_bin LINES tab_lines.
packing_list-doc_type = 'TXT'.
packing_list-obj_descr = lv_filename."'Ficheiro Retorno'.
packing_list-obj_name = lv_filename.
packing_list-body_num = tab_lines.
packing_list-doc_size = tab_lines * 255.
APPEND packing_list.
Best Regards
Thanks,
João Martins -
Problem with the function module SO_DOCUMENT_SEND_API1
Hi Friends,
I am facing the problem wiht the function module SO_DOCUMENT_SEND_API1,
My actull requirement is : - i need to send the sap data to my externa mail id (Like as XYZ@) with out the any attachment , So i have implemented the code with the function module SO_DOCUMENT_SEND_API1.
The mail has successfully sent the sap inbox (SOST) but the mail are not reached to the external mail ID'S( XYZ@GMAIL)
i Have maintained my code lines same as below.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = wa_doc_data
put_in_outbox = ca_x
commit_work = ca_x
TABLES
packing_list = tb_packing_list
contents_txt = tb_mailbody
receivers = tb_receiver.
Can you please tell me soultion ,
Thanks
charan.Hi charan,
If u r able to see the mail in sost, then i think ur code has worked fine. if the mail is not going to outside domains from sost u need to do some configurations for that, u can find lots of configuration docs regarding mail setup in sap.
once try to pass below parameter also.
t_receivers1-rec_type = 'U'.
For configuring mail setup u need to sit with ur basis guy.
Moderator message: please do not use SMS speak.
Edited by: Thomas Zloch on Nov 23, 2010 5:51 PM -
Problem using FM SO_DOCUMENT_SEND_API1
hi gurus,
I'm having a hard time trying to get the right result using FM SO_DOCUMENT_SEND_API1 to send and attachment with email.
I collected a number of lines (8252 lines !) into an internal table defines as followed :
DATA : wt_report TYPE TABLE OF SOLISTI1 WITH HEADER LINE.
Now I would like to send the content of each line as email attachement as EITHER .xls OR .txt files. (for now I get an email with attachment but canno view the content of the email)
Here is my code :
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = ws_doc_data
PUT_IN_OUTBOX = 'x'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
SENDER_ID =
tables
packing_list = it_packing_list <----
what is this supposed to contain ??
OBJECT_HEADER =
CONTENTS_TXT = wt_report <------ Here is my itab with 8252 lines
CONTENTS_HEX = wt_report
OBJECT_PARA =
OBJECT_PARB =
receivers = wt_receivers
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
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Thank you so much for help, <removed_by_moderator>
C.K.
Edited by: Julius Bussche on Jul 8, 2008 4:36 PMhi check this....
REPORT ZMAIL.
TABLES: ekko.
PARAMETERS: p_email TYPE somlreci1-receiver .
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
ebeln(10) TYPE c,
ebelp(5) TYPE c,
aedat(8) TYPE c,
matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
*START_OF_SELECTION
START-OF-SELECTION.
Retrieve sample data from table ekpo
PERFORM data_retrieval.
Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.
*END-OF-SELECTION
END-OF-SELECTION.
Populate message body text
perform populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
'Example .xls documnet attachment'
'XLS'
'filename'
changing gd_error
gd_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
ENDFORM. " DATA_RETRIEVAL
*& Form BUILD_XLS_DATA_TABLE
Build data table for .xls document
FORM build_xls_data_table.
data: ld_store(50) type c. "Leading zeros
CONSTANTS: con_cret(5) TYPE c VALUE '0D', "OK for non Unicode
con_tab(5) TYPE c VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>CR_LF.
CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR' INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT it_ekpo INTO wa_charekpo.
*Modification to retain leading zeros
inserts code for excell REPLACE command into ld_store
=REPLACE("00100",1,5,"00100")
concatenate '=REPLACE("' wa_charekpo-ebelp '",1,5,"'
wa_charekpo-ebelp '")' into ld_store .
concatenate ld_store into .xls file instead of actual value(ebelp)
CONCATENATE wa_charekpo-ebeln ld_store wa_charekpo-aedat wa_charekpo-matnr INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
FORM send_file_as_email_attachment tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
Instructs mail send program for SAPCONNECT to send email.
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
*& Form POPULATE_EMAIL_MESSAGE_BODY
Populate message body text
form populate_email_message_body.
REFRESH it_message.
it_message = 'Please find attached a list test ekpo records'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY -
Problem with sender name CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
Hi All ,
I am using below function module to send a mail to external email Id's , Everything is working perfectly .
But in the sender address I have passed text as 'infomation ' , In email which i am recieving sender address is like text and '@xyz.com' .
Any idea from where this @xyz.com is picking ? .
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
sender_address = 'Information'
sender_address_type = 'INT'
commit_work = 'X'
IMPORTING
sent_to_all = gd_sent_all
TABLES
packing_list = it_packing_list
contents_bin = it_attachment
contents_txt = it_message
receivers = it_receivers
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.Hi All ,
I am using below function module to send a mail to external email Id's , Everything is working perfectly .
But in the sender address I have passed text as 'infomation ' , In email which i am recieving sender address is like text and '@xyz.com' .
Any idea from where this @xyz.com is picking ? .
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
sender_address = 'Information'
sender_address_type = 'INT'
commit_work = 'X'
IMPORTING
sent_to_all = gd_sent_all
TABLES
packing_list = it_packing_list
contents_bin = it_attachment
contents_txt = it_message
receivers = it_receivers
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. -
Problem while sending attachment thru 'SO_DOCUMENT_SEND_API1'
Hi Experts ,
I am trying to send two excel files thrugh the function module 'SO_DOCUMENT_SEND_API1' .
Attachments are reaching the destination email address successfully , But along with two attacments its sending one more .txt file also in which email body text is included .
Please help me to resolve the issue .
Thanks in advance .Hi Manu ,
Thanks for your reply .
I checked with setting and everything is as expected .
Attaching the code which I have used in my program for sending 2 excel , Please help .
gd_doc_data-doc_size = 1.
*Fill the document data for attachment 2
Populate the subject/generic message attributes
READ TABLE it_attach INDEX gd_cnt.
gd_doc_data-doc_size =
( gd_cnt - 1 ) * 255 + STRLEN( it_attach ).
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
CLEAR it_attachment.
REFRESH it_attachment.
it_attachment[] = it_attach[].
Describe the body of the message
CLEAR it_packing_list.
REFRESH it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES it_packing_list-body_num.
it_packing_list-doc_type = 'RAW'.
APPEND it_packing_list.
Create attachment notification
it_packing_list-transf_bin = 'X'.
it_packing_list-head_start = 1.
it_packing_list-head_num = 1.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.
it_packing_list-doc_type = 'XLS'.
it_packing_list-obj_descr = 'Successful Ser.no'.
it_packing_list-obj_name = 'Allot'.
it_packing_list-doc_size = it_packing_list-body_num * 255.
APPEND it_packing_list.
Fill the document data attachment 2
Populate the subject/generic message attributes
READ TABLE it_attach_1 INDEX gd_cnt.
gd_doc_data-doc_size =
( gd_cnt - 1 ) * 255 + STRLEN( it_attach_1 ).
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
CLEAR it_attachment.
REFRESH it_attachment.
it_attachment[] = it_attach_1[].
Describe the body of the message
CLEAR it_packing_list.
REFRESH it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES it_packing_list-body_num.
it_packing_list-doc_type = 'RAW'.
APPEND it_packing_list.
Create attachment notification
it_packing_list-transf_bin = 'X'.
it_packing_list-head_start = 1.
it_packing_list-head_num = 1.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.
it_packing_list-doc_type = 'XLS'.
it_packing_list-obj_descr = 'Unsuccessful Ser.no'.
it_packing_list-obj_name = 'Allot1'.
it_packing_list-doc_size = it_packing_list-body_num * 255.
APPEND it_packing_list.
Call the FM to post the message to SAPMAIL
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
sender_address = 'Traking System'
sender_address_type = 'INT'
commit_work = 'X'
IMPORTING
sent_to_all = gd_sent_all
TABLES
packing_list = it_packing_list
contents_bin = it_attachment
contents_txt = it_message
receivers = it_receivers
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. -
Hello Experts,
I am using the said FM to send e-mail with Excel attachment but it always give me the error
DOCUMENT_NOT_SENT. What maybe the cause of this error? hope you could help me out here guys.
Thank you and take care!Hi
Try using this class <b>CL_BCS</b> for mailing with attachments.
Checkout this thread
Class CL_BCS Query for body part of mail
Regards,
Raj -
SO_DOCUMENT_SEND_API1 and Business Workplace
Hello gurus,
I'm using the FM SO_DOCUMENT_SEND_API1 to send emails (massively) with a pdf file as attachment. Unfortunately, I can't see the email in the outbox of my business workplace . Nevertheless all the recipients get the emails without problems. The sy-subrc after calling the FM is 0. Everything seems to go fine except for the missing entries in my outbox .
Any help will be appreciated.
Thank you,
Jaime
P.D. This is the way how I'm calling the FM:
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = wa_doc_data
put_in_outbox = 'X'
sender_address = in_sender_address
sender_address_type = in_sender_addres_type
commit_work = 'X'
importing
sent_to_all = w_sent_all
tables
packing_list = it_packing_list
contents_bin = it_attachment_int
contents_txt = it_message_body_int
receivers = it_email_receivers_int
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.
case sy-subrc.
when 0.
* Todo bien!
when 1.
raise too_many_receivers.
when 2.
raise document_not_sent.
when 3.
raise document_type_not_exist.
when 4.
raise operation_no_authorization.
when 5.
raise parameter_error.
when 6.
raise x_error.
when 7.
raise enqueue_error.
when others.
raise unknown_error.
endcase.Hello.
please find the code below it will be more help ful to you
DATA :
IT_PACKING_LIST TYPE TABLE OF SOPCKLSTI1,
IT_CONTENTS_TXT TYPE TABLE OF SOLISTI1,
IT_RECEIVERS TYPE TABLE OF SOMLRECI1,
WA_DOCUMENT TYPE SODOCCHGI1,
WA_PACKING_LIST TYPE SOPCKLSTI1,
WA_RECEIVERS TYPE SOMLRECI1,
WA_CONTENTS_TXT TYPE SOLISTI1,
IT_OTF TYPE table of ITCOO,
T_html_raw type table of ITCOO,
T_SENDER TYPE SO_REC_EXT,
T_ADSMTP_LINE TYPE SZADR_ADSMTP_LINE,
T_SENDER_TYP TYPE SOEXTRECI1-ADR_TYP,
T_pdf_xstring type xstring,
Tt_lines type table of tline,
wa_lines type tline,
T_pdf_len type i,
it_docs TYPE STANDARD TABLE OF docs,
L_SMTP_ADDR type AD_SMTPADR,
MID(20) type c,
wa_buffer TYPE string.
*Importing the MAil Address from the Memory id
*Pass the OTF data to the Internal Table
IT_OTF = job_output_info-OTFDATA.
If not IT_OTF is INITIAL.
*Convert the OTF data to ASCII
Call function 'CONVERT_OTF'
exporting
format = 'ASCII'
importing
bin_filesize = T_pdf_len
bin_file = T_pdf_xstring " binary file
tables
otf = IT_OTF
lines = tt_lines
exceptions
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
others = 5.
if sy-subrc = 0.
*PAss the ASCII data to the Body Of the Mail
loop at tt_lines into wa_lines.
wa_CONTENTS_TXT = wa_lines-tdline.
append wa_contents_txt to it_contents_txt.
clear wa_contents_txt.
endloop.
*Mail headder information **
WA_DOCUMENT-OBJ_NAME = 'SMARTFORM'.
WA_DOCUMENT-OBJ_LANGU = SY-LANGU.
WA_DOCUMENT-OBJ_DESCR = 'Interest Calculation' .
WA_DOCUMENT-SENSITIVTY = 'F'.
If email exist.
WA_RECEIVERS-RECEIVER = ur email addrees
WA_RECEIVERS-REC_TYPE = 'U'.
WA_RECEIVERS-COM_TYPE = 'INT'.
WA_RECEIVERS-NOTIF_DEL = 'X'.
WA_RECEIVERS-NOTIF_NDEL = 'X'.
APPEND WA_RECEIVERS TO IT_RECEIVERS.
T_SENDER = SY-UNAME.
T_SENDER_TYP = 'INT'.
*Passing the data to the Context Table
Document Attachement information **
CLEAR WA_PACKING_LIST-TRANSF_BIN.
WA_PACKING_LIST-TRANSF_BIN = SPACE.
WA_PACKING_LIST-HEAD_START = 1.
WA_PACKING_LIST-HEAD_NUM = 0.
WA_PACKING_LIST-BODY_START = 1.
WA_PACKING_LIST-obj_name = 'Interest Calculation Letter'.
DESCRIBE TABLE IT_CONTENTS_TXT LINES WA_PACKING_LIST-BODY_NUM.
WA_PACKING_LIST-DOC_size = WA_PACKING_LIST-BODY_NUM * 255.
WA_PACKING_LIST-BODY_NUM = WA_PACKING_LIST-BODY_NUM.
WA_PACKING_LIST-DOC_TYPE = 'RAW'.
APPEND WA_PACKING_LIST TO IT_PACKING_LIST.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = WA_DOCUMENT
PUT_IN_OUTBOX = 'X'.
SENDER_ADDRESS = T_SENDER
SENDER_ADDRESS_TYPE = 'B'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = IT_PACKING_LIST
CONTENTS_TXT = IT_CONTENTS_TXT
RECEIVERS = IT_RECEIVERS
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.
Thanks,
Maybe you are looking for
-
How do I link to a HelpID or a Search Term without any programming, through a URL?
I have looked through the documentation, and it seems that every "possibility" to call either a search term or a HelpID/CHSID for my documentation is to use some sort of API. Is there a way to call the search function and CHSIDs directly by only typi
-
MacBook Pro issues connecting to Gmail, Facebook, and other websites
Hi, In the past week or so, I have had problems connecting to Gmail, Facebook, and other websites on my MacBook. When I try to open Gmail, I get the following message "Safari can't verify the identity of the website "accounts.google.com". The certifi
-
Count of rows of a table in header
Hi Experts, I am stuck in a tricky scenario. I need to get the count of rows of a table in a webi report in the header of the report. And the count should change dynamically according to the filtering done on the table. For eg. If I have 10 countries
-
Software required to communicate with the ipod is not working error, help!!
I've had my iPod nano for a while now, and it was working fine until I installed the new iTunes. Now, when I plug my nano in, iTunes won't start. Then, I open up iTunes, and it says "The software required to communicate with the iPod is not properly
-
Hi, I'm installing EPSP9 (NW04 SR1) on Windows 2000Server/Oracle9206. I've successfully installed J2EE engine, but during portal installation at step "Check Portal Deployment Status" it gives error. Following errors reported in file j2ee\cluster\serv