11-15-2005 11:54 PM
Hi,
I have the following program for sending email attachment as xls file. To send it as a pdf file, what I should modify.
Thanks
Veni.
FORM EMAIL_DATA.
Populate details for .xls file
PERFORM build_xls_data_table.
Populate message body
PERFORM populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
TABLES i_message
i_attach
USING p_email
'Commercial Invoice'
'XLS'
'COMMERCIAL_INVOICE'
' '
' '
' '
CHANGING g_error
g_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
ENDFORM. " EMAIL_DATA
&----
*& Form build_xls_data_table
&----
text
----
--> p1 text
<-- p2 text
----
FORM build_xls_data_table .
CONSTANTS:
con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
i_attach-line = 'Commercial Invoice Details., INC.'.
APPEND i_attach.
i_attach-line = 'Details of Commercial Invoice:'.
APPEND i_attach.
LOOP AT FTAB.
i_attach-line = FTAB-VBELN.
APPEND i_attach.
CONCATENATE 'MATERIAL' 'NET PRICE' INTO i_attach
SEPARATED BY space.
CONCATENATE con_cret i_attach INTO i_attach.
APPEND i_attach.
LOOP AT ITAB_VBRP INTO wa_data.
CONCATENATE wa_data-MATNR
wa_data-NETWR INTO i_attach
SEPARATED BY space. "con_tab.
CONCATENATE con_cret i_attach INTO i_attach.
APPEND i_attach.
ENDLOOP.
ENDLOOP.
ENDFORM. " build_xls_data_table
&----
*& Form populate_email_message_body
&----
text
----
--> p1 text
<-- p2 text
----
FORM populate_email_message_body .
DATA: l_buffer(250).
REFRESH i_message.
l_buffer = 'COMMERCIAL INVOICE DATA DOWNLOAD. '.
SKIP 2.
CONCATENATE l_buffer 'You will find an attachment in this message.'
INTO l_buffer.
i_message = l_buffer.
APPEND i_message.
ENDFORM. " populate_email_message_body
&----
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
&----
Send email
----
FORM send_file_as_email_attachment TABLES p_i_message
p_i_attach
USING p_email1
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
CHANGING p_error
p_receiver.
DATA: l_error TYPE sy-subrc,
l_receiver TYPE sy-subrc,
l_email LIKE somlreci1-receiver,
l_mtitle LIKE sodocchgi1-obj_descr,
l_format TYPE so_obj_tp,
l_attfilename TYPE so_obj_des ,
l_attdescription TYPE so_obj_nam ,
l_sender_address LIKE soextreci1-receiver,
l_sender_address_type LIKE soextreci1-adr_typ.
l_email = p_email1.
l_mtitle = p_mtitle.
l_format = p_format.
l_attfilename = p_filename.
l_attdescription = p_attdescription.
l_sender_address = p_sender_address.
l_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 = l_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE i_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( i_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = l_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR i_attachment.
REFRESH i_attachment.
i_attachment[] = p_i_attach[].
Describe the body of the message
CLEAR i_packing_list.
REFRESH i_packing_list.
i_packing_list-transf_bin = space.
i_packing_list-head_start = 1.
i_packing_list-head_num = 0.
i_packing_list-body_start = 1.
DESCRIBE TABLE i_message LINES i_packing_list-body_num.
i_packing_list-doc_type = 'RAW'.
APPEND i_packing_list.
Create attachment notification
i_packing_list-transf_bin = 'X'.
i_packing_list-head_start = 1.
i_packing_list-head_num = 1.
i_packing_list-body_start = 1.
DESCRIBE TABLE i_attachment LINES i_packing_list-body_num.
i_packing_list-doc_type = l_format.
i_packing_list-obj_descr = l_attdescription.
i_packing_list-obj_name = l_attfilename.
i_packing_list-doc_size = i_packing_list-body_num * 255.
APPEND i_packing_list.
Add the recipients email address
CLEAR i_receivers.
REFRESH i_receivers.
i_receivers-receiver = l_email.
i_receivers-rec_type = 'U'.
i_receivers-com_type = 'INT'.
i_receivers-notif_del = 'X'.
i_receivers-notif_ndel = 'X'.
APPEND i_receivers.
i_receivers-receiver = l_email.
i_receivers-rec_type = 'B'.
i_receivers-com_type = ''.
i_receivers-notif_del = 'X'.
i_receivers-notif_ndel = 'X'.
APPEND i_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = l_sender_address
sender_address_type = l_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = i_packing_list
contents_bin = i_attachment
contents_txt = i_message
receivers = i_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
l_error = sy-subrc.
Populate zreceiver return code
LOOP AT i_receivers.
l_receiver = i_receivers-retrn_code.
ENDLOOP.
ENDFORM. "send_file_as_email_attachment
&----
*& 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 = ''
AND RETURN.
ENDFORM. "
11-16-2005 12:01 AM
11-16-2005 3:33 AM
11-16-2005 6:07 AM
11-16-2005 2:53 PM
Hi Veni,
I hope this code will help you.
&----
*& Report ZPDF_MAIL_TEST_2 *
*& *
&----
*& *
*& *
&----
REPORT ZPDF_MAIL_TEST_2 .
INCLUDE <%_LIST>.
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: BEGIN OF DATA_TAB OCCURS 20,
LINE(255),
END OF DATA_TAB.
DATA:
MSTR_PRINT_PARMS LIKE PRI_PARAMS,
MC_VALID(1) TYPE C,
MI_BYTECOUNT TYPE I,
MI_LENGTH TYPE I,
MI_RQIDENT LIKE TSP01-RQIDENT,
MTAB_PDF LIKE TLINE OCCURS 10 WITH HEADER LINE,
MC_FILENAME LIKE RLGRAP-FILENAME,
V_MAILID(241) TYPE C.
DATA: TAB_LINES LIKE SY-TABIX.
CONCATENATE 'C:\' SY-REPID '.PDF' INTO MC_FILENAME.
WRITE :/5 '01234567890123456789012345678901234567890123456789012345678',
75 '012345678901234567890123456789012345678901234567890123456789'
.
Create a new spool from the data in data_tab
NEW-PAGE PRINT ON
DESTINATION 'LOCL' "<<== my printer
receiver 'TJOSVOB'
COVER TEXT 'Spool title' "<<== Title or Spool req. name
LIST NAME 'List name'
LIST DATASET 'List Dataset'
IMMEDIATELY ' ' " X means print now
KEEP IN SPOOL 'X' " X means keep spool
NEW LIST IDENTIFICATION 'X'
NO DIALOG .
WRITE :/5 '01234567890123456789012345678901234567890123456789012345678',
75 '012345678901234567890123456789012345678901234567890123456789'
.
NEW-PAGE PRINT OFF.
Captue the spool number, it is in SY-SPONO
WRITE: / 'Spool #', SY-SPONO.
MI_RQIDENT = SY-SPONO.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = MI_RQIDENT
NO_DIALOG = SPACE
DST_DEVICE = MSTR_PRINT_PARMS-PDEST
IMPORTING
PDF_BYTECOUNT = MI_BYTECOUNT
TABLES
PDF = MTAB_PDF
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.
Creation of the document to be sent
DOC_CHNG-OBJ_NAME = 'TEST'.
DOC_CHNG-OBJ_DESCR = 'Test for PDF'.
OBJTXT = 'Contents of mail'.
APPEND OBJTXT.
OBJTXT = 'PDF'.
APPEND OBJTXT.
OBJTXT = 'PDF'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creation of the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
Creation of the document attachment
(Assume that the data in OBJBIN is in BMP format)
*
*LOOP AT MTAB_PDF.
*APPEND LINES OF MTAB_PDF TO OBJBIN.
*ENDLOOP.
MC_FILENAME = 'c:\test.pdf' .
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = MI_BYTECOUNT
FILENAME = MC_FILENAME
FILETYPE = 'BIN'
TABLES
DATA_TAB = MTAB_PDF
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
MC_FILENAME = 'c:\test.pdf' .
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = MC_FILENAME
FILETYPE = 'BIN'
TABLES
DATA_TAB = OBJBIN.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'TEST.pdf'. APPEND OBJHEAD.
Creation of the entry for the compressed attachment
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
OBJPACK-OBJ_NAME = 'Testing PDF Attachment'.
OBJPACK-OBJ_DESCR = 'Customes Ageing report PDF Output Attachment'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
CLEAR V_MAILID.
V_MAILID = 'RAGHOTHAMR@INTELLIGROUP.COM'.
RECLIST-RECEIVER = V_MAILID.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
* Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
EXCEPTION HANDLING
CASE SY-SUBRC.
WHEN 0.
WRITE: / 'Mail sent with attachment'.
WHEN 1.
WRITE: / 'No authorization for sending to the specified number',
'of recipients'.
WHEN 2.
WRITE: / 'Document could not be sent to any recipient'.
WHEN 4.
WRITE: / 'No send authorization'.
WHEN OTHERS.
WRITE: / 'Error occurred while sending'.
ENDCASE.
Cheers,
Saraswathi.
11-16-2005 10:35 PM
Hi,
I changed 'SO_DOCUMENT_SEND_API1' to 'SO_NEW_DOCUMENT_ATT_SEND_API1'. With 'SO_DOCUMENT_SEND_API1' it was sending email with XLS attachment. Now after changing the function it is not sending email. Before I wrote the code for XLS file, now I want to change it to PDF file. Where should I change it. please look at my code.
Thanks
Neelima.
FORM EMAIL_DATA.
Populate details for .xls file
PERFORM build_xls_data_table.
Populate message body
PERFORM populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
TABLES i_message
i_attach
USING p_email
'Commercial Invoice'
'XLS'
'COMMERCIAL_INVOICE'
' '
' '
' '
CHANGING g_error
g_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
ENDFORM. " EMAIL_DATA
&----
*& Form build_xls_data_table
&----
text
----
--> p1 text
<-- p2 text
----
FORM build_xls_data_table .
CONSTANTS:
con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
i_attach-line = 'AMERICA, INC.'.
APPEND i_attach.
i_attach-line = 'Commercial Invoice Details., INC.'.
APPEND i_attach.
i_attach-line = 'Details of Commercial Invoice:'.
APPEND i_attach.
LOOP AT FTAB.
i_attach-line = FTAB-VBELN.
APPEND i_attach.
CONCATENATE 'MATERIAL' 'NET PRICE' INTO i_attach
SEPARATED BY space.
CONCATENATE con_cret i_attach INTO i_attach.
APPEND i_attach.
LOOP AT ITAB_VBRP INTO wa_data.
CONCATENATE wa_data-MATNR
wa_data-NETWR INTO i_attach
SEPARATED BY space. "con_tab.
CONCATENATE con_cret i_attach INTO i_attach.
APPEND i_attach.
ENDLOOP.
ENDLOOP.
ENDFORM. " build_xls_data_table
&----
*& Form populate_email_message_body
&----
text
----
--> p1 text
<-- p2 text
----
FORM populate_email_message_body .
DATA: l_buffer(250).
REFRESH i_message.
l_buffer = 'COMMERCIAL INVOICE DATA DOWNLOAD. '.
SKIP 2.
CONCATENATE l_buffer 'You will find an attachment in this message.'
INTO l_buffer.
i_message = l_buffer.
APPEND i_message.
ENDFORM. " populate_email_message_body
&----
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
&----
Send email
----
FORM send_file_as_email_attachment TABLES p_i_message
p_i_attach
USING p_email1
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
CHANGING p_error
p_receiver.
DATA: l_error TYPE sy-subrc,
l_receiver TYPE sy-subrc,
l_email LIKE somlreci1-receiver,
l_mtitle LIKE sodocchgi1-obj_descr,
l_format TYPE so_obj_tp,
l_attfilename TYPE so_obj_des ,
l_attdescription TYPE so_obj_nam ,
l_sender_address LIKE soextreci1-receiver,
l_sender_address_type LIKE soextreci1-adr_typ.
l_email = p_email1.
l_mtitle = p_mtitle.
l_format = p_format.
l_attfilename = p_filename.
l_attdescription = p_attdescription.
l_sender_address = p_sender_address.
l_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 = l_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE i_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( i_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = l_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR i_attachment.
REFRESH i_attachment.
i_attachment[] = p_i_attach[].
Describe the body of the message
CLEAR i_packing_list.
REFRESH i_packing_list.
i_packing_list-transf_bin = space.
i_packing_list-head_start = 1.
i_packing_list-head_num = 0.
i_packing_list-body_start = 1.
DESCRIBE TABLE i_message LINES i_packing_list-body_num.
i_packing_list-doc_type = 'RAW'.
APPEND i_packing_list.
Create attachment notification
i_packing_list-transf_bin = 'X'.
i_packing_list-head_start = 1.
i_packing_list-head_num = 1.
i_packing_list-body_start = 1.
DESCRIBE TABLE i_attachment LINES i_packing_list-body_num.
i_packing_list-doc_type = l_format.
i_packing_list-obj_descr = l_attdescription.
i_packing_list-obj_name = l_attfilename.
i_packing_list-doc_size = i_packing_list-body_num * 255.
APPEND i_packing_list.
Add the recipients email address
CLEAR i_receivers.
REFRESH i_receivers.
i_receivers-receiver = l_email.
i_receivers-rec_type = 'U'.
i_receivers-com_type = 'INT'.
i_receivers-notif_del = 'X'.
i_receivers-notif_ndel = 'X'.
APPEND i_receivers.
i_receivers-receiver = l_email.
i_receivers-rec_type = 'B'.
i_receivers-com_type = ''.
i_receivers-notif_del = 'X'.
i_receivers-notif_ndel = 'X'.
APPEND i_receivers.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = w_doc_data
PUT_IN_OUTBOX = 'X'
IMPORTING
SENT_TO_ALL = w_sent_all
NEW_OBJECT_ID =
TABLES
PACKING_LIST = i_packing_list
OBJECT_HEADER =
CONTENTS_BIN = i_attachment
CONTENTS_TXT = i_message
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
RECEIVERS = i_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.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = l_sender_address
sender_address_type = l_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = i_packing_list
contents_bin = i_attachment
contents_txt = i_message
receivers = i_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
l_error = sy-subrc.
Populate zreceiver return code
LOOP AT i_receivers.
l_receiver = i_receivers-retrn_code.
ENDLOOP.
ENDFORM. "send_file_as_email_attachment
&----
*& 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 = ''
AND RETURN.
ENDFORM. "
11-16-2005 3:11 PM
Hi Veni,
check this links it may help you...
http://www.geocities.com/mpioud/Z_EMAIL_ABAP_REPORT.html
http://www.thespot4sap.com/Articles/SAP_Mail_SO_Object_Send.asp
http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm
reward points for helpfull answers and close the thread if your question is solved.
regards,
venu.
11-17-2005 11:30 AM
Hi Veni,
Go through the code that I sent you. Try executing the same by copying it in $tmp and then let me know if it doesn't work.
All the best.
Cheers,
Saraswathi.