cancel
Showing results for 
Search instead for 
Did you mean: 

script in email problem!

Former Member
0 Kudos

Hi,

I'm using the following code to send the output of the scipt as a PDF attachment in mail. An exception 4(<b>operation_no_authorization</b>) is getting raised in SO_NEW_DOCUMENT_ATT_SEND_API1.

Can anybody tell why this <b>operation_no_authorization</b> exception is being raised.

&----


*& Report ZRV_SCRIPT_EMAIL *

*& *

&----


*& *

*& *

&----


REPORT zrv_script_email .

TABLES mara.

SELECT-OPTIONS: s_matnr FOR mara-matnr.

DATA: BEGIN OF itab OCCURS 0,

mtart TYPE mara-mtart,

mbrsh TYPE mara-mbrsh,

matkl TYPE mara-matkl,

END OF itab.

DATA: itcpo TYPE itcpo.

DATA: pdftab TYPE TABLE OF tline WITH HEADER LINE,

datab TYPE TABLE OF itcoo WITH HEADER LINE.

DATA: binfilesize TYPE i,

file_name TYPE string,

file_path TYPE string,

full_path TYPE string.

START-OF-SELECTION.

itcpo-tdnoprev = 'X'.

itcpo-tddest = 'LP01'.

itcpo-tdgetotf = 'X'.

SELECT mtart mbrsh matkl

FROM mara

INTO TABLE itab

WHERE matnr IN s_matnr.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

device = 'PRINTER'

dialog = ''

form = 'ZSCRIPT_EMAIL'

language = sy-langu

options = itcpo.

LOOP AT itab.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'ELEMENT1'

function = 'SET'

type = 'BODY'

window = 'MAIN'.

ENDLOOP.

CALL FUNCTION 'CLOSE_FORM'

TABLES

otfdata = datab[].

*****************conver to OTF***************

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

IMPORTING

bin_filesize = binfilesize

TABLES

otf = datab[]

lines = pdftab[].

*****************Download PDF File******

  • CALL FUNCTION 'GUI_DOWNLOAD'

  • EXPORTING

  • bin_filesize = binfilesize

  • filename = 'D:\test.pdf'

  • filetype = 'BIN'

  • TABLES

  • data_tab = pdftab[].

                                    • Mail settings **************

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 righe_attachment TYPE i.

DATA righe_testo TYPE i.

DATA z_email(80) TYPE c.

  • Receivers parameters

SELECT-OPTIONS: s_email FOR z_email LOWER CASE NO INTERVALS.

PARAMETERS rec_type LIKE reclist-rec_type

DEFAULT 'U'. " type of sending address

CLEAR: reclist, reclist[],

objhead, objhead[],

objtxt, objtxt[],

objbin, objbin[],

objpack, objpack[].

  • Attachment filling

LOOP AT pdftab.

objbin-line = pdftab.

APPEND objbin.

ENDLOOP.

DESCRIBE TABLE objbin LINES righe_attachment.

  • Text filling

objtxt = 'Testo della Mail - Riga 1'.APPEND objtxt.

objtxt = 'Testo della Mail - Riga 2'.APPEND objtxt.

objtxt = 'Testo della Mail - Riga n'.APPEND objtxt.

DESCRIBE TABLE objtxt LINES righe_testo.

  • Other filling

doc_chng-obj_name = 'URGENT'.

doc_chng-expiry_dat = sy-datum + 10.

doc_chng-obj_descr = 'Prova invio Mail con PDF'.

doc_chng-sensitivty = 'O'.

doc_chng-doc_size = righe_testo * 255.

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = righe_testo.

objpack-doc_type = 'RAW'.

APPEND objpack.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = righe_attachment.

objpack-doc_type = 'PDF'.

objpack-obj_name = 'TEST'.

objpack-obj_descr = 'File.pdf'.

objpack-doc_size = righe_attachment * 255.

APPEND objpack.

  • Receivers filling

LOOP AT s_email WHERE sign = 'I'

AND option = 'EQ'

AND NOT ( low IS INITIAL ).

CLEAR reclist.

IF sy-tabix > 1.

reclist-copy = 'X'.

ENDIF.

reclist-receiver = s_email-low.

