2006 Jun 21 12:09 PM
Hello All,
I have to send a smartform with email as attachement. CAn anyone help in this how to do that,.
Thanks in Advance
Anu
2006 Jun 21 12:10 PM
Hai Maheswari
Go through the following Code
REPORT ZRICH_0003.
DATA: ITCPO LIKE ITCPO,
TAB_LINES LIKE SY-TABIX.
Variables for EMAIL functionality
DATA: MAILDATA LIKE SODOCCHGI1.
DATA: MAILPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: MAILHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: MAILBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: MAILTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: MAILREC LIKE SOMLREC90 OCCURS 0 WITH HEADER LINE.
DATA: SOLISTI1 LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
PERFORM SEND_FORM_VIA_EMAIL.
************************************************************************
FORM SEND_FORM_VIA_EMAIL *
************************************************************************
FORM SEND_FORM_VIA_EMAIL.
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 = 'TEST'.
Mail Subject
MAILDATA-OBJ_DESCR = 'Subject'.
Mail Contents
MAILTXT-LINE = 'Here is your file'.
APPEND MAILTXT.
Prepare Packing List
PERFORM PREPARE_PACKING_LIST.
Set recipient - email address here!!!
MAILREC-RECEIVER = 'itsme@whatever.com'.
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.
ENDFORM.
************************************************************************
Form PREPARE_PACKING_LIST
************************************************************************
FORM PREPARE_PACKING_LIST.
CLEAR: MAILPACK, MAILBIN, MAILHEAD.
REFRESH: MAILPACK, MAILBIN, MAILHEAD.
DESCRIBE TABLE MAILTXT LINES TAB_LINES.
READ TABLE MAILTXT INDEX TAB_LINES.
MAILDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( MAILTXT ).
Creation of the entry for the compressed document
CLEAR MAILPACK-TRANSF_BIN.
MAILPACK-HEAD_START = 1.
MAILPACK-HEAD_NUM = 0.
MAILPACK-BODY_START = 1.
MAILPACK-BODY_NUM = TAB_LINES.
MAILPACK-DOC_TYPE = 'RAW'.
APPEND MAILPACK.
Creation of the document attachment
This form gets the OTF code from the SAPscript form.
If you already have your OTF code, I believe that you may
be able to skip this form. just do the following code, looping thru
your SOLISTI1 and updating MAILBIN.
PERFORM GET_OTF_CODE.
LOOP AT SOLISTI1.
MOVE-CORRESPONDING SOLISTI1 TO MAILBIN.
APPEND MAILBIN.
ENDLOOP.
DESCRIBE TABLE MAILBIN LINES TAB_LINES.
MAILHEAD = 'TEST.OTF'.
APPEND MAILHEAD.
Creation of the entry for the compressed attachment
MAILPACK-TRANSF_BIN = 'X'.
MAILPACK-HEAD_START = 1.
MAILPACK-HEAD_NUM = 1.
MAILPACK-BODY_START = 1.
MAILPACK-BODY_NUM = TAB_LINES.
MAILPACK-DOC_TYPE = 'OTF'.
MAILPACK-OBJ_NAME = 'TEST'.
MAILPACK-OBJ_DESCR = 'Subject'.
MAILPACK-DOC_SIZE = TAB_LINES * 255.
APPEND MAILPACK.
ENDFORM.
************************************************************************
Form GET_OTF_CODE
************************************************************************
FORM GET_OTF_CODE.
DATA: BEGIN OF OTF OCCURS 0.
INCLUDE STRUCTURE ITCOO .
DATA: END OF OTF.
DATA: ITCPO LIKE ITCPO.
DATA: ITCPP LIKE ITCPP.
CLEAR ITCPO.
ITCPO-TDGETOTF = 'X'.
Start writing OTF code
CALL FUNCTION 'OPEN_FORM'
EXPORTING
FORM = 'ZTEST_FORM'
LANGUAGE = SY-LANGU
OPTIONS = ITCPO
DIALOG = ' '
EXCEPTIONS
OTHERS = 1.
CALL FUNCTION 'START_FORM'
EXCEPTIONS
ERROR_MESSAGE = 01
OTHERS = 02.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
WINDOW = 'MAIN'
EXCEPTIONS
ERROR_MESSAGE = 01
OTHERS = 02.
Close up Form and get OTF code
CALL FUNCTION 'END_FORM'
EXCEPTIONS
ERROR_MESSAGE = 01
OTHERS = 02.
MOVE-CORRESPONDING ITCPO TO ITCPP.
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = ITCPP
TABLES
OTFDATA = OTF
EXCEPTIONS
OTHERS = 1.
Move OTF code to structure SOLI form email
CLEAR SOLISTI1. REFRESH SOLISTI1.
LOOP AT OTF.
SOLISTI1-LINE = OTF.
APPEND SOLISTI1.
ENDLOOP.
ENDFORM.
Thanks & regards
Sreenivasulu O
2006 Jun 21 12:15 PM
Hi,
Try function module SO_NEW_DOCUMENT_ATT_SEND_API1
Regards,
Amole
2006 Jun 21 12:16 PM
2006 Jun 21 12:19 PM
hi,
Call the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.
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.
Regards,
Richa
2006 Jun 21 12:19 PM
Hi,
Following are the things u hav to do,
A. Calling smartform form function module and getting OTF data from this.
B. convert this to pdf using CONVERT_OTF_2_PDF func mod. this returns itab for pdf data.
c. Now using SO_NEW_DOCUMENT_ATT_SEND_API1 func module to send mail
Check out the Forum on this topic, u will find lots of discussions made.
rgds,
latheesh
Message was edited by: Latheesh Kaduthara
2006 Jun 21 12:23 PM
Hi anu
&----
*& Report ZSENDMAIL_TO_VENDOR_AU *
&----
*& Author : kiran *
*& Desc : Sending an External Mail to Vendors *
*& Date : 15/10/04 *
&----
report zsendmail_to_vendor_au
message-id zfi
no standard page heading.
************************************************************************
TABLES DECLARATIONS
************************************************************************
tables: lfa1,reguh.
************************************************************************
INTERNAL TABLE DECLARATIONS
************************************************************************
data: begin of it_data occurs 0,
lifnr like reguh-lifnr, "vendor
vblnr like reguh-vblnr, "Document Number of the Payment Doc
rbetr like reguh-rbetr, "Amount in Local Currency
rskon like reguh-rskon, "Total Cash Discount (Local Curr)
adrnr like reguh-adrnr, "Address Number
smtp_addr like ADR6-SMTP_ADDR, "Vendor Email address
end of it_data.
data: begin of it_data_final occurs 0,
lifnr like reguh-lifnr, "vendor
vblnr like reguh-vblnr, "Document Number of Payment Doc
rbetr like reguh-rbetr, "Amount in Local Currency
rskon like reguh-rskon, "Total Cash Discount(Local Curr)
adrnr like reguh-adrnr, "Address Number
smtp_addr like ADR6-SMTP_ADDR, "Vendor Email address
end of it_data_final.
************************************************************************
DATA DECLARATIONS
************************************************************************
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: v_flag type c.
data: vrbetr(18) type c,
vrskon(18) type c.
************************************************************************
SELECTION SCREEN
************************************************************************
selection-screen begin of block b1 with frame title text-h01.
select-options: s_lifnr for lfa1-lifnr.
select-options: s_laufd for reguh-laufd.
select-options: s_laufi for reguh-laufi.
selection-screen end of block b1.
************************************************************************
SELECTION SCREEN EVENTS
************************************************************************
at selection-screen.
perform validate_lifnr.
************************************************************************
START-OF-SELECTION
************************************************************************
start-of-selection.
perform get_data.
************************************************************************
END-OF-SELECTION
************************************************************************
end-of-selection.
if v_flag = 'X'.
perform send_mail.
else.
message i003 with 'No Data Found'(001).
endif.
&----
*& Form VALIDATE_LIFNR
&----
Validating the Vendor
----
form validate_lifnr.
select lifnr
up to 1 rows
into (lfa1-lifnr)
from lfa1
where lifnr in s_lifnr.
endselect.
if sy-subrc ne 0.
message i003 with 'Invalid Range of Vendor'(002) s_lifnr-low
'To'(003) s_lifnr-high.
endif.
endform. " VALIDATE_LIFNR
&----
*& Form GET_DATA
&----
Getting the Data
----
form get_data.
select a~lifnr
a~vblnr
a~rbetr
a~rskon
a~adrnr
b~smtp_addr
into it_data
into it_data
from reguh as a
inner join ADR6 as b
on aadrnr eq bADDRNUMBER
where a~lifnr in s_lifnr
and a~laufd in s_laufd
and a~laufi in s_laufi
and a~xvorl ne 'X'.
append it_data.
exit.
endselect.
if sy-subrc eq 0.
v_flag = 'X'.
else.
v_flag = space.
endif.
endform. " GET_DATA
&----
*& Form SEND_MAIL
&----
Sending the Mail to Vendors
----
form send_mail.
*--Creation of the document to be sent
*--Mail Subject
doc_chng-obj_descr = 'Vendor Details sent by kiran'.
*--Mail Contents
loop at it_data.
it_data_final = it_data.
objtxt = 'abc sent this Testing mail'.
append objtxt.
objtxt = 'Through ABAP Program for the following Vendors'.
append objtxt.
concatenate 'Vendor No: ' it_data_final-lifnr into objtxt.
append objtxt.
concatenate 'Parent Document No: ' it_data_final-vblnr into objtxt.
append objtxt.
write it_data_final-rbetr to vrbetr.
concatenate 'Amount in Local Currency: ' vrbetr into objtxt.
append objtxt.
write it_data_final-rskon to vrskon.
concatenate 'Discount amount in Local Currency: ' vrskon into objtxt.
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.
*--Completing the recipient list
reclist-receiver = it_data_final-smtp_addr.
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.
case sy-subrc.
when 0.
write:/ 'Mail Sent Successfully to Vendor: ',it_data_final-lifnr,
'at',it_data_final-smtp_addr.
when 1.
write: /
'No authorization for sending to the specified number 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.
clear: it_data_final,tab_lines,vrbetr,vrskon.
refresh: reclist,objpack,objtxt,it_data_final.
endloop.
endform. " SEND_MAIL
Thanks,
Kiran.M
Message was edited by: kiran machavarapu