2007 Sep 04 10:16 AM
Hi all
I have some doubts. i searched the forum threads. But still not clear.
How do i send mail to external servers (like gmail, yahoo). I got some code for sending mail. but they are for internal sap users. I would like to send mail to external system.
How do i see the mails received by my internal sap user id. ? Through which transaction.
2007 Sep 04 10:30 AM
Hi,
If you are sending email from sap business workplace, you simply enter e-mail address into recipient field and type of Receip. Type U - internet address.
If you would like to have program which is sending emails to the specific e-mail addresses you can check code below. This program is sending stock value in xls format to external email addresses.
I hope, i helped you,
BR
Saso
CODE:
************************************************************************************
&----
*& REPORT ZSENDMAIL_SIMOBIL_STOCK *
*& *
&----
*& Example of sending external email via SAPCONNECT *
*& *
&----
REPORT ZSENDMAIL_SIMOBIL_STOCK .
TABLES: mard, makt, mara, SOMLRECI1.
SELECT-OPTIONS: matnr FOR mard-matnr.
SELECT-OPTIONS: werks FOR mard-werks.
SELECT-OPTIONS: labst FOR mard-labst.
SELECT-OPTIONS: matkl FOR MARA-matkl.
SELECT-OPTIONS: lgort FOR mard-lgort.
SELECT-OPTIONS RECEIVER FOR SOMLRECI1-RECEIVER NO INTERVALS.
*
*PARAMETERS: p_email TYPE somlreci1-receiver
DEFAULT [email protected]'.
PARAMETERS: p_subj TYPE EPSF-EPSFILNAM.
PARAMETERS: p_filen TYPE EPSF-EPSFILNAM.
TYPES: BEGIN OF t_mard,
maktx TYPE makt-maktx,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
labst TYPE mard-labst,
matkl TYPE mara-matkl,
END OF t_mard.
DATA: it_mard TYPE STANDARD TABLE OF t_mard WITH HEADER LINE,
wa_mard TYPE t_mard.
TYPES: BEGIN OF t_charekpo,
maktx(40) TYPE c,
matnr(18) TYPE c,
werks(4) TYPE c,
lgort(4) TYPE c,
labst(18) TYPE c,
matkl(3) TYPE c,
kolicina(15) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
INCLUDE RFTS7001.
INITIALIZATION.
*No intervall for value help
CLEAR OPT_LIST.
MOVE 'JUST_EQ' TO OPT_LIST-NAME.
MOVE 'X' TO OPT_LIST-OPTIONS-EQ.
APPEND OPT_LIST TO RESTRICT-OPT_LIST_TAB.
CLEAR ASS.
MOVE: 'S' TO ASS-KIND,
'RECEIVER' TO ASS-NAME,
'I' TO ASS-SG_MAIN,
'JUST_EQ' TO ASS-OP_MAIN.
APPEND ASS TO RESTRICT-ASS_TAB.
CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
RESTRICTION = RESTRICT.
*$001 ins end
************************************************************************
*START_OF_SELECTION
START-OF-SELECTION.
Retrieve sample data from table ekpo
PERFORM data_retrieval.
Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
Populate message body text
perform populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
using RECEIVER
p_subj
'Naročilnica Simobil'
'XLS'
p_filen
'filename'
' '
' '
' '
changing gd_error
gd_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form MARD table and populate itab it_mard
----
FORM data_retrieval.
SELECT * FROM mard WHERE ( matnr IN matnr ) and
( labst IN labst ) AND
( werks IN werks ) and
( lgort in lgort ).
SELECT * FROM MARA WHERE ( matnr = Mard-matnr ) AND
( matkl in matkl ).
SELECT SINGLE * FROM MAKT WHERE ( matnr = mard-matnr ) AND
( SPRAS = 'E' ).
IF sy-subrc = 0.
CLEAR it_mard.
MOVE mard-matnr TO it_mard-matnr.
MOVE mard-lgort TO it_mard-lgort.
MOVE mard-werks TO it_mard-werks.
MOVE mard-labst TO it_mard-labst.
MOVE mara-matkl TO it_mard-matkl.
MOVE makt-maktx TO it_mard-maktx.
APPEND it_mard.
ENDIF.
ENDSELECT.
ENDSELECT.
ENDFORM. " DATA_RETRIEVAL
*FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
*ENDFORM.
&----
*& Form BUILD_XLS_DATA_TABLE
&----
Build data table for .xls document
----
FORM build_xls_data_table.
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>CR_LF.
CONCATENATE 'Opis Materiala' 'Material' 'Količina'
'Skladiče' 'Zaloga' 'obrat' 'Mat. grupa'
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT it_mard INTO wa_charekpo.
CONCATENATE wa_charekpo-MAKTX wa_charekpo-matnr
wa_charekpo-lgort wa_charekpo-labst
wa_charekpo-WERKS wa_charekpo-MAKTX wa_charekpo-MATKL
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
&----
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
&----
Send email
----
FORM send_file_as_email_attachment tables pit_message
pit_attach
using p_email
using receiver
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
ld_email = receiver.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
( w_cnt + 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
LOOP AT RECEIVER.
t_receivers-receiver = ld_email.
t_receivers-receiver = RECEIVER-LOW.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
ENDLOOP.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
&----
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
&----
Instructs mail send program for SAPCONNECT to send email.
----
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
&----
*& Form POPULATE_EMAIL_MESSAGE_BODY
&----
Populate message body text
----
form populate_email_message_body.
REFRESH it_message.
it_message = SAMPLE TEXT BODY.
Sales Support'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY
2007 Sep 04 10:21 AM
Hi aarthi ,
check with this,
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
.
Thanks
2007 Sep 04 10:28 AM
Thanks for ur response Naveen. But is this for sending mails to internal sap user ids or external userids.
2007 Sep 04 10:27 AM
Hi Aarathi,
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 Sep 04 10:30 AM
Hi,
If you are sending email from sap business workplace, you simply enter e-mail address into recipient field and type of Receip. Type U - internet address.
If you would like to have program which is sending emails to the specific e-mail addresses you can check code below. This program is sending stock value in xls format to external email addresses.
I hope, i helped you,
BR
Saso
CODE:
************************************************************************************
&----
*& REPORT ZSENDMAIL_SIMOBIL_STOCK *
*& *
&----
*& Example of sending external email via SAPCONNECT *
*& *
&----
REPORT ZSENDMAIL_SIMOBIL_STOCK .
TABLES: mard, makt, mara, SOMLRECI1.
SELECT-OPTIONS: matnr FOR mard-matnr.
SELECT-OPTIONS: werks FOR mard-werks.
SELECT-OPTIONS: labst FOR mard-labst.
SELECT-OPTIONS: matkl FOR MARA-matkl.
SELECT-OPTIONS: lgort FOR mard-lgort.
SELECT-OPTIONS RECEIVER FOR SOMLRECI1-RECEIVER NO INTERVALS.
*
*PARAMETERS: p_email TYPE somlreci1-receiver
DEFAULT [email protected]'.
PARAMETERS: p_subj TYPE EPSF-EPSFILNAM.
PARAMETERS: p_filen TYPE EPSF-EPSFILNAM.
TYPES: BEGIN OF t_mard,
maktx TYPE makt-maktx,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
labst TYPE mard-labst,
matkl TYPE mara-matkl,
END OF t_mard.
DATA: it_mard TYPE STANDARD TABLE OF t_mard WITH HEADER LINE,
wa_mard TYPE t_mard.
TYPES: BEGIN OF t_charekpo,
maktx(40) TYPE c,
matnr(18) TYPE c,
werks(4) TYPE c,
lgort(4) TYPE c,
labst(18) TYPE c,
matkl(3) TYPE c,
kolicina(15) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
INCLUDE RFTS7001.
INITIALIZATION.
*No intervall for value help
CLEAR OPT_LIST.
MOVE 'JUST_EQ' TO OPT_LIST-NAME.
MOVE 'X' TO OPT_LIST-OPTIONS-EQ.
APPEND OPT_LIST TO RESTRICT-OPT_LIST_TAB.
CLEAR ASS.
MOVE: 'S' TO ASS-KIND,
'RECEIVER' TO ASS-NAME,
'I' TO ASS-SG_MAIN,
'JUST_EQ' TO ASS-OP_MAIN.
APPEND ASS TO RESTRICT-ASS_TAB.
CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
RESTRICTION = RESTRICT.
*$001 ins end
************************************************************************
*START_OF_SELECTION
START-OF-SELECTION.
Retrieve sample data from table ekpo
PERFORM data_retrieval.
Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
Populate message body text
perform populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
using RECEIVER
p_subj
'Naročilnica Simobil'
'XLS'
p_filen
'filename'
' '
' '
' '
changing gd_error
gd_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form MARD table and populate itab it_mard
----
FORM data_retrieval.
SELECT * FROM mard WHERE ( matnr IN matnr ) and
( labst IN labst ) AND
( werks IN werks ) and
( lgort in lgort ).
SELECT * FROM MARA WHERE ( matnr = Mard-matnr ) AND
( matkl in matkl ).
SELECT SINGLE * FROM MAKT WHERE ( matnr = mard-matnr ) AND
( SPRAS = 'E' ).
IF sy-subrc = 0.
CLEAR it_mard.
MOVE mard-matnr TO it_mard-matnr.
MOVE mard-lgort TO it_mard-lgort.
MOVE mard-werks TO it_mard-werks.
MOVE mard-labst TO it_mard-labst.
MOVE mara-matkl TO it_mard-matkl.
MOVE makt-maktx TO it_mard-maktx.
APPEND it_mard.
ENDIF.
ENDSELECT.
ENDSELECT.
ENDFORM. " DATA_RETRIEVAL
*FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
*ENDFORM.
&----
*& Form BUILD_XLS_DATA_TABLE
&----
Build data table for .xls document
----
FORM build_xls_data_table.
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>CR_LF.
CONCATENATE 'Opis Materiala' 'Material' 'Količina'
'Skladiče' 'Zaloga' 'obrat' 'Mat. grupa'
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT it_mard INTO wa_charekpo.
CONCATENATE wa_charekpo-MAKTX wa_charekpo-matnr
wa_charekpo-lgort wa_charekpo-labst
wa_charekpo-WERKS wa_charekpo-MAKTX wa_charekpo-MATKL
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
&----
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
&----
Send email
----
FORM send_file_as_email_attachment tables pit_message
pit_attach
using p_email
using receiver
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
ld_email = receiver.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
( w_cnt + 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
LOOP AT RECEIVER.
t_receivers-receiver = ld_email.
t_receivers-receiver = RECEIVER-LOW.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
ENDLOOP.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
&----
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
&----
Instructs mail send program for SAPCONNECT to send email.
----
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
&----
*& Form POPULATE_EMAIL_MESSAGE_BODY
&----
Populate message body text
----
form populate_email_message_body.
REFRESH it_message.
it_message = SAMPLE TEXT BODY.
Sales Support'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY
2007 Sep 04 10:31 AM
Hi aarthi,
search via SE38 for BCS_EXAMPLE_*. There are good examples.
Regards, Dieter
2007 Sep 04 10:32 AM
Hello
you can send mail to any external id using FM "SO_NEW_DOCUMENT_ATT_SEND_API1"
ask your basis team to check out SOST settings .
after using the FM in se 38 run report "RSCONN01" to clear the queue.
to see mails recived in your internal id TCODE : SBWP
or press ctrl F12 from your sap easy access menu.
reward points if helpful
2007 Sep 04 10:33 AM
Hi aarthi,
The sending of documents via external communications services like fax, paging (radio call services, SMS), Internet mail, X.400, and so on is carried out with the components SAPoffice and SAPconnect. For an 'actual' sending via the corresponding communications services you still need R/3-external additional components ("SAPconnect node") which are delivered either by SAP (for example SAP Internet Mail Gateway or SAP Exchange Connector) or by external manufacturers (for example, fax servers).
. . . . . . . . . . . . . . . . .
. .
. R/3 .
. .
. ----
. ! Application ! .
. ----
. | .
. | <------- Business Communication Interface
. v .
. ----
. ! SAPoffice ! .
. ----
. | .
. | <------- SAPoffice/SAPconnect send queue
. v .
. ----
. ! SAPconnect ! .
. ----
. | .
. . . . . . . .|. . . . . . . . .
<------- RFC Interface BC-CON v ---- ! Communication system ! ! ="SAPconnect node" ! ---- |
v
Data transfer network
You can check the correct sending of documents from applications with two different tests:
1. 'Actual' test
Documents are actually transferred via the communications services. Precondition is the installation of an external communication system and its connection to the data transfer networks (telephone line, Intra/Internet...).
This way, the documents can be transferred to any participant of the corresponding communications service (fax machines, mailboxes...).
2. 'Loop-back' test
The documents are returned here to the own R/3 System which functions like a SAPconnect node and are stored in the SAPoffice inbox of an R/3 user. The operation of an external communications system is nonrequired in this case.
In general, all points relevant for application can be checked during this test: Contents and structure of the documents, entry of sender and receiver addresses, format of the documents for transmission, handling of status confirmations and so on
For both tests, proceed as follows:
1. 'Actual' test
Contact the R/3 System administration to set up the R/3-external infrastructure necessary for the required communication service and to carry out the R/3 internal configuration.
2. 'Loop-back' test
a) Address management
All R/3 users who want to send documents via a communication service need an address of the respective communication service type which is used as a sender specification.
All users also need an address of this type to receive documents in the R/3 System via a communications service and under which they are attainable as receivers.
If documents are to be sent to the own R/3 user during the loop-back test, a single address of the corresponding communication service suffices for this user. This is then used both as sender and as receiver specification.
Create addresses
The address maintenance of R/3 users is carried out either via the R/3 User Maintenance (Transaction SU01) or the Private office settings (Transaction SO12):
Address --> Other communication...
Selection of the required communication service.
Enter address.
Copy or save.
b) Configuration of SAPconnect (Transaction SCOT)
Set communication method
4.0 + 4.5: Goto --> Customizing --> Communication methods
as of 4.6: Settings --> Communication methods
Set the method of the required communication service to the value 'SAPCONNECT' and save the setting.
Create node
View --> Nodes, node --> Create
Nodes = for example system name/client "ALR003"
For example, Description = "ALR client R/3 System 003"
RFC destination = 'NONE'
Address type = Selection of the required communication service.
Address area = for example '*'
Format = 'PDF' for fax, 'RAW' for paging and Internet mail
Device type = 'POST2' for fax, 'ASCIPRI' for paging and Internet mail
Restrict send time = do not flag
Country = 'DE' (only for fax)
Flag Node-specific fax number changes... = (only for fax)
Enter two entries in the table: (only for fax)
Begin. no Substitute Comment
-
00 + foreign country
0 +49 home country
Set further address type = 'no'
Maximum waiting time... = enter nothing
Node can resolve path references = do not flag
Node is to be monitored by the alert monitor = do not flag
Node in use = mark
Schedule send process
View --> Jobs, job --> Dispatch
Job name = for example 'SAPconnect'
--> place cursor on variant SAP&CONNECTALL Schedule job (F6)
Schedule periodically, for example 5 minutes.
After sending a document from an R/3 application this is displayed in the outbox of the sender (if requested SAPoffice interface). After the next SAPconnect transmission process (according to the period chosen when scheduling the job) the document is displayed in the inbox of the receiver.
Go thru below links:-
http://www.tamboly.com/SAPEmailConfiguration.html
http://help.sap.com/saphelp_nw2004s/helpdata/en/2b/d925bf4b8a11d1894c0000e8323c4f/frameset.htm
Regards,
Kumar.
2007 Sep 04 10:49 AM
Hi all
Thanks for all for your timely help.I have awarded points. But cant award 10 for more than one, and 6 more than 2. Anyway all your responses are very useful .