IF rec_type IS INITIAL.

reclist-rec_type = 'U'. " Internet e-mail

ELSE.

reclist-rec_type = rec_type.

ENDIF.

reclist-notif_del = 'X'. " request delivery notification

reclist-notif_ndel = 'X'. " request not delivered notification

APPEND reclist.

ENDLOOP.

  • Mail Send

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = reclist

  • CONTENTS_HEX =

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.

WRITE: sy-subrc.

regards,

Ravi.

Points will be given

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Check with your Basis Guy and also see your user profile

there maintain ur user id and then send email to ur email id.

If it is not working then might be ur code problem.

Reward points if it is useful.

Thanks

Seshu

Former Member
0 Kudos

hi ,

Also note that the communication email address should be maintained in ur SU01 user profile .

Go to SBWP and compose an email and send it to external email address .

If it fails there....then the communication email address is the issue..

The email generated can be checked in SOST

Thanks

Former Member
0 Kudos

Hi Soumyadip,

I made the required settings. Now the returncode is 0, but no mail is beng sent.SOST is simply empty.could u please help me out.

regards,

ravi.

Former Member
0 Kudos

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = maildata

document_type = 'RAW'

put_in_outbox = 'X'

<b>Commit_work = 'X'.</b>

here u will get one more parameter to commit thw work , check that one

Regards

prabhu

Answers (1)

Answers (1)

Former Member
0 Kudos

HI Ravi

OPERATION_NO_AUTHORIZATION means

The document was not allowed to be sent, because one of the required authorizations did not exist for you.



Go through this example Program:
*----------------------------------------------------------------------*
* INCLUDE ZINCUSMAIL *
*----------------------------------------------------------------------*
include <symbol>.
data : i_doc_data like sodocchgi1.
data : begin of i_pack_list occurs 0.
include structure sopcklsti1.
data : end of i_pack_list.
data : begin of i_receivers occurs 0.
include structure somlreci1.
data : end of i_receivers.
data : begin of i_contents occurs 0.
include structure solisti1.
data : end of i_contents.
data : begin of i_header occurs 0.
include structure solisti1.
data : end of i_header.
data : begin of i_att occurs 0.
include structure solisti1.
data : end of i_att.
* Internal Table for Internet address.
data: begin of it_inad occurs 0,
kunnr like kna1-kunnr, " Customer Code
name1 like kna1-name1, " Customer Name
ssobl like knkk-ssobl, " Security Deposit
klimk like knkk-klimk, " Credit Limit
opbal like bsid-wrbtr, " Opening Balance
clbal like bsid-wrbtr, " Closing Balance
smtp like adr6-smtp_addr, " Internet mail (SMTP) address
end of it_inad.
data : pdf_line(134),
asdf like pdf_line occurs 0 with header line.
data : pdf_table like tline occurs 0 with header line,
pdf_fsize type i.
data : stuff(65000),
len type i,
pos type i,
tab_lines like sy-tabix.
data: spoolid type tsp01-rqident,
spdel type tsp01sys.
data: v_gjahrt like bsid-gjahr,
fmondest(10),
tmondest(10),
kunnr1 like kna1-kunnr,
gjah(4),
fmon(10).


*&---------------------------------------------------------------------*
*& Form hide_write
*&---------------------------------------------------------------------*
form hide_write.
new-page print on
line-size 160
* line-count 58
no-title
no-heading
destination 'LOCL'
immediately ' '
new list identification 'X'
no dialog.
set blank lines on.
endform. " hide_write
*&---------------------------------------------------------------------*
*& Form end_write
*&---------------------------------------------------------------------*
form end_write using kunnr1.

set blank lines off.
new-page print off.

***Using Spoolid we are getting PDF formated file
spoolid = spdel-rqident = sy-spono.
spdel-sys = sy-sysid.
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid = spoolid
no_dialog = 'X'
importing
pdf_bytecount = pdf_fsize
tables
pdf = pdf_table
exceptions
others = 0.

