2008 May 14 6:02 AM
Hello ABAPers,
I am have my own customized screen and Txcode for tht screen. Here in this screen i will be createing a material details i.e fields tht are not there in standard SAP.
Here after createing the material i want to trigger a mail to the concern person is it possible if yes can anybody share me the procedure.
Thks
Hello ABAPers,
I am have my own customized screen and Txcode for tht screen. Here in this screen i will be createing a material details i.e fields tht are not there in standard SAP.
Here after createing the material i want to trigger a mail to the concern person is it possible if yes can anybody share me the procedure.
Thks
2008 May 14 6:09 AM
Hi,
Please check the below report to send a email
report ztest_email.
parameters: psubject(40) type c default 'Hello',
p_email(40) type c default mail id .
data: it_packing_list like sopcklsti1 occurs 0 with header line,
it_receivers like somlreci1 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.
write:/ 'done'.
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.
Populate the subject/generic message attributes
gd_doc_data-obj_descr = psubject.
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-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'
commit_work = 'X'
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
Reward points if useful.
2008 May 14 8:07 AM
Hello thks for ur support but i am getting error one error when i am using your code..like field "MAIL" is unknown. It is neither defined....
Thks
2008 May 14 6:10 AM
Hi
hope it will help you.
Reward pts if help
&----
*& Report ZEMAIL_SIVA
*&
&----
*&
*&
&----
REPORT zemail_siva.
DATA : gd_doc_data LIKE sodocchgi1,
l_i_mail TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,
it_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE.
DATA: w_pack TYPE sopcklsti1,
i_pack TYPE TABLE OF sopcklsti1.
PARAMETERS : p_email(100) TYPE c.
gd_doc_data-obj_descr = 'TEST EMAIL FROM ABAP SE TEAM'.
l_i_mail-line = 'Testing the Mail from ABAP on 31st March 2008'.
APPEND l_i_mail.
it_receivers-receiver = p_email.
it_receivers-rec_type = 'A'.
it_receivers-com_type = 'INT'.
*it_receivers-notif_del = 'X'.
*it_receivers-notif_ndel = 'X'.
APPEND it_receivers.
CLEAR w_pack.
w_pack-head_start = 1.
w_pack-head_num = 0.
w_pack-body_start = 1.
DESCRIBE TABLE l_i_mail LINES w_pack-body_num.
w_pack-doc_type = 'RAW'.
w_pack-doc_size = w_pack-body_num * 255.
APPEND w_pack TO i_pack.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
packing_list = i_pack
OBJECT_HEADER =
CONTENTS_BIN =
contents_txt = l_i_mail
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
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 Sent to specified address'.
ENDIF.
2008 May 14 10:30 AM
Hello i have used ur code it is showing sntactically correct here one thing i am unable to understand like where we are giving the meesage and where we are giving our email id and where we are type the email id to whom we are sending.
Please revert me
2008 May 14 8:25 AM
Hi ,
Try this code.
***************************************************************
zdp_solisti1 is a structure having fields naming LINE of type LCHR and its length being 2500.
*******Email declarations
data : gv_delimit TYPE c,
lv_lncnt1(5) TYPE c,
tempread(10) TYPE c VALUE 0,
objpack TYPE sopcklsti1 OCCURS 0 WITH HEADER LINE,
objhead TYPE zdp_solisti1 OCCURS 1 WITH HEADER LINE,
objbin TYPE soli OCCURS 0 WITH HEADER LINE,
objtxt TYPE zdp_solisti1 OCCURS 0 WITH HEADER LINE,
reclist TYPE somlreci1 OCCURS 0 WITH HEADER LINE,
doc_chng LIKE sodocchgi1,
tab_lines LIKE sy-tabix.
CLEAR GV_DELIMIT.
GV_DELIMIT = CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
TEMPREAD = LV_LNCNT1.
REFRESH OBJTXT.
CONCATENATE 'The no. of error records are : ' TEMPREAD
INTO OBJTXT-LINE.
APPEND OBJTXT.
CLEAR OBJPACK. REFRESH OBJPACK.
CONCATENATE C_CODE
C_CMMT
C_COMMENT1
INTO OBJTXT-LINE SEPARATED BY GV_DELIMIT.
APPEND OBJTXT.
LOOP AT IT_DATA INTO WA_DATA.
CONCATENATE WA_DATA-ZCODE
WA_DATA-ZCOMMENT
WA_DATA-ZREASON
INTO OBJTXT-LINE SEPARATED BY GV_DELIMIT.
APPEND OBJTXT.
ENDLOOP.
CLEAR GV_DELIMIT.
CLEAR OBJPACK. REFRESH OBJPACK.
CLEAR DOC_CHNG.
TAB_LINES = 0.
OBJHEAD = REJFILE. APPEND OBJHEAD.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-OBJ_NAME = REJFILE.
MOVE TEXT-006 TO
DOC_CHNG-OBJ_DESCR.
DOC_CHNG-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 = 1. " 3.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
FOR ASCII TO BINARY OBJECT FUNCTION
TOTLINEXFER = 0.
TOTXFER = 0.
BINMAXLEN = 255.
REFRESH OBJBIN.
LV_CR = CL_ABAP_CHAR_UTILITIES=>CR_LF.
TGTMAXLEN = BINMAXLEN.
TGTLEN = 0.
LOOP AT OBJTXT FROM 2.
IF NOT OBJTXT-LINE CP 'The no. of records are '." AND
CONCATENATE OBJTXT-LINE LV_CR INTO BUFFER.
SRCOBJLEN = STRLEN( BUFFER ).
SRCOBJPTR = 0.
WHILE SRCOBJLEN > 0 .
XFERLEN = TGTMAXLEN - TGTLEN.
IF XFERLEN > SRCOBJLEN.
XFERLEN = SRCOBJLEN.
MOVE BUFFERSRCOBJPTR TO OBJBIN-LINETGTLEN.
TGTLEN = TGTLEN + SRCOBJLEN.
SRCOBJLEN = 0.
CLEAR BUFFER.
ELSE.
MOVE BUFFER+SRCOBJPTR(XFERLEN) TO
OBJBIN-LINE+TGTLEN(XFERLEN).
APPEND OBJBIN.
CLEAR OBJBIN-LINE.
TGTLEN = 0.
SRCOBJLEN = SRCOBJLEN - XFERLEN.
SRCOBJPTR = SRCOBJPTR + XFERLEN.
TOTLINEXFER = TOTLINEXFER + 1.
ENDIF.
TOTXFER = TOTXFER + XFERLEN.
ENDWHILE.
ENDIF.
ENDLOOP.
IF TGTLEN > 0.
APPEND OBJBIN.
TOTLINEXFER = TOTLINEXFER + 1.
ENDIF.
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TOTLINEXFER.
OBJPACK-DOC_TYPE = 'XLS'.
OBJPACK-OBJ_NAME = REJFILE.
OBJPACK-OBJ_DESCR = 'Rejected Entries File'.
OBJPACK-DOC_SIZE = TOTXFER.
APPEND OBJPACK.
REFRESH RECLIST.
MAIL1 = 'xxxxxxxx' " Email Address
RECLIST-RECEIVER = MAIL1.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
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.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
***************************************************************
Hope this is helpful to you. If you need further information, revert back.
Reward all the helpful answers.
Regards
Nagaraj T
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |