We have added search box. Key in SAP issue keyword to search
TopBottom

Announcement: wanna exchange links? contact me at sapchatroom@gmail.com.

[sap-dev] SAP Mail with an PDF attachment

Posted by Admin at
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

Posted by The_Boondock_Saints
on Sep 10 at 4:50 AM
Hello,

I've got a big problem. i read a lot of threads about the attachments for a mail in sap.
but in my program it's a kind tricky.
in the parameter p_file you can choose a pdf file. this should be an attachment in the mail. but it doesn't work.
the pdf if file is empty.
But i don't know how i can get the pdf file i chose into the mail.

here is my program:
TYPES: t_text_data(4096) TYPE c.
TYPES: t_it_solisti1 TYPE TABLE OF solisti1.
TYPES: t_line TYPE tline,
t_lines TYPE TABLE OF t_line.
DATA: lit_objcsv TYPE TABLE OF t_text_data,
lit_body TYPE t_it_solisti1,
lit_objtxt TYPE t_it_solisti1,
lit_lines TYPE t_lines.

DATA: ls_body TYPE solisti1,
ls_objtxt TYPE solisti1,
wa_line TYPE tline.

DATA: li_lines TYPE i,
li_length TYPE i,
li_next_row_objtxt TYPE i.

DATA: docdata LIKE sodocchgi1,
objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objhex LIKE solix OCCURS 10 WITH HEADER LINE,
reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.

DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.

DATA: tab_lines TYPE i,
doc_size TYPE i,
att_type LIKE soodk-objtp.

DATA: lines TYPE TABLE OF tline.
DATA: bdoc_size TYPE so_doc_siz.

DATA: it_tab TYPE filetable,
g_subrc TYPE i.

DATA: l_date(10),
l_uzeit(8),
l_text(255).


* Eingabefelder
PARAMETERS: p_rec(15) TYPE c ,
p_trans(15) TYPE c,
p_file(25) TYPE c.

CLEAR objbin.
REFRESH objbin.
CLEAR objhex.
REFRESH objhex.

docdata-obj_name = 'Ă„nderung einer Transaktion'.
docdata-obj_descr = 'Ă„nderung einer Transaktion'.

* Umwandlung des Datums und der Zeit
CONCATENATE space sy-datum+6(2) '.' sy-datum+4(2) '.' sy-datum(4) INTO l_date.
CONCATENATE sy-uzeit(2) ':' sy-uzeit+2(2) ':' sy-uzeit+4(2) INTO l_uzeit.

* Body-Text Gestaltung
CONCATENATE 'NEWSLETTER vom' l_date 'um' l_uzeit INTO ls_body-line SEPARATED BY space.
APPEND ls_body TO lit_body.

APPEND text-001 TO lit_body. " text-001 dient als Leerzeile
APPEND text-002 TO lit_body. " -----------
CONCATENATE text-003 p_trans INTO l_text SEPARATED BY space.
APPEND l_text TO lit_body.
APPEND text-002 TO lit_body.
APPEND text-001 TO lit_body.
APPEND text-004 TO lit_body.
APPEND text-001 TO lit_body.
CONCATENATE text-005 p_trans text-006 INTO l_text SEPARATED BY space.
APPEND l_text TO lit_body.
APPEND text-007 TO lit_body.
APPEND text-008 TO lit_body.
APPEND text-001 TO lit_body.
APPEND text-009 TO lit_body.
APPEND text-001 TO lit_body.
APPEND text-002 TO lit_body.
APPEND text-001 TO lit_body.
APPEND text-010 TO lit_body.
APPEND text-001 TO lit_body.
APPEND text-001 TO lit_body.
APPEND text-011 TO lit_body.
APPEND text-012 TO lit_body.
APPEND text-013 TO lit_body.
APPEND text-014 TO lit_body.

* Body-text in Text-Tabelle eintragen
LOOP AT lit_body INTO ls_body.
APPEND ls_body TO lit_objtxt.
ENDLOOP.

DESCRIBE TABLE lit_body LINES li_lines.
DESCRIBE FIELD ls_body LENGTH li_length IN CHARACTER MODE.
READ TABLE lit_body INTO ls_body INDEX li_lines.
docdata-doc_size = ( li_lines - 1 ) * li_length +
STRLEN( ls_body ).

* Packing List
CLEAR: objpack-transf_bin, objpack.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = li_lines.
objpack-doc_type = 'RAW'. " SAP Text Dokument
objpack-transf_bin = 'T'. " Transaktion
APPEND objpack.

li_next_row_objtxt = li_lines + 1.

IF p_rec NE space.
reclist-receiver = p_rec.
MOVE 'B' TO reclist-rec_type. " an die SAP-Benutzer
reclist-express = 'X'. " als Expressnachricht
APPEND reclist.
ENDIF.

* Generate Attachment
DESCRIBE TABLE objbin LINES li_lines.
READ TABLE objbin INDEX li_lines.

objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = li_lines.
objpack-doc_type = 'PDF'.
objpack-obj_name = 'Anlage'.
objpack-obj_descr = 'Beschreibung Transaktionsänderung'.
objpack-doc_size = li_lines * 255.
APPEND objpack.


*** Aufruf fĂ¼r Mehtode um Datei auszuwählen

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. " wenn auf p_file gegangen wird

CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Datei auswählen'
default_filename = '*.pdf'
multiselection = ''
CHANGING
file_table = it_tab " Ăœbergabetabelle
rc = g_subrc.

LOOP AT it_tab INTO p_file.
ENDLOOP.

*call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
* exporting
* src_spoolid = p_file
* no_dialog = ''
* importing
* pdf_bytecount = bytecount
* tables
* pdf = it_tab
* 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.

START-OF-SELECTION.

*** Aufruf des Funktiosnbausteins zum Versenden der Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = lit_objtxt
* ontents_hex = objhex
* OBJECT_PARA =
* OBJECT_PARB =
receivers = reclist
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
.

* Ausgabe Fehlermeldung
CASE sy-subrc.
WHEN 0.
WRITE: 'Ergebnis des Sendevorgangs:'.
LOOP AT reclist.
WRITE: / reclist-receiver(50).
IF reclist-retrn_code = 0.
WRITE: ' wurde erfolgreich gesendet'.
ELSE.
WRITE: 'nicht versendet'.
ENDIF.
ENDLOOP.

WHEN 1.
WRITE: ' Es sind zu viele Empfänger, um das Dokument zu versenden'.

WHEN 2.
WRITE: ' Das Dokument konnte nicht versendet werden'.

WHEN 4.
WRITE: ' Sie haben keine Berechtigung zum Versand des Dokumentes'.

WHEN OTHERS.
WRITE: ' Fehler beim Senden'.

ENDCASE.
COMMIT WORK.

i don't know if i need the fm convert...and when yes, what declarations do i need.


Thanks a lot!
Greetings
Marcel

__.____._
Copyright © 2010 Toolbox.com and message author.

Toolbox.com 4343 N. Scottsdale Road Suite 280, Scottsdale, AZ 85251
In the Spotlight
Toolbox.com for iPhone: Ask Questions & Get Answers Anywhere. Use the New iPhone App
_.____.__

0 comments:

Post a Comment

T r a n s l a t e to your language