Skip to Content
0
Former Member
Apr 24, 2007 at 12:53 PM

script in email problem!

20 Views

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