***Delleting Spool request
call function 'RSPO_IDELETE_SPOOLREQ'
exporting
spoolreq = spdel
exceptions
others = 2.
***Converting PDF table line size 134 into standard list size 255
loop at pdf_table into pdf_line.
if pos = 34170.
perform attach.
endif.
stuff+pos(134) = pdf_line.
add 134 to pos.
endloop.
if not ( stuff is initial ).
perform attach.
endif.
clear pdf_line.
clear pdf_table[].
describe table i_att lines tab_lines.
i_pack_list-transf_bin = 'X'.
i_pack_list-head_start = '1'.
i_pack_list-head_num = '1'.
i_pack_list-body_start = '1'.
i_pack_list-body_num = tab_lines.
i_pack_list-doc_type = 'PDF'.
i_pack_list-obj_name = 'LedgerMail'.
concatenate fmon '-' gjah into i_pack_list-obj_descr.
*i_pack_list-obj_descr = '2092-Oct03'.
i_pack_list-obj_langu = 'E'.
i_pack_list-doc_size = tab_lines * 255.
append i_pack_list.

***Data for receivers list
loop at it_inad where kunnr eq kunnr1.
i_receivers-receiver = it_inad-smtp.
i_receivers-rec_type = 'U'.
i_receivers-rec_date = sy-datum.
i_receivers-express = 'X'.
i_receivers-com_type = 'INT'.
i_receivers-notif_del = 'X'.
append i_receivers.
endloop.

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = i_doc_data
* PUT_IN_OUTBOX = ' '
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
tables
packing_list = i_pack_list
object_header = i_header
contents_bin = i_att
contents_txt = i_contents
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
.
refresh i_att. clear i_att.
refresh i_receivers. clear i_receivers.
delete i_pack_list where doc_type = 'PDF'.
*refresh i_header.
*refresh i_contents.
*clear i_doc_data.
endform. " end_write
*&---------------------------------------------------------------------*
*& Form doc_data
*&---------------------------------------------------------------------*
form doc_data using fmondest v_gjahrt.
gjah = v_gjahrt.
fmon = fmondest.
***Data for Document Data
i_doc_data-obj_name = 'LedgerMail'.
concatenate 'Customer Ledger for : ' fmondest gjah
into i_doc_data-obj_descr separated by space.
i_doc_data-obj_langu = 'E'.
i_doc_data-obj_prio = '1'.
i_doc_data-no_change = 'X'.
i_doc_data-doc_size = '5101'.

***Data for Packing list
i_pack_list-head_start = '1'.
i_pack_list-head_num = '1'.
i_pack_list-body_start = '1'.
i_pack_list-body_num = '20'.
i_pack_list-doc_type = 'RAW'.
i_pack_list-obj_langu = 'E'.
append i_pack_list.

***Data for Header
i_header-line = 'Header'. append i_header.

***Data for contents
i_contents-line = 'Dear Customer,'. append i_contents.
i_contents-line = ' '. append i_contents.
concatenate 'Please find your enclosed Ledger for the month of : '
fmondest gjah into i_contents-line separated by space.
append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = 'This is a computer generated document and does not
require a signature.'. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = 'Note : If you do not have Acrobat Reader please click
on the below link.'. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = 'http://www.adobe.com/products/acrobat/readstep2.html'
. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.

endform. " doc_data
*&---------------------------------------------------------------------*
*& Form attach
*&---------------------------------------------------------------------*
form attach.
clear pos.
len = strlen( stuff ).
while len > 0.
subtract 255 from len.
i_att = stuff+pos(255).
append i_att.
add 255 to pos.
endwhile.
clear pos.
clear stuff.
endform. " attach

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

/people/thomas.jung3/blog/2004/09/07/sending-e-mail-from-abap--version-46d-and-lower--api-interface

Another example of The BCS Classes for sending email can be found here.

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

It is a nice OO approach to sending Email and can be used from any type of ABAP program(WebAS version 6.10 and higher). I have used it in a Unicode system and as long as you have your setup correct in SCOT (the code page setting in the General Node Data Configuration screen) it works fine.

/people/gregor.wolf3/blog/2006/05/25/extend-thomas-jung146s-simple-mail-function-with-attachment-filename

/people/thomas.jung3/blog/2004/09/07/sending-e-mail-from-abap--version-46d-and-lower--api-interface

Regards Rk

Message was edited by:

Rk Pasupuleti