09-15-2009 3:04 PM
Hi,
I have a requirement to update a ztable. If the update statement fails then I need to populate all the messages with the fields msgid,msgty,msgno and msgv1 into an internal table and use that internal table in the function module that is used to send the email with the error messages populated in the internal table.
The internal table populated with messages is tab_msg. I have used the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1' to send the mail.But after executing the function module it is giving exception as document _not _sent.
Please give me a sample code how to pass the internal table containing the message information into a parameter contents_txt in the function module
'SO_NEW_DOCUMENT_ATT_SEND_API1' .
09-15-2009 3:09 PM
Hi Dear,
Use this.
TYPE-POOLS: slis.
TYPES: BEGIN OF str_mara,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
laeda TYPE mara-laeda,
aenam TYPE mara-aenam,
vpsta TYPE mara-vpsta,
END OF str_mara.
DATA: i_mat TYPE TABLE OF str_mara,
wa_mat LIKE LINE OF i_mat.
DATA:params LIKE pri_params.
DATA: days(1) TYPE n VALUE 2,
valid TYPE c.
DATA: obj TYPE REF TO cl_salv_table.
SELECT matnr
ersda
ernam
laeda
aenam
vpsta
UP TO 10 ROWS FROM mara INTO CORRESPONDING FIELDS OF TABLE i_mat.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = obj
CHANGING
t_table = i_mat.
CATCH cx_salv_msg .
ENDTRY.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
* destination = 'QAS'
list_name = 'ZTEST_VERTEX'
list_text = 'TEST'
no_dialog = 'X'
immediately = ' '
expiration = days
IMPORTING
* OUT_ARCHIVE_PARAMETERS =
out_parameters = params
valid = valid
* VALID_FOR_SPOOL_CREATION =
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
TRY .
NEW-PAGE PRINT ON PARAMETERS params NO DIALOG.
CATCH cx_sy_nested_print_on .
ENDTRY.
CALL METHOD obj->display.
NEW-PAGE PRINT OFF.
PERFORM send_mail.
*&---------------------------------------------------------------------*
*& Form SEND_MAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM send_mail .
DATA: lv_subject LIKE sodocchgi1-obj_descr,
i_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
lv_attachment_desc TYPE so_obj_nam.
DATA: wa_top TYPE slis_listheader.
DATA: i_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
i_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
wa_cnt TYPE i,
wa_sent_all(1) TYPE c,
wa_doc_data LIKE sodocchgi1.
DATA: BEGIN OF i_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF i_pdf_output.
DATA: lv_recsize TYPE i.
DATA: lv_spool_nr1 LIKE tsp01-rqident,
lv_destination LIKE rlgrap-filename,
lv_bytecount LIKE tst01-dsize,
lv_buffer TYPE string.
TYPES : BEGIN OF str_tsp01,
rqident TYPE tsp01-rqident,
rqowner TYPE tsp01-rqowner,
rqcretime TYPE tsp01-rqcretime,
END OF str_tsp01.
DATA lv_spool_nr TYPE tsp01-rqident.
DATA : i_tsp01 TYPE STANDARD TABLE OF str_tsp01,
wa_tsp01 LIKE LINE OF i_tsp01.
SELECT rqident
rqowner
rqcretime
FROM tsp01
INTO TABLE i_tsp01
WHERE rqowner = sy-uname.
SORT i_tsp01 BY rqcretime DESCENDING.
READ TABLE i_tsp01 INTO wa_tsp01 INDEX 1.
IF sy-subrc = 0 .
lv_spool_nr = wa_tsp01-rqident.
ENDIF.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = lv_spool_nr
no_dialog = ''
dst_device = 'LOCL'
* PDF_DESTINATION =
IMPORTING
pdf_bytecount = lv_bytecount
* PDF_SPOOLID =
* LIST_PAGECOUNT =
* BTC_JOBNAME =
* BTC_JOBCOUNT =
TABLES
pdf = i_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
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Transfer the 132-long strings to 255-long strings
LOOP AT i_pdf_output.
TRANSLATE i_pdf_output USING ' ~'.
CONCATENATE lv_buffer i_pdf_output INTO lv_buffer.
ENDLOOP.
TRANSLATE lv_buffer USING '~ '.
DO.
i_mess_att = lv_buffer.
APPEND i_mess_att.
SHIFT lv_buffer LEFT BY 255 PLACES.
IF lv_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
DESCRIBE TABLE i_mess_att LINES lv_recsize.
CHECK lv_recsize > 0.
REFRESH i_mess_bod.
*-- Default Subject Matter
lv_subject = 'Price List'.
lv_attachment_desc = 'Price List'.
i_mess_bod = 'Please Find the Attatchment of the Price list'.
APPEND i_mess_bod .
i_mess_bod = 'This is System/Auto Generated mail please DONOT REPLY'.
APPEND i_mess_bod .
i_mess_bod = 'Regards.'.
APPEND i_mess_bod .
i_mess_bod = 'System Administrator.'.
APPEND i_mess_bod .
*-- Fill Dcument data
*wa_doc_data-obj_langu = sy-langu.
*wa_doc_data-obj_name = 'Price List'.
*wa_doc_data-obj_descr = 'Customer Price List'.
*wa_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
CLEAR wa_doc_data.
READ TABLE i_mess_att INDEX wa_cnt.
wa_doc_data-doc_size = ( wa_cnt - 1 ) * 255 + STRLEN( i_mess_att ).
wa_doc_data-obj_langu = sy-langu.
wa_doc_data-obj_name = 'Price List'.
wa_doc_data-obj_descr = 'Customer Price List'.
wa_doc_data-sensitivty = 'F'.
REFRESH i_attachment.
i_attachment[] = i_mess_att[].
*-- Describe the Body of the message.
CLEAR i_packing_list.
REFRESH i_packing_list.
i_packing_list-transf_bin = space.
i_packing_list-head_start = 1.
i_packing_list-head_num = 0.
i_packing_list-body_start = 1.
DESCRIBE TABLE i_mess_bod LINES i_packing_list-body_num.
i_packing_list-doc_type = 'RAW'.
APPEND i_packing_list.
* Create attachment notification
i_packing_list-transf_bin = 'X'.
i_packing_list-head_start = 1.
i_packing_list-head_num = 1.
i_packing_list-body_start = 1.
DESCRIBE TABLE i_attachment LINES i_packing_list-body_num.
i_packing_list-doc_type = 'PDF'.
i_packing_list-obj_descr = lv_attachment_desc.
i_packing_list-obj_name = lv_attachment_desc .
i_packing_list-doc_size = i_packing_list-body_num * 255.
APPEND i_packing_list.
*-- Add recipent email address.
* LOOP AT s_email .
i_receivers-receiver = 'mlunkavertex.co.in'.
i_receivers-rec_type = 'U'.
i_receivers-com_type = 'INT'.
i_receivers-notif_del = ' '.
i_receivers-notif_ndel = ' '.
APPEND i_receivers.
* ENDLOOP.
*Send Email.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = wa_doc_data
put_in_outbox = ' '
* SENDER_ADDRESS = SY-UNAME
* SENDER_ADDRESS_TYPE = 'B'
commit_work = 'X'
IMPORTING
sent_to_all = wa_sent_all
* NEW_OBJECT_ID =
* SENDER_ID =
TABLES
packing_list = i_packing_list
* OBJECT_HEADER =
contents_bin = i_attachment
contents_txt = i_mess_bod
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
receivers = i_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.
ENDIF.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = ''
AND RETURN.
IF sy-subrc = 0.
MESSAGE 'Message Sent' TYPE 'S'.
ENDIF.
ENDFORM. " SEND_MAIL
Regards,
Vijay
09-15-2009 3:09 PM
Hi,
Check this simple sample code,
data : t_docu_data like sodocchgi1 occurs 0 with header line,
t_packing_list like sopcklsti1 occurs 0 with header line,
t_recipients like somlreci1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_objbin like solisti1 occurs 0 with header line.
t_recipients-receiver = 'abc at xyz dot com'.
t_recipients-rec_type = 'U'. " U Means Internet address
append t_recipients.
*** E-MAIL SUBJECT
t_docu_data-obj_descr = 'E-MAIL SUBJECT'.
*** E-MAIL BODY
t_objbin = 'BODY LINE ONE'. append t_objbin.
t_objbin = 'BODY LINE TWO'. append t_objbin.
t_objbin = 'BODY LINE THREE'. append t_objbin.
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
t_packing_list-body_num = 5.
t_packing_list-doc_type = 'TXT'.
t_packing_list-obj_name = ''.
t_packing_list-obj_descr = 'file name'.
t_packing_list-obj_langu = 'EN'.
t_packing_list-doc_size = '9999'.
append t_packing_list.
clear : t_packing_list-transf_bin ,
t_packing_list-doc_size.
t_packing_list-doc_type = 'RAW'.
append t_packing_list.
*** ATTACHMENT
loop at itab. " The internal table consisting of the error messages
t_contents-line = itab-field1.
append t_contents.
t_contents-line = itab-field2.
append t_contents.
endloop.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = t_docu_data
* PUT_IN_OUTBOX = 'X'
tables
packing_list = t_packing_list
object_header = t_object_header
contents_bin = t_objbin
contents_txt = t_contents
receivers = t_recipients
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.
endif.
Regards,
Vikranth
09-16-2009 5:58 AM
Hi Vikranth,
I have used the same code as yours but after executing the function module,I am getting sy-subrc value as 2 and it is giving following error message.
Database error for <ADDR_PERS_COMP_COMM_GET> <0>.
Could you please give me some solution for this.
09-16-2009 6:09 AM
09-16-2009 6:11 AM
Hi,
In the paremeter REC_TYPE try with "A' instead of 'U'.
>>and in Exporting parameters put commit_work = u2018Xu2019 .
May be it can solve your problem.
Regards,
Rajesh Kumar
Edited by: Rajesh Kumar on Sep 16, 2009 7:27 AM
09-16-2009 7:08 AM
Hi,
Now the function module is successful and showing sy-subrc value as '0'.But when I check in SBWP and SOST transactions I couldn't find any entry.
09-16-2009 8:45 AM