Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report YBC_JOB_SPOOL_MAIL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ztest70.
TABLES adr6.
* ============ SAP Hinweis 186603 ==============
*Bei der Anzeige einer Spool-Liste in der SP01 und bei der
*Weiterverarbeitung (z.B. Senden an SAPoffice) wird die Breite
*der Liste immer auf 255 gesetzt, egal wie breit die Liste vorher war.
TABLES: tsp01.
DATA pdf_xstring TYPE xstring.
DATA pdf_size TYPE so_obj_len.
DATA send_request TYPE REF TO cl_bcs.
DATA document TYPE REF TO cl_document_bcs.
DATA recipient TYPE REF TO if_recipient_bcs.
DATA bcs_exception TYPE REF TO cx_bcs.
DATA sent_to_all TYPE os_boolean.
DATA pdf_content TYPE solix_tab.
DATA mailto TYPE ad_smtpadr VALUE 'Thomas.Schneider@ec6.com'.
DATA gv_subject TYPE so_obj_des.
DATA sender TYPE REF TO if_sender_bcs.
DATA l_sendadr TYPE adr6-smtp_addr.
DATA: numbytes TYPE i,
pdfspoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount,
is_otf.
* Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
gd_eventparm LIKE tbtcm-eventparm,
gd_external_program_active LIKE tbtcm-xpgactive,
gd_jobcount LIKE tbtcm-jobcount,
gd_jobname LIKE tbtcm-jobname,
gd_stepcount LIKE tbtcm-stepcount.
* Spool IDs
TYPES: BEGIN OF t_tbtcp.
INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
wa_tbtcp TYPE t_tbtcp.
DATA spoolno LIKE tsp01-rqident.
*PARAMETERS p_uname TYPE usr02-bname DEFAULT sy-uname.
SELECT-OPTIONS p_smtp FOR adr6-smtp_addr NO INTERVALS.
IF p_smtp[] IS INITIAL.
SKIP.
WRITE:/ '>>> Keine Email Adressen übergeben ! <<<'
COLOR COL_NEGATIVE INTENSIFIED OFF .
ENDIF.
* Klappt NUR als Job !!!!!!
IF sy-batch IS INITIAL.
SKIP.
WRITE:/ '>>> Programm muss im Hintergrund (als Job) laufen <<<'
COLOR COL_NEGATIVE INTENSIFIED OFF .
EXIT.
ENDIF.
* Get current job details
CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
IMPORTING
eventid = gd_eventid
eventparm = gd_eventparm
external_program_active = gd_external_program_active
jobcount = gd_jobcount
jobname = gd_jobname
stepcount = gd_stepcount
EXCEPTIONS
no_runtime_info = 1
OTHERS = 2.
* Nimm das Spoolfile des vorherigen Steps
gd_stepcount = gd_stepcount - 1.
IF gd_stepcount < 1.
MESSAGE s398(00) WITH
'Problem - kann nicht als STEP 1 laufen !!' '' '' ''.
EXIT.
ENDIF.
SELECT * FROM tbtcp INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname jobcount stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
spoolno = wa_tbtcp-listident.
MESSAGE s398(00) WITH 'Spoolnummer ' spoolno ' gefunden.' '' .
ELSE.
MESSAGE s398(00) WITH 'Problem - keine Spoolnummer gefunden' '' '' ''.
EXIT.
ENDIF.
SELECT SINGLE * FROM tsp01 WHERE rqident = spoolno.
IF sy-subrc <> 0.
WRITE: / 'Spoolauftrag existiert nicht'(003)
COLOR COL_NEGATIVE.
EXIT.
ENDIF.
PERFORM gen_subject CHANGING gv_subject.
PERFORM create_pdf.
PERFORM send.
*&---------------------------------------------------------------------*
*& Form send
*&---------------------------------------------------------------------*
FORM send.
DATA:
lv_pers_nr TYPE ad_persnum,
lv_adr_nr TYPE ad_addrnum,
lv_smtp_addr TYPE ad_smtpadr.
* SELECT SINGLE persnumber addrnumber FROM usr21 INTO (lv_pers_nr,lv_adr_nr) WHERE
* bname = p_uname.
* IF sy-subrc = 0.
* SELECT SINGLE smtp_addr FROM adr6 INTO lv_smtp_addr WHERE
* addrnumber = lv_adr_nr AND
* persnumber = lv_pers_nr AND
* flgdefault = 'X'.
* ENDIF.
*
* IF NOT lv_smtp_addr IS INITIAL.
* mailto = lv_smtp_addr.
* ENDIF.
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document -------------------------------
pdf_content = cl_document_bcs=>xstring_to_solix( pdf_xstring ).
document = cl_document_bcs=>create_document(
i_type = 'PDF'
i_hex = pdf_content
i_length = pdf_size
i_subject = gv_subject ). "#EC NOTEXT
* add document object to send request
send_request->set_document( document ).
* create sender and add to send request
CONCATENATE 'Noreply@' sy-sysid '-' sy-mandt '.sam' INTO l_sendadr.
sender = cl_cam_address_bcs=>create_internet_address( l_sendadr ).
send_request->set_sender( EXPORTING i_sender = sender ).
* --------- add recipient (e-mail address) -----------------------
* create recipient object
LOOP AT p_smtp.
recipient = cl_cam_address_bcs=>create_internet_address( p_smtp-low ).
* add recipient object to send request
send_request->add_recipient( recipient ).
ENDLOOP.
* ---------- send document ---------------------------------------
send_request->set_send_immediately( i_send_immediately = 'X' ).
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
COMMIT WORK.
IF sent_to_all IS INITIAL.
MESSAGE i500(sbcoms) WITH mailto.
ELSE.
MESSAGE s022(so).
ENDIF.
* ------------ exception handling ----------------------------------
* replace this rudimentary exception handling with your own one !!!
CATCH cx_bcs INTO bcs_exception.
MESSAGE i865(so) WITH bcs_exception->error_type.
ENDTRY.
ENDFORM. "send
*&---------------------------------------------------------------------*
*& Form create_pdf
*&---------------------------------------------------------------------*
* Create PDF Content
* 1) get attributes of spool request
* 2) convert spool request to PDF dependent on document type
*----------------------------------------------------------------------*
FORM create_pdf.
DATA rqident TYPE tsp01-rqident .
DATA rq TYPE tsp01.
DATA bin_size TYPE i.
DATA dummy TYPE TABLE OF rspoattr.
rqident = spoolno.
* ------------ get attributes of spool request ---------------------
CALL FUNCTION 'RSPO_GET_ATTRIBUTES_SPOOLJOB'
EXPORTING
rqident = rqident
IMPORTING
rq = rq
TABLES
attributes = dummy
EXCEPTIONS
no_such_job = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e126(po) WITH rqident.
ENDIF.
* --- convert spool request into PDF, dependent on document type ---
IF rq-rqdoctype = 'OTF' OR rq-rqdoctype = 'SMART'.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = rqident
no_dialog = 'X'
pdf_destination = 'X'
no_background = 'X'
IMPORTING
pdf_bytecount = bin_size
bin_file = pdf_xstring
EXCEPTIONS
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 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 e712(po) WITH sy-subrc 'CONVERT_OTFSPOOLJOB_2_PDF'.
ENDIF.
ELSEIF rq-rqdoctype = 'LIST'.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = rqident
no_dialog = 'X'
pdf_destination = 'X'
no_background = 'X'
IMPORTING
pdf_bytecount = bin_size
bin_file = pdf_xstring
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 e712(po) WITH sy-subrc 'CONVERT_ABAPSPOOLJOB_2_PDF'.
ENDIF.
ELSE.
MESSAGE e789(po) WITH rq-rqdoctype.
ENDIF.
pdf_size = bin_size.
ENDFORM. "create_pdf
*&---------------------------------------------------------------------*
*& Form gen_subject
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM gen_subject CHANGING i_subject TYPE so_obj_des.
DATA lv_date TYPE scal-date.
DATA lv_week TYPE scal-week.
lv_date = sy-datum.
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
date = lv_date
IMPORTING
week = lv_week
EXCEPTIONS
date_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
IF sy-langu = 'D'.
CONCATENATE
'CATS Zeiten auf Projekt für KW' lv_week+4 INTO i_subject.
ELSE.
CONCATENATE
'CATS hours on projects for week' lv_week+4 INTO i_subject.
ENDIF.
ENDFORM. "gen_subject
Code: Alles auswählen.
lr_document = cl_document_bcs=>create_document(
* i_type = lc_raw
i_type ='HTM'
i_text = lit_text
* i_length = '12'
i_subject = lc_subject && <lfs_notif>-qmnum ).