Code: Alles auswählen.
* Deklarationen und Oberfläche bzw SpoolNr beschaffen.
:
:
DATA: BEGIN OF pdf OCCURS 0,
t(134),
END OF pdf.
DATA: numbytes TYPE i,
pdfspoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount,
is_otf.
DATA: document_data LIKE sodocchgi1,
object_txt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
object_pack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
object_bin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
receiver_list LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
tab_lines TYPE i.
DATA: client LIKE tst01-dclient,
name LIKE tst01-dname,
objtype LIKE rststype-type,
type LIKE rststype-type.
DATA:
i TYPE i,
k TYPE i,
j TYPE i.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = spoolno
no_dialog = ' '
* DST_DEVICE = 'A4Q'
* PDF_DESTINATION =
IMPORTING
pdf_bytecount = numbytes
pdf_spoolid = pdfspoolid
* LIST_PAGECOUNT =
btc_jobname = jobname
btc_jobcount = jobcount
TABLES
pdf = pdf
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.
IF sy-subrc = 0.
**************************************
* Hier steckt die KONVERTIERUNG
**************************************
k = i = 0.
LOOP AT pdf.
DO 134 TIMES.
j = sy-index - 1.
object_bin+i(1) = pdf+j(1).
i = i + 1.
IF i > 254.
APPEND object_bin.
CLEAR i.
ENDIF.
k = k + 1.
IF k GE numbytes.
IF i NE 0. APPEND object_bin.ENDIF.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
* Titel und Beschreibung
document_data-obj_name = 'TEST_PDF'.
document_data-obj_descr = 'Test mit einem angehängten PDF'.
* Text der Email
object_txt = 'Hallo Benutzername,'.
APPEND object_txt.
object_txt = 'hier Ihre Email.'.
APPEND object_txt.
object_txt = 'Mit freundlichen Grüßen'.
APPEND object_txt.
object_txt = 'Der Versender'.
APPEND object_txt.
* Packing List(Haupt-Email)
* Zaehlen der Zeile von object_txt
DESCRIBE TABLE object_txt LINES tab_lines.
READ TABLE object_txt INDEX tab_lines.
document_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( object_txt ).
* Erzeugen der Packing List
CLEAR object_pack-transf_bin.
object_pack-head_start = 1.
object_pack-head_num = 0.
object_pack-body_start = 1.
object_pack-body_num = tab_lines.
object_pack-doc_type = 'RAW'.
APPEND object_pack.
* Erzeugen des Anhangs
* Packing List(Anhang)
DESCRIBE TABLE object_bin LINES tab_lines.
READ TABLE object_bin INDEX tab_lines.
object_pack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( object_bin ).
object_pack-transf_bin = 'X'.
object_pack-head_start = 1.
object_pack-head_num = 0.
object_pack-body_start = 1.
object_pack-body_num = tab_lines.
object_pack-doc_type = 'PDF'.
object_pack-obj_name = 'SPOOL'.
object_pack-obj_descr = spoolno.
APPEND object_pack.
* Erstellen der Empfänger-Liste
* Externer Benutzer
*receiver_list-receiver = 'BCUSER'.
*receiver_list-rec_type = 'B'.
*APPEND receiver_list.
*Interner Benutzer
LOOP at uname.
receiver_list-receiver = uname-low.
receiver_list-rec_type = 'B'.
APPEND receiver_list.
ENDLOOP.
*Sender der Email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = document_data
put_in_outbox = 'X'
commit_work = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
TABLES
packing_list = object_pack
* OBJECT_HEADER =
contents_bin = object_bin
contents_txt = object_txt
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
receivers = receiver_list
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.
ELSE.
EXIT.
ENDIF.