*&---------------------------------------------------------------------*
*& Subroutinepool YMEDRUCK_EMAIL_UC by Dipl.Ing.Jens G. *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
* WARNING : NO POPUPS - NO COMMIT WORK IN HERE !!!!!!!!!!!!!!!!!!!!!!!!!
* How to do (i left some TODO-comments)
* 1.) Change/verify the "PERFORM" so the "TRUE" Print Routine is called
* (only needed if you have an own ME_DRUCK) just look table TNAPR
* 2.) Change the Receiver Email-adress.
* 3.) Activate YMEDRUCK_EMAIL_UC :-)
* 4.) Customize (Tc NACE) the message-Type "NEU" and enter
* "YMEDRUCK_EMAIL_UC" as Program and "ENTRY_NEU" as FORM
* How this works (short version)
* by customizing, the original Print routine is substituted by this one
* to retrieve the SpoolId, which we need for PDF generation and email.
* YMEDRUCK_EMAIL_UC calls the "Original" Print routine as a subroutine.
* After this step the Program retrieves the Spool created.
* Then the OTF is converted into PDF.
DATA: retcode
LIKE sy
-subrc
. "Returncode DATA: xscreen
(1) TYPE c
. "Output on printer or screen tnapr. "Programs & Forms
*&---------------------------------------------------------------------*
*& Form ENTRY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RETURN_CODE text
* -->US_SCREEN text
*----------------------------------------------------------------------*
FORM entry_neu
USING return_code
TYPE i
us_screen TYPE c.
<p> TYPE ssfcrescl.
DATA pgnam
TYPE na_pgnam
." Programname DATA ronam
TYPE na_ronam
."Formname DATA fm_name
TYPE rs38l_fnam
. "genr.Druckbaustein DATA spoolid
TYPE rspoid
.
xscreen = us_screen.
* Call the "Original" Printroutine
************************
* @@@@ TODO !!!!!
************************
*-real program---------+
* |
*-real Form---+ |
* | |
PERFORM entry_neu
(sapfm06p
) USING return_code us_screen
.
* Try Sapscript (take from mother)
ASSIGN ('(SAPLSTXC)ITCPP') TO <f
>. NOT <f>-tdspoolid IS INITIAL AND
us_screen IS INITIAL.
PERFORM processing
USING <f
>-tdspoolid
. UNASSIGN <f>.
* Try Smartforms (take from mother)
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = tnapr-sform
IMPORTING
fm_name = fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
retcode = 1.
SELECT SINGLE pname
FROM tfdir
INTO lv_vec
WHERE funcname = fm_name.
NOT <p>-spoolids[] IS INITIAL AND
us_screen IS INITIAL.
LOOP AT <p
>-spoolids
INTO spoolid
. UNASSIGN <p>.
ENDIF." sapscript/smartforms
return_code = 1.
return_code = 0.
*&---------------------------------------------------------------------*
*& Form PROCESSING
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM processing
USING spoolid
TYPE itcpp
-tdspoolid
. pdfspoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount.
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.
TYPES pdf_raw
TYPE x
LENGTH 268. DATA: pdf_lines
TYPE TABLE OF tline
, BEGIN OF content_in,
line TYPE tline,
dummy TYPE tline,
END OF content_in,
content_out TYPE solix,
line_width_src TYPE i,
pos_out TYPE i,
pos_in TYPE i,
len_out TYPE i.
DATA content_bin
TYPE TABLE OF solix
.
**** Main - Email ****
* Title and Description
document_data-obj_name = 'BESTELLUNG'.
document_data-obj_descr = nast-objky.
* Email Body Text
SEPARATED BY space.
* Packing List(Main-Part)
* Calculate the contents length
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 ).
* generate the 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'.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = spoolid
no_dialog = ' '
* DST_DEVICE =
* PDF_DESTINATION =
IMPORTING
pdf_bytecount = numbytes
pdf_spoolid = pdfspoolid
* OTF_PAGECOUNT =
btc_jobname = jobname
btc_jobcount = jobcount
pdf = pdf_lines
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.
* Cast to binary type and adjust table line length
DESCRIBE FIELD content_in-line LENGTH line_width_src IN BYTE MODE.
pos_out = 0.
LOOP AT pdf_lines
INTO content_in
-line. ASSIGN content_in
TO <pdf_bin
> CASTING. MOVE <pdf_bin
> TO content_out
-line+pos_out
. ADD line_width_src
TO pos_out
. APPEND content_out
TO content_bin
. pos_in = line_width_src - pos_out.
MOVE <pdf_bin
>+pos_in
TO content_out
-line. APPEND content_out
TO content_bin
.
* Generate the Attachment
* Packing List(Att)
DESCRIBE TABLE content_bin LINES tab_lines.
object_pack-doc_size = numbytes.
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 = nast-objky.
* generate the receiver list
* Internet User
************************
* @@@@ TODO !!!!!
************************
* Your Email Adress goes HERE
receiver_list-receiver = 'SAPUSER@LOCALHOST'.
receiver_list-rec_type = 'U'.
receiver_list-com_type ='INT'.
* Send the mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = document_data
* PUT_IN_OUTBOX = ' '
commit_work = ' '
packing_list = object_pack
contents_txt = object_txt
contents_hex = content_bin
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.