‎2007 May 02 1:17 PM
I made a report that creates one pdf and gets the otf to send it as email.It works fine .
Now i want to put as attachment more pdf's that i have already create and store in my pc.
For example i will have 2 pdf (1 from the otf code , and 1 in c:\test.pdf)
The FM that i use is
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 someone has a idea ...
I can send my code to see what happens ....
‎2007 May 02 1:24 PM
HI,
Check for logic in the standard FM 'FI_SEND_PDF', if this FM is not available see sap note 976306.
Try this program
* Read SRQ document from Application Server
DATA: BEGIN OF INT_SRQ OCCURS 0,
FIELD(256),
END OF INT_SRQ.
DATA: WS_FILE1(100) VALUE '/tmp/safety_questionaire.pdf'.
OPEN DATASET WS_FILE1 FOR INPUT IN BINARY MODE.
DO.
READ DATASET WS_FILE1 INTO INT_SRQ-FIELD.
IF SY-SUBRC EQ 0.
APPEND INT_SRQ.
ELSE.
EXIT.
ENDIF.
ENDDO.
* Read Insurance document from Application Server
DATA: BEGIN OF INT_INSURANCE OCCURS 0,
FIELD(256),
END OF INT_INSURANCE.
DATA: WS_FILE2(100) VALUE '/tmp/insurance.pdf'.
OPEN DATASET WS_FILE2 FOR INPUT IN BINARY MODE.
DO.
READ DATASET WS_FILE2 INTO INT_INSURANCE-FIELD.
IF SY-SUBRC EQ 0.
APPEND INT_INSURANCE.
ELSE.
EXIT.
ENDIF.
ENDDO.
*****************************************************************
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.
if sy-subrc eq 0.
message i000(0) with 'e-mail sent successfully'.
endif.
************************************************************************
* 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 = 'SRQ '.
* Mail Subject
maildata-obj_descr = Questionnaires.
* Mail Contents
mailtxt-line = 'Questionnaires'.
append mailtxt.
* Prepare Packing List
perform prepare_packing_list.
* Set recipient - email address here!!!
mailrec-receiver = 'vamseekrishna_k@yahoo.co.in'.
mailrec-rec_type = 'U'.
append mailrec.
* Sending the document
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = maildata
put_in_outbox = 'x'
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.
mailhead = 'TEST.pdf'.
append mailhead.
* File 1
CALL FUNCTION 'QCE1_CONVERT'
TABLES
T_SOURCE_TAB = INT_SRQ
T_TARGET_TAB = mailbin.
append mailbin.
*CLEAR:TAB_LINES.
describe table mailbin lines tab_lines.
READ TABLE MAILBIN INDEX TAB_LINES.
mailpack-transf_bin = 'X'.
mailpack-head_start = 1.
mailpack-head_num = 0.
mailpack-body_start = 1.
mailpack-body_num = tab_lines.
mailpack-doc_type = 'PDF'.
mailpack-obj_name = 'TEST1'.
mailpack-obj_descr = 'attach1'.
mailpack-doc_size = tab_lines * 255.
append mailpack.
IF SY-SUBRC EQ 0.
MESSAGE I000(2) WITH 'FILE1 READ IS OKAY'.
ENDIF.
**File 2
CALL FUNCTION 'QCE1_CONVERT'
TABLES
T_SOURCE_TAB = INT_INSURANCE
T_TARGET_TAB = mailbin.
*
append mailbin.
data:TAB_LINES2 type i.
DESCRIBE TABLE MAILBIN LINES TAB_LINES2.
READ TABLE MAILBIN INDEX TAB_LINES2.
*
data: start type i.
data: end type i.
end = TAB_LINES2.
start = tab_lines + 1.
*
* describe table mailbin lines end.
*
mailpack-transf_bin = 'X'.
mailpack-head_start = 1.
mailpack-head_num = 0.
mailpack-body_start = start.
mailpack-body_num = end.
mailpack-doc_type = 'PDF'.
mailpack-obj_name = 'TEST2'.
mailpack-obj_descr = 'attach2'.
mailpack-doc_size = ( tab_lines2 - 1 ) * 255 + strlen( mailBIN ).
append mailpack.
**
if sy-subrc eq 0.
message i000(1) with 'file 2 read ok'.
endif.
endform.Regards
Sudheer
‎2007 May 02 2:44 PM
Hi,
You need to carefully build the internal table 'PACKING_LIST'.
If you have 2 PDF files the approach would typically be:
a. read the first file into an internal table in BINARY MODE.
b. packing_list-body_start = 1.
c. Fill table CONTENTS_BIN with the contents of internal table in step a.
Each line should be having 255 characters only. Count the number of lines.
d. packing_list-body_num = number of lines.
e. read the second file into internal table.
d. packing_list-body_start = 1 + number of lines.
c. Fill table CONTENTS_BIN with the contents of internal table in step a.
Each line should be having 255 characters only. Count the number of lines.
d. packing_list-body_num = number of lines.
You can actually put this in a loop and increment packing_list-body_start.
Hope this helps.
Thanks and regards,
S. Chandra Mouli.
‎2007 May 02 6:56 PM
Hi,
Check the following program in the link:
http://www.sap-img.com/abap/sending-email-with-attachment.htm
Regards,
Bhaskar
‎2007 May 02 6:57 PM
Hi
Please have a look on the link:
http://www.sap-img.com/abap/sending-email-with-attachment.htm
Regards,
Sreeram