02-03-2005 10:17 AM
Hi,
Someone know to how use this FM SO_NEW_DOCUMENT_ATT_SEND_API1??
02-03-2005 10:28 AM
02-03-2005 10:27 AM
Here is a sample code:
CALL FUNCTION 'CONVERT_OTF_2_PDF'
IMPORTING
bin_filesize = pdf_bytecount
TABLES
otf = otf_data
doctab_archive = lt_docs
lines = pdfout
EXCEPTIONS
err_conv_not_possible = 1
err_otf_mc_noendmarker = 2
OTHERS = 3.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
TABLES
content_in = pdfout
content_out = pdfout2.
CLEAR: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.
REFRESH: mailtxt, mailbin, mailpack, mailhead, mailrec.
Creation of the document to be sent File Name
maildata-obj_name = 'Order output'.
Mail Subject
CONCATENATE 'Order :' vbdka-vbeln INTO maildata-obj_descr .
Mail Contents
mailtxt-line = 'Order output '.
APPEND mailtxt.
Set recipient - email address here!!!
SELECT SINGLE adrnr FROM kna1
INTO adrnr_sv
WHERE kunnr = vbdka-kunnr.
SELECT SINGLE *
FROM adrc
INTO adrc_sv
WHERE addrnumber = adrnr_sv.
SELECT SINGLE smtp_addr FROM adr6
INTO email
WHERE addrnumber = adrnr_sv
AND flgdefault = 'X'.
mailrec-receiver = email.
mailrec-rec_type = 'U'.
APPEND mailrec.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = maildata
put_in_outbox = ' '
TABLES
packing_list = mailpack
object_header = mailhead
contents_bin = mailbin
contents_txt = mailtxt
receivers = mailrec
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
-
If it helps please give points.
02-03-2005 10:45 AM
Hi Fuat,
I have a question what is mailbin?? I put my code here so maybe you can help me
Tks
********************************************
CALL FUNCTION 'CONVERT_OTF_2_PDF'
EXPORTING
use_otf_mc_cmd = 'X'
IMPORTING
bin_filesize = L_PDF_LEN
TABLES
otf = OUTPUT_DATA-OTFDATA
doctab_archive = itab2
lines = l_t_pdfdata_tab
EXCEPTIONS
err_conv_not_possible = 1
err_otf_mc_noendmarker = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CONCATENATE 'C:\factura' d_vbeln '.pdf' into file_name.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
bin_filesize = L_PDF_LEN
filename = file_name
filetype = 'BIN'
mode = ' '
IMPORTING
filelength = L_PDF_LEN
TABLES
data_tab = l_t_pdfdata_tab
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.
ENDFORM. " PDF
**&----
*
**& Form EMAIL
**&----
*
text
**----
*
--> p1 text
<-- p2 text
**----
*
FORM email .
SELECT * FROM vbrk
INTO w_vbrk
WHERE vbeln = d_vbeln.
ENDSELECT.
SELECT * FROM kna1
INTO w_kna1
WHERE kunnr = w_vbrk-kunrg.
ENDSELECT.
CALL FUNCTION 'ADDR_GET_REMOTE'
EXPORTING
ADDRNUMBER = w_kna1-adrnr
ADDRHANDLE =
TABLES
ADDR1 =
ADTEL =
ADFAX =
ADTTX =
ADTLX =
ADSMTP = v_email
ADRML =
ADX400 =
ADRFC =
ADPRT =
ADSSF =
ADURI =
ADPAG =
ADDR_REM =
ADCOMREM =
EXCEPTIONS
PARAMETER_ERROR = 1
ADDRESS_NOT_EXIST = 2
INTERNAL_ERROR = 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.
MOVE v_email-smtp_addr TO dest.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
COMPRESSED_SIZE =
TABLES
IN = l_t_pdfdata_tab
OUT = objbin
EXCEPTIONS
OTHERS = 1
.
if sy-subrc <> 0.
message ID '61' TYPE 'E' NUMBER '731'
with 'TABLE_COMPRESS'.
endif.
Title and Description
docdata-obj_name = file_name.
docdata-obj_descr = 'Factura'.
Main Text
objtxt = 'Factura:'.
append objtxt.
objtxt = d_vbeln.
append objtxt.
Write Packing List (Main)
describe table objtxt lines tab_lines.
read table objtxt index tab_lines.
docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
clear objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'PDF'.
append objpack.
Create Message Attachment
Write Packing List (Attachment)
att_type = 'ALI'.
describe table objbin lines tab_lines.
read table objbin index tab_lines.
objpack-doc_size = L_PDF_LEN + ( tab_lines - 1 ) * 255 + strlen(
objbin ).
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = att_type.
objpack-obj_name = file_name.
objpack-obj_descr = 'Factura'.
append objpack.
Create receiver list
reclist-receiver = dest.
reclist-rec_type = 'U'.
append reclist.
reclist-receiver = sy-uname.
*
reclist-rec_type = 'B'.
*
append reclist.
Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X' "used from rel.6.10
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
tables
packing_list = objpack
OBJECT_HEADER = objhead
CONTENTS_BIN = objbin
CONTENTS_TXT = objtxt
CONTENTS_HEX = objbin
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.
IF sy-subrc <> 0.
message ID 'SO' TYPE 'S' NUMBER '023'
with docdata-obj_name.
ENDIF.
*
ENDFORM. " EMAIL
02-03-2005 11:01 AM
contents_bin = mailbin
for binary part of the mail.
Do you ask what is it in my sample code?
02-03-2005 11:13 AM
Yes, because you have a table called pdfout2 but I don't understand what do you do with that. I supposed this tables is the binary part of the email, isn't?
02-03-2005 10:28 AM
02-03-2005 10:50 AM
Hi Thomas,
In your code you have objpack-doc_type = 'RAW'. If I have a PDF I must put objpack-doc_type = 'PDF'. Because I generate the email but I can't open the attach. I don't know exactly where to enter the output of my PDF.
I hope you can help me
Tks
02-03-2005 11:03 AM
Actually have two entries in my Objpack table. The first one which is the body of the email has type RAW. The second entry (my attachment) has type HTM.
You have the input parameters for objbin and objtxt. I put the body of my email(which is plain text) in the objtxt table. I put the HTML content (or in your case PDF) in the objbin table (bin for BINARY). The packing list table (objpack) then tells the sap function how to separate out the individual elements of these two tables into the body and attachmetns of the email.
02-03-2005 11:34 AM
Hi Fuat and Thomas,
It was very helpful your suggestions. It's works!!!
Thanks a lot!! 🐵
06-09-2006 11:43 AM
Hello,
I have another query on same topic,
Is there any possibility to mention sender name in FM SO_NEW_DOCUMENT_ATT_SEND_API1.
Actually I have a requirement to send mail with some attachment and if it goes from one particular application it should go from some fixed mail address.
Thanks
-Sourabh
03-09-2011 12:01 PM
Dear Thomas,
I tried clicking the link and viewing the content. HAs it been moved to another area?
Thanks
Siva
07-25-2006 4:43 PM
Hey can some body tell me how to have multiple attachments in sending mail using this function module.
04-13-2011 6:51 AM
Hi,
You can use the below code to have multiple attachments.
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 1.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = LINES( lt_attachment ).
lt_packing_list-doc_type = 'XLS'. " You can give RAW incase if you want just a txt file.
lt_packing_list-obj_name = 'test.xls'.
lt_packing_list-obj_descr = 'test.xls'.
lt_packing_list-doc_size = lt_packing_list-body_num * 255.
APPEND lt_packing_list. CLEAR lt_packing_list.
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 1.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = LINES( lt_attachment ).
lt_packing_list-doc_type = 'XLS'. " You can give RAW incase if you want just a txt file.
lt_packing_list-obj_name = 'test1.xls'.
lt_packing_list-obj_descr = 'test1.xls'.
lt_packing_list-doc_size = lt_packing_list-body_num * 255.
APPEND lt_packing_list. CLEAR lt_packing_list.
Rest of the code will be the one you are using for sending the single attachment, this will create two attachments test and test1.
Thanks,
Manish
08-12-2014 6:39 AM