2007 Oct 10 6:22 AM
hi Gurus
Please tell me How to pass text message to the body of the email using FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'
2007 Oct 10 1:19 PM
Hi Sudheer,
Please refer to the below code.Here,it does show how to send the text in the mail.
************************************************************
Program: ZRAT Creation Date: 12.04.2007 *
Program Title : Retirement Age Trigger *
Program Author: Puneet Jhari *
Program Type : Executable *
************************************************************
Object ID : *
Technical Specification Version: *
Technical Specification Author: *
Code Quality Reviewer : *
Transport No. : SRDK906499 *
************************************************************
Program Description: *
************************************************************
Inputs *
Tables: *
Parameters *
External files: *
Outputs *
Reports: *
Tables: *
Databases: *
Screens: *
Parameters *
External files: *
Other objects: *
Return codes set by ABAP: *
************************************************************
Modification Informaion *
Program Version: *
Date : DD-MMM-YYYY *
Author : *
Description : *
Transport No.: *
************************************************************
REPORT zrat NO STANDARD PAGE HEADING.
************************************************************
*DATA DECLARATION
************************************************************
DATA : BEGIN OF wa_ccode,
bukrs TYPE t001-bukrs,
END OF wa_ccode.
DATA : itab_ccode LIKE TABLE OF wa_ccode.
DATA : BEGIN OF wa_emp,
pernr TYPE pa0001-pernr,
sachp TYPE pa0001-sachp,
sname TYPE pa0001-sname,
END OF wa_emp.
DATA : itab_emp LIKE TABLE OF wa_emp.
DATA : BEGIN OF wa_bdate,
nachn LIKE pa0002-nachn,
vorna LIKE pa0002-vorna,
pernr TYPE pa0002-pernr,
gbdat TYPE pa0002-gbdat,
END OF wa_bdate.
DATA : itab_bdate LIKE TABLE OF wa_bdate.
DATA : new_date LIKE sy-datum.
DATA : diff TYPE i.
DATA : years LIKE p0347-scryy,
months LIKE p0347-scrmm,
days LIKE p0347-scrdd.
DATA : sup_code LIKE pa0001-sachp,
itab_usrid LIKE t526-usrid,
sup_pernr LIKE pa0105-pernr.
DATA : BEGIN OF wa_email,
usrid_long LIKE pa0105-usrid_long,
END OF wa_email.
DATA : sup_email LIKE TABLE OF wa_email.
DATA : gwa_document_data LIKE sodocchgi1,
gc_name TYPE so_obj_nam VALUE 'RETIREMENT',
gc_senst TYPE so_obj_sns VALUE 'P',
gc_size TYPE so_doc_siz VALUE '510',
gi_obj_cnt LIKE TABLE OF solisti1 WITH HEADER LINE,
gi_recievers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
gwa_obj_cnt LIKE LINE OF gi_obj_cnt.
DATA : smtp_addr LIKE adr6-smtp_addr.
DATA : wa_date LIKE sy-datum,
entries LIKE sy-tabix,
name(15),
line1(18) TYPE c,
line2(20) TYPE c,
line3(20) TYPE c,
line4(23) TYPE c,
line5(10) TYPE c,
line6(45) type c,
date(2) TYPE c,
month(2) TYPE c,
year(4) TYPE c.
************************************************************
*START OF SELECTION
************************************************************
SELECT bukrs
FROM t001
INTO TABLE itab_ccode
WHERE land1 EQ 'GB'.
SORT itab_ccode.
DELETE ADJACENT DUPLICATES FROM itab_ccode.
SELECT pernr sachp sname
FROM pa0001
INTO TABLE itab_emp
FOR ALL ENTRIES IN itab_ccode
WHERE bukrs EQ itab_ccode-bukrs AND begda LE sy-datum AND
endda GE sy-datum and persg eq '1'.
SELECT nachn vorna pernr gbdat
FROM pa0002
INTO TABLE itab_bdate
FOR ALL ENTRIES IN itab_emp
WHERE pernr EQ itab_emp-pernr.
************************************************************
*TO CHECK EMPLOYEES WHOSE AGE IS NEAR 75 YEARS.
************************************************************
LOOP AT itab_bdate INTO wa_bdate.
new_date = wa_bdate-gbdat.
************************************************************
*TO CALCULATE THE AGE TILL DATE
************************************************************
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
date1 = sy-datum
date2 = new_date
output_format = '05'
IMPORTING
years = years
months = months
days = days
.
IF sy-subrc <> 0.
ENDIF.
IF years EQ 64 AND months EQ 4.
IF days GE 23 AND days LE 31.
************************************************************
*FETCH THE DATA IF THE AGE IS NEARING 75 YEARS
************************************************************
SELECT SINGLE sachp FROM pa0001 INTO sup_code WHERE pernr EQ
wa_bdate-pernr AND begda LE sy-datum AND endda GE sy-datum.
SELECT SINGLE usrid FROM t526 INTO itab_usrid WHERE sachx EQ
sup_code.
SELECT SINGLE pernr FROM pa0105 INTO sup_pernr WHERE usrid EQ
itab_usrid AND subty EQ '0001'.
clear sup_email[].
SELECT usrid_long FROM pa0105 INTO TABLE sup_email WHERE pernr EQ
sup_pernr AND subty EQ '0010'.
************************************************************
*EMAIL ADDRESS OF THE SUPERVISOR TO BE NOTIFIED
************************************************************
CLEAR gi_obj_cnt.
CLEAR gi_recievers.
CLEAR gwa_document_data.
Loop at sup_email into wa_email.
write sy-uline+0(5).
write sy-uline+10(5).
write sy-uline+20(5).
write sy-uline+30(5).
write sy-uline+40(5).
write sy-uline+50(5).
write sy-uline+60(5).
write sy-uline+70(5).
smtp_addr = wa_email-usrid_long.
gi_recievers-receiver = smtp_addr.
gi_recievers-rec_type = 'U'.
gi_recievers-com_type = 'INT'.
APPEND gi_recievers.
Endloop.
smtp_addr = '[email protected]'.
gi_recievers-receiver = smtp_addr.
gi_recievers-rec_type = 'U'.
gi_recievers-com_type = 'INT'.
APPEND gi_recievers.
gwa_document_data-obj_name = gc_name.
gwa_document_data-obj_descr = 'RETIRE'.
gwa_document_data-sensitivty = gc_senst.
gwa_document_data-obj_langu = sy-langu.
************************************************************
*CONTENT OF THE EMAIL TO BE SENT
************************************************************
line1 = 'Please note that '.
line2 = wa_bdate-vorna.
line3 = wa_bdate-nachn.
line4 = ' will be 65 years on '.
line50(4) = wa_bdate-gbdat4(4).
date = line5+2(2).
month = line5+0(2).
year = wa_bdate-gbdat+0(4) + 65.
CONCATENATE date month year INTO line5 SEPARATED BY '.'.
line6 = '.Please complete the Retirement Procedure.'.
CONCATENATE line1 line2 line3 line4 line5 line6 INTO gwa_obj_cnt
SEPARATED BY space.
APPEND gwa_obj_cnt TO gi_obj_cnt.
CLEAR gwa_obj_cnt.
DESCRIBE TABLE gi_obj_cnt LINES entries.
READ TABLE gi_obj_cnt INDEX entries.
gwa_document_data-doc_size = ( entries - 1 ) * 255 + STRLEN( gi_obj_cnt
).
************************************************************
*FUNCTION MODULE TO SEND THE EMAIL TO THE CONCERNED PERSONS
************************************************************
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = gwa_document_data
document_type = 'RAW'
commit_work = 'X'
TABLES
object_content = gi_obj_cnt
receivers = gi_recievers
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
.
************************************************************
*MESSAGE TO BE DISPLAYED AFTER THE EXECUTION
************************************************************
endif.
CASE sy-subrc.
WHEN 0.
LOOP AT gi_recievers.
IF gi_recievers-receiver = space.
name = gi_recievers-rec_id.
ELSE.
name = gi_recievers-receiver.
ENDIF.
IF gi_recievers-retrn_code = 0.
WRITE: / name, ': succesfully sent'.
ELSE.
WRITE: / name, ': error occured'.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / 'Too many receivers specified !'.
WHEN 2.
WRITE: / 'No receiver got the document !'.
WHEN 4.
WRITE: / 'Missing send authority !'.
WHEN OTHERS.
WRITE: / 'Unexpected error occurred !'.
ENDCASE.
ENDIF.
ENDIF.
ENDLOOP.
In case you have any further clarifications,do let me know.
Regards,
Puneet Jhari.
hi Gurus
Please tell me How to pass text message to the body of the email using FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'
2007 Oct 10 6:27 AM
Hi,
For only text mail use the function module
<b>SO_DOCUMENT_SEND_API1</b>
Use the below code
****************************************
Check the mail in T-code SBWP
To check the send mail status T-Code SOST
***********************************************
TABLES:pa0001.
DATA: v_ans,
v_body_lines TYPE i.
Local declarations
CONSTANTS:
c_note_00 TYPE solisti1 VALUE 'NOTE',
c_note_01 TYPE solisti1 VALUE
'Do not reply to this email, instead please contact the compensation ',
c_note_02 TYPE solisti1 VALUE
'specialist (see above for contact details). This will help avoid ',
c_note_03 TYPE solisti1 VALUE
'unnecessarily delaying your request.'.
DATA: it_packing_list TYPE TABLE OF sopcklsti1,
wa_packing_list LIKE LINE OF it_packing_list,
it_receivers TYPE TABLE OF somlreci1,
wa_receivers LIKE LINE OF it_receivers,
it_mailbody TYPE TABLE OF solisti1,
wa_mailbody LIKE LINE OF it_mailbody.
DATA: it_doc TYPE sodocchgi1.
DATA: v_sent_all TYPE boolean.
START-OF-SELECTION.
mail header
it_doc-obj_descr = 'Hello'.
Add the recipients email address
CLEAR wa_receivers.
REFRESH it_receivers.
wa_receivers-receiver = '[email protected]'.
wa_receivers-rec_type = 'U'.
wa_receivers-com_type = 'INT'.
wa_receivers-notif_del = 'X'.
wa_receivers-notif_ndel = 'X'.
APPEND wa_receivers TO it_receivers.
wa_receivers-receiver = '[email protected]'.
wa_receivers-rec_type = 'U'.
wa_receivers-com_type = 'INT'.
wa_receivers-notif_del = 'X'.
wa_receivers-notif_ndel = 'X'.
APPEND wa_receivers TO it_receivers.
Mail Body
CLEAR wa_mailbody.
REFRESH it_mailbody.
wa_mailbody-line = 'Hi All,'.
APPEND wa_mailbody TO it_mailbody.
wa_mailbody-line = ' '.
APPEND wa_mailbody TO it_mailbody.
wa_mailbody-line = 'This is a test mail'.
APPEND wa_mailbody TO it_mailbody.
wa_mailbody-line = ' '.
APPEND wa_mailbody TO it_mailbody.
DO 3 TIMES.
wa_mailbody-line = ' '.
APPEND wa_mailbody TO it_mailbody.
ENDDO.
wa_mailbody-line = c_note_00.
APPEND wa_mailbody TO it_mailbody.
wa_mailbody-line = c_note_01.
APPEND wa_mailbody TO it_mailbody.
wa_mailbody-line = c_note_02.
APPEND wa_mailbody TO it_mailbody.
wa_mailbody-line = c_note_03.
APPEND wa_mailbody TO it_mailbody.
Describe the body of the message
CLEAR wa_packing_list.
REFRESH it_packing_list.
wa_packing_list-transf_bin = space.
wa_packing_list-head_start = 1.
wa_packing_list-head_num = 0.
wa_packing_list-body_start = 1.
DESCRIBE TABLE it_mailbody LINES v_body_lines.
wa_packing_list-body_num = v_body_lines.
wa_packing_list-doc_type = 'RAW'.
APPEND wa_packing_list TO it_packing_list.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = it_doc
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = v_sent_all
TABLES
packing_list = it_packing_list
contents_txt = it_mailbody
receivers = it_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.
ELSE.
WRITE:/ 'Mail has been sent to the receivers sucessfully'.
ENDIF.
2007 Oct 10 6:41 AM
Hi
it_mailbody is coming in attachment , but i don't want in attachment .
i have already attached a pdf file to this mail,now i need to send some message in the body of mail ( not as attachment ).
2007 Oct 10 6:29 AM
Hi
see this sample code
FORM send_mail_2 USING msgid msgno msgv1.
mailuser oder Gruppe like sy-uname default 'Ruckerk'.
DATA: express_hold_time LIKE sovaltime.
DATA: text LIKE sotxtinfo.
DATA: receiver LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
MESSAGE ZF100 (FTP an UDB fehlgeschlagen)
text-msgid = msgid.
text-msgno = msgno.
text-msgv1 = msgv1.
text-msgv2 = ' '.
text-msgv3 = ' '.
text-msgv4 = ' '.
express_hold_time
express_hold_time-days = 01.
express_hold_time-h_min_sec = 240000.
receiver
receiver-receiver = mreceivr.
Gruppe von Empfängern
receiver-rec_type = 'C'.
und Expressmeldung ausgeben
receiver-express = 'X'.
APPEND receiver.
CALL FUNCTION 'MESSAGE_SEND_AS_MAIL'
EXPORTING
msgid = text-msgid
msgno = text-msgno
msgv1 = text-msgv1
msgv2 = text-msgv2
msgv3 = text-msgv3
TABLES
receivers = receiver.
IF sy-subrc <> 0.
WRITE:/ 'hat nicht geklappt', 'SY-SUBRC =', sy-subrc.
ENDIF.
PERFORM print_error_report.
Fehlermeldung zum Abbrechen des Report's ausgeben.
MESSAGE e398 WITH 'Jobabbruch' msgv1.
ENDFORM. " SEND_MAIL_2
Another Program:
*& Report ZSENDEMAIL *
*& *
*&----
*
*& Example of sending external email via SAPCONNECT *
*& *
*&----
*
REPORT zsendemail .
PARAMETERS: psubject(40) type c default 'Hello',
p_email(40) type c default '[email protected]' .
data: it_packing_list like sopcklsti1 occurs 0 with header line,
it_contents like solisti1 occurs 0 with header line,
it_receivers like somlreci1 occurs 0 with header line,
it_attachment like solisti1 occurs 0 with header line,
gd_cnt type i,
gd_sent_all(1) type c,
gd_doc_data like sodocchgi1,
gd_error type sy-subrc.
data: it_message type standard table of SOLISTI1 initial size 0
with header line.
***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
Perform populate_message_table.
*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
PERFORM send_email_message.
*Instructs mail send program for SAPCONNECT to send email(rsconn01)
perform initiate_mail_execute_program.
*&----
*
*& Form POPULATE_MESSAGE_TABLE
*&----
*
Adds text to email text table
*----
*
form populate_message_table.
Append 'Email line 1' to it_message.
Append 'Email line 2' to it_message.
Append 'Email line 3' to it_message.
Append 'Email line 4' to it_message.
endform. " POPULATE_MESSAGE_TABLE
*&----
*
*& Form SEND_EMAIL_MESSAGE
*&----
*
Send email message
*----
*
form send_email_message.
Fill the document data.
gd_doc_data-doc_size = 1.
Populate the subject/generic message attributes
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
Describe the body of the message
clear it_packing_list.
refresh it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
describe table it_message lines it_packing_list-body_num.
it_packing_list-doc_type = 'RAW'.
append it_packing_list.
Add the recipients email address
clear it_receivers.
refresh it_receivers.
it_receivers-receiver = p_email.
it_receivers-rec_type = 'U'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
append it_receivers.
Call the FM to post the message to SAPMAIL
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = gd_doc_data
put_in_outbox = 'X'
importing
sent_to_all = gd_sent_all
tables
packing_list = it_packing_list
contents_txt = it_message
receivers = it_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.
Store function module return code
gd_error = sy-subrc.
Get it_receivers return code
loop at it_receivers.
endloop.
endform. " SEND_EMAIL_MESSAGE
*&----
*
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
*&----
*
Instructs mail send program for SAPCONNECT to send email.
*----
*
form initiate_mail_execute_program.
wait up to 2 seconds.
if gd_error eq 0.
submit rsconn01 with mode = 'INT'
with output = 'X'
and return.
endif.
endform. " INITIATE_MAIL_EXECUTE_PROGRAM
Regards
ANJI
2007 Oct 10 1:19 PM
Hi Sudheer,
Please refer to the below code.Here,it does show how to send the text in the mail.
************************************************************
Program: ZRAT Creation Date: 12.04.2007 *
Program Title : Retirement Age Trigger *
Program Author: Puneet Jhari *
Program Type : Executable *
************************************************************
Object ID : *
Technical Specification Version: *
Technical Specification Author: *
Code Quality Reviewer : *
Transport No. : SRDK906499 *
************************************************************
Program Description: *
************************************************************
Inputs *
Tables: *
Parameters *
External files: *
Outputs *
Reports: *
Tables: *
Databases: *
Screens: *
Parameters *
External files: *
Other objects: *
Return codes set by ABAP: *
************************************************************
Modification Informaion *
Program Version: *
Date : DD-MMM-YYYY *
Author : *
Description : *
Transport No.: *
************************************************************
REPORT zrat NO STANDARD PAGE HEADING.
************************************************************
*DATA DECLARATION
************************************************************
DATA : BEGIN OF wa_ccode,
bukrs TYPE t001-bukrs,
END OF wa_ccode.
DATA : itab_ccode LIKE TABLE OF wa_ccode.
DATA : BEGIN OF wa_emp,
pernr TYPE pa0001-pernr,
sachp TYPE pa0001-sachp,
sname TYPE pa0001-sname,
END OF wa_emp.
DATA : itab_emp LIKE TABLE OF wa_emp.
DATA : BEGIN OF wa_bdate,
nachn LIKE pa0002-nachn,
vorna LIKE pa0002-vorna,
pernr TYPE pa0002-pernr,
gbdat TYPE pa0002-gbdat,
END OF wa_bdate.
DATA : itab_bdate LIKE TABLE OF wa_bdate.
DATA : new_date LIKE sy-datum.
DATA : diff TYPE i.
DATA : years LIKE p0347-scryy,
months LIKE p0347-scrmm,
days LIKE p0347-scrdd.
DATA : sup_code LIKE pa0001-sachp,
itab_usrid LIKE t526-usrid,
sup_pernr LIKE pa0105-pernr.
DATA : BEGIN OF wa_email,
usrid_long LIKE pa0105-usrid_long,
END OF wa_email.
DATA : sup_email LIKE TABLE OF wa_email.
DATA : gwa_document_data LIKE sodocchgi1,
gc_name TYPE so_obj_nam VALUE 'RETIREMENT',
gc_senst TYPE so_obj_sns VALUE 'P',
gc_size TYPE so_doc_siz VALUE '510',
gi_obj_cnt LIKE TABLE OF solisti1 WITH HEADER LINE,
gi_recievers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
gwa_obj_cnt LIKE LINE OF gi_obj_cnt.
DATA : smtp_addr LIKE adr6-smtp_addr.
DATA : wa_date LIKE sy-datum,
entries LIKE sy-tabix,
name(15),
line1(18) TYPE c,
line2(20) TYPE c,
line3(20) TYPE c,
line4(23) TYPE c,
line5(10) TYPE c,
line6(45) type c,
date(2) TYPE c,
month(2) TYPE c,
year(4) TYPE c.
************************************************************
*START OF SELECTION
************************************************************
SELECT bukrs
FROM t001
INTO TABLE itab_ccode
WHERE land1 EQ 'GB'.
SORT itab_ccode.
DELETE ADJACENT DUPLICATES FROM itab_ccode.
SELECT pernr sachp sname
FROM pa0001
INTO TABLE itab_emp
FOR ALL ENTRIES IN itab_ccode
WHERE bukrs EQ itab_ccode-bukrs AND begda LE sy-datum AND
endda GE sy-datum and persg eq '1'.
SELECT nachn vorna pernr gbdat
FROM pa0002
INTO TABLE itab_bdate
FOR ALL ENTRIES IN itab_emp
WHERE pernr EQ itab_emp-pernr.
************************************************************
*TO CHECK EMPLOYEES WHOSE AGE IS NEAR 75 YEARS.
************************************************************
LOOP AT itab_bdate INTO wa_bdate.
new_date = wa_bdate-gbdat.
************************************************************
*TO CALCULATE THE AGE TILL DATE
************************************************************
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
date1 = sy-datum
date2 = new_date
output_format = '05'
IMPORTING
years = years
months = months
days = days
.
IF sy-subrc <> 0.
ENDIF.
IF years EQ 64 AND months EQ 4.
IF days GE 23 AND days LE 31.
************************************************************
*FETCH THE DATA IF THE AGE IS NEARING 75 YEARS
************************************************************
SELECT SINGLE sachp FROM pa0001 INTO sup_code WHERE pernr EQ
wa_bdate-pernr AND begda LE sy-datum AND endda GE sy-datum.
SELECT SINGLE usrid FROM t526 INTO itab_usrid WHERE sachx EQ
sup_code.
SELECT SINGLE pernr FROM pa0105 INTO sup_pernr WHERE usrid EQ
itab_usrid AND subty EQ '0001'.
clear sup_email[].
SELECT usrid_long FROM pa0105 INTO TABLE sup_email WHERE pernr EQ
sup_pernr AND subty EQ '0010'.
************************************************************
*EMAIL ADDRESS OF THE SUPERVISOR TO BE NOTIFIED
************************************************************
CLEAR gi_obj_cnt.
CLEAR gi_recievers.
CLEAR gwa_document_data.
Loop at sup_email into wa_email.
write sy-uline+0(5).
write sy-uline+10(5).
write sy-uline+20(5).
write sy-uline+30(5).
write sy-uline+40(5).
write sy-uline+50(5).
write sy-uline+60(5).
write sy-uline+70(5).
smtp_addr = wa_email-usrid_long.
gi_recievers-receiver = smtp_addr.
gi_recievers-rec_type = 'U'.
gi_recievers-com_type = 'INT'.
APPEND gi_recievers.
Endloop.
smtp_addr = '[email protected]'.
gi_recievers-receiver = smtp_addr.
gi_recievers-rec_type = 'U'.
gi_recievers-com_type = 'INT'.
APPEND gi_recievers.
gwa_document_data-obj_name = gc_name.
gwa_document_data-obj_descr = 'RETIRE'.
gwa_document_data-sensitivty = gc_senst.
gwa_document_data-obj_langu = sy-langu.
************************************************************
*CONTENT OF THE EMAIL TO BE SENT
************************************************************
line1 = 'Please note that '.
line2 = wa_bdate-vorna.
line3 = wa_bdate-nachn.
line4 = ' will be 65 years on '.
line50(4) = wa_bdate-gbdat4(4).
date = line5+2(2).
month = line5+0(2).
year = wa_bdate-gbdat+0(4) + 65.
CONCATENATE date month year INTO line5 SEPARATED BY '.'.
line6 = '.Please complete the Retirement Procedure.'.
CONCATENATE line1 line2 line3 line4 line5 line6 INTO gwa_obj_cnt
SEPARATED BY space.
APPEND gwa_obj_cnt TO gi_obj_cnt.
CLEAR gwa_obj_cnt.
DESCRIBE TABLE gi_obj_cnt LINES entries.
READ TABLE gi_obj_cnt INDEX entries.
gwa_document_data-doc_size = ( entries - 1 ) * 255 + STRLEN( gi_obj_cnt
).
************************************************************
*FUNCTION MODULE TO SEND THE EMAIL TO THE CONCERNED PERSONS
************************************************************
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = gwa_document_data
document_type = 'RAW'
commit_work = 'X'
TABLES
object_content = gi_obj_cnt
receivers = gi_recievers
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
.
************************************************************
*MESSAGE TO BE DISPLAYED AFTER THE EXECUTION
************************************************************
endif.
CASE sy-subrc.
WHEN 0.
LOOP AT gi_recievers.
IF gi_recievers-receiver = space.
name = gi_recievers-rec_id.
ELSE.
name = gi_recievers-receiver.
ENDIF.
IF gi_recievers-retrn_code = 0.
WRITE: / name, ': succesfully sent'.
ELSE.
WRITE: / name, ': error occured'.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / 'Too many receivers specified !'.
WHEN 2.
WRITE: / 'No receiver got the document !'.
WHEN 4.
WRITE: / 'Missing send authority !'.
WHEN OTHERS.
WRITE: / 'Unexpected error occurred !'.
ENDCASE.
ENDIF.
ENDIF.
ENDLOOP.
In case you have any further clarifications,do let me know.
Regards,
Puneet Jhari.
2007 Oct 11 5:54 AM
Hi
The text is comming in pdf file , i don't want in pdf file.
please send me the code as text in body of email.
2007 Oct 11 7:19 AM
Hi,
try this sample:
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: SENT_TO_ALL like SONV-FLAG.
DATA : BEGIN OF itab OCCURS 0,
pernr LIKE p0001-pernr,
name LIKE p0002-vorna,
END OF itab.
Creation of the document to be sent
doc_chng-obj_name = 'SENDFILE'.
Mail Subject
concatenate 'title1'
'title2'
into doc_chng-obj_descr.
Mail Contents
objtxt = 'Dear user,'.
APPEND objtxt.
objtxt = ' '.
APPEND objtxt.
objtxt = 'Text1'.
APPEND objtxt.
objtxt = 'text2'.
APPEND objtxt.
objtxt = ' '.
APPEND objtxt.
objtxt = 'text3 '.
APPEND objtxt.
DESCRIBE TABLE objtxt LINES tab_lines.
*
Creation of the entry for the document
CLEAR objpack-transf_bin. "Will get content from content_text
objpack-head_start = 1. "Reads given row number in object header
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
APPEND objpack.
DESCRIBE TABLE itab LINES tab_lines.
DESCRIBE TABLE objbin LINES tab_lines.
target recipent
CLEAR reclist.
reclist-receiver = '[email protected]'.
*reclist-express = 'X'.
reclist-rec_type = 'U'.
APPEND reclist.
copy recipents
*CLEAR reclist.
*reclist-receiver = '[email protected]'.
**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
put_in_outbox = 'X'
commit_work = '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.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
if sy-subrc = 0.
write:'Apparently successful'.
else.
write:'Error while sending mail!'.
ENDIF.
Regards
2007 Oct 11 8:07 AM
hi
Now i need to implement same thing useing classes and methods.
i have used
TRY.
-------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
-------- create and set document with attachment ---------------
create document from internal table with text
APPEND 'Hello world!' TO text.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_hex = gti_contents_hex
i_length = '12'
i_subject = 'test created by BCS_EXAMPLE' ).
add attachment to document
BCS expects document content here e.g. from document upload
binary_content = ...
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = 'RAW'
i_attachment_subject = 'My attachment'
<b> i_att_content_hex = gti_contents_hex.</b>
add document to send request
CALL METHOD send_request->set_document( document ).
--------- set sender -------------------------------------------
note: this is necessary only if you want to set the sender
different from actual user (SY-UNAME). Otherwise sender is
set automatically with actual user.
sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
--------- add recipient (e-mail address) -----------------------
create recipient - please replace e-mail address !!!
recipient = cl_cam_address_bcs=>create_internet_address(
'[email protected]' ).
add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
CALL METHOD send_request->set_send_immediately( 'X' ).
---------- send document ---------------------------------------
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
IF sent_to_all = 'X'.
WRITE text-003.
ENDIF.
COMMIT WORK.
-----------------------------------------------------------
* exception handling
-----------------------------------------------------------
* replace this very rudimentary exception handling
* with your own one !!!
-----------------------------------------------------------
CATCH cx_bcs INTO bcs_exception.
WRITE: 'Fehler aufgetreten.'(001).
WRITE: 'Fehlertyp:'(002), bcs_exception->error_type.
EXIT.
ENDTRY.
Eery thing is working fine ,but the data in pdf file is not comming .
i think problem is convertion of tline to solix_tab.
(
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
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.
<b> it_pdf_output needs to be converted in to gti_contents_hex</b>.
Help me ,its very urgent
Message was edited by:
sudheer kumar
2009 Oct 19 11:01 AM
Hi,
I am also fetching the same problem.Kindly post the solution.
regards,
padmaja.
2009 Oct 19 11:01 AM
Hi,
I am also fetching the same problem.Kindly post the solution.
regards,
padmaja.
2009 Oct 19 11:02 AM
Hi,
I am also fetching the same problem.Kindly post the solution.
regards,
padmaja.
2009 Oct 20 4:59 AM
hi,
If anybody face the same problem like mail body as attachment then go for the bellow solution.
Check your settings in TCODE SCOT
Double click on SMTP note . For "Internet" click on set, under "Output format for SAP documents" RAW Text musts be set as "TXT"
Regards
padmaja.