05-11-2006 10:47 AM
Hi,
I am trying to sead an email with attachment as a word document using the FM SO_NEW_DOCUMENT_ATT_SEND_API1.
The Details which has to be send are stored in an internal table. I have compressed that table and I am passing the same to the table parameter CONTENTS_BIN. But the attachment is not the readable format.
Which document type should i use PACKING_LIST-DOC_TYPE = ?.
Please advice me.
Thanks in advance.
05-11-2006 10:55 AM
05-11-2006 11:03 AM
HI
CHECK THIS THREAD
http://www.sapdevelopment.co.uk/reporting/email/emailhome.htm
HOPE THIS HELPS,
PRIYA.
05-11-2006 11:11 AM
Hi Sabari,
This sample code will send a word document as email attachment to vendor.
&----
Form f_final_output *
&----
This perform will generate output as an attachment and will send to *
user *
----
All the Output data has been entered into a single internal table of type character
(table ? Objbin) and passing this table to function module
form f_final_output.
v_total = c_0.
objbin-line = text-025.
append objbin.
loop at i_headertable into wa_headertable.
v_total = v_total + c_1.
To supress the leading zeros.
write wa_headertable-kunag to wa_headertable-kunag.
write wa_headertable-vbeln to v_vbeln.
write wa_headertable-kunnr to wa_headertable-kunnr.
write wa_headertable-vbelv to wa_headertable-vbelv.
write wa_headertable-kunnr_no to wa_headertable-kunnr_no.
write wa_headertable-shipment_no to wa_headertable-shipment_no.
write wa_headertable-lifnr to wa_headertable-lifnr.
To add horizantal line
objbin-line = c_line.
append objbin.
objbin-line = text-005. " Sold to party
objbin-line+50(15) = text-001. " Delivery no.
append objbin.
endloop.
endform. " f_final_output.
&----
Form f_mail *
&----
This perform send email *
----
form f_email.
concatenate v_filename '\' text-026 '_' v_country '_'
v_date into v_filename.
Creation of the document to be sent
doc_chng-obj_name = text-027. " del_not_yet_picked
doc_chng-obj_descr = text-025. " Deliveries not Yet Picked
" Printout
objtxt = text-025. " Deliveries not Yet Picked
" Printout
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 = c_1.
objpack-head_num = c_0.
objpack-body_start = c_1.
objpack-body_num = tab_lines.
objpack-doc_type = c_raw.
append objpack.
**Creation of the document attachment
describe table objbin lines tab_lines.
objhead = 'del_not_yet_picked.doc'.
append objhead.
Creation of the entry for the compressed attachment
objpack-transf_bin = c_x. " X = attachment (for Attachment)
objpack-head_start = c_1.
objpack-head_num = c_1.
objpack-body_start = c_1.
objpack-body_num = tab_lines.
objpack-doc_type = c_document.
objpack-obj_name = v_filename.
objpack-obj_descr = v_filename.
objpack-doc_size = tab_lines * 255.
append objpack.
Completing the recipient list
reclist-receiver = sy-uname. "v_emailid .
reclist-rec_type = c_b. "c_u.
reclist-express = c_x.
append reclist.
Sending the document
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = doc_chng
put_in_outbox = c_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.
case sy-subrc.
when 0.
write: / 'Result of the send process:'."#EC NOTEXT
loop at reclist.
write: / reclist-receiver(48), ':'.
if reclist-retrn_code = c_0.
write 'The document was sent'."#EC NOTEXT
else.
write 'The document could not be sent'."#EC NOTEXT
endif.
endloop.
when 1.
write: / 'No authorization for sending to the specified number',
'of recipients'."#EC NOTEXT
when 2.
write: / 'Document could not be sent to any recipient'."#EC NOTEXT
when 4.
write: / 'No send authorization'."#EC NOTEXT
when others.
write: / 'Error occurred while sending'. "#EC NOTEXT
endcase.
clear objpack.
clear objhead.
clear objtxt.
refresh objpack.
refresh objhead.
refresh objtxt.
clear objbin.
refresh objbin.
clear : reclist.
refresh reclist.
clear :v_emailid, v_filename .
endform. " f_email.
Regards,
Susmitha
05-11-2006 11:29 AM
Hi Susmitha,
Thanks for your reply.
I just wants to know which document type should I use ?
i.e c_document means ?
objpack-doc_type = c_document.
With Regards,
Sabari
05-11-2006 11:39 AM
hi,
did u try using PACKING_LIST-DOC_TYPE = RAW.
hope this helps,
priya.
05-11-2006 11:45 AM
Hai Sabari
Check the following Code
FORM SEND_MAIL.
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: TAB_LINES LIKE SY-TABIX.
DATA L_NUM(3).
Creation of the document to be sent
File Name
DOC_CHNG-OBJ_NAME = 'SENDFILE'.
Mail Subject
DOC_CHNG-OBJ_DESCR = 'Delivered Mail'.
Mail Contents
OBJTXT = 'Object text'.
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
LOOP AT ITAB_DATA.
CONCATENATE ITAB_DATA-PRODUCTOR
ITAB_DATA-VBELN
ITAB_DATA-POSNR
ITAB_DATA-MATNR INTO OBJBIN.
APPEND OBJBIN.
ENDLOOP.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'ORDERS'.
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 = 'TXT'.
OBJPACK-OBJ_NAME = 'WEBSITE'.
OBJPACK-OBJ_DESCR = 'ORDERS.TXT'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
Completing the recipient list
target recipent
clear RECLIST.
RECLIST-RECEIVER = 'test@here.com'.
RECLIST-EXPRESS = 'X'.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
copy recipents
clear RECLIST.
RECLIST-RECEIVER = 'secondtest@here.com'.
RECLIST-EXPRESS = 'X'.
RECLIST-REC_TYPE = 'U'.
RECLIST-COPY = 'X'.
APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
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.
ENDFORM. " SEND_MAIL
Thanks & Regards
Sreenivasulu P
05-11-2006 11:58 AM
05-11-2006 12:05 PM
i have given RAW and CSV both are working fine.
check your program with this document type.
WA_OBJPACK-TRANSF_BIN = 'X'.
WA_OBJPACK-HEAD_START = 1.
WA_OBJPACK-HEAD_NUM = 1.
WA_OBJPACK-BODY_START = 1.
WA_OBJPACK-BODY_NUM = V_TABLE_LINES .
WA_OBJPACK-DOC_TYPE = 'CSV' .
WA_OBJPACK-DOC_TYPE = 'RAW' .
WA_OBJPACK-DOC_SIZE = V_TABLE_LINES * 255.
APPEND WA_OBJPACK TO IT_OBJPACK.
regards
srikanth