*&---------------------------------------------------------------------*
*& Subroutinepool YMEDRUCK_EMAIL_GOS by TRON *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
* 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_GOS :-)
* 4.) Customize (Tc NACE) the message-Type "NEU" and enter
* "YMEDRUCK_EMAIL_GOS" 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_GOS calls the "Original" Print routine as a subroutine.
* After this step the Program retrieves the Spool created.
* Then the OTF is converted into PDF. In the third step
* YMEDRUCK_EMAIL_GOS collects all Attachments of the Purchase Order and
* sends everything to the assigned Email-Address..vamos
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: BEGIN OF pdf
OCCURS 0, t(134),
END OF pdf.
i TYPE i,
k TYPE i,
j TYPE i.
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.
**** Main - Email ****
* Title and Description
document_data-obj_name = 'PURCHASE ORDER'.
document_data-obj_descr = nast-objky.
* Text of Email
SEPARATED BY space.
* Packing List(Main-Part)
* Calculate the contens 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
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.
k = i = 0.
j = sy-index - 1.
object_bin+i(1) = pdf+j(1).
i = i + 1.
k = k + 1.
* Generate the Attachment
* Packing List(Att)
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 = nast-objky.
* get all GOS - Attachments from Purchase Order
* 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 = 'X' not really
commit_work = ' '
packing_list = object_pack
contents_bin = object_bin
contents_txt = object_txt
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.
retcode = 1.
*&---------------------------------------------------------------------*
*& Form Get_Gos_documents
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->BIN_TAB text
* -->PACK_TAB text
*----------------------------------------------------------------------*
bin_tab STRUCTURE solisti1
pack_tab STRUCTURE sopcklsti1.
CONSTANTS: c_botype
TYPE borident
-objtype
VALUE 'BUS2012', c_reltyp TYPE breltyp-reltype VALUE 'ATTA'.
DATA: lo_is_object_a
TYPE sibflporb
, lt_links TYPE obl_t_link,
ls_links TYPE LINE OF obl_t_link.
DATA : lt_rel
TYPE obl_t_relt
, wa_rel LIKE LINE OF lt_rel.
DATA document_id
TYPE sofolenti1
-doc_id
. DATA document_data
TYPE sofolenti1
. DATA object_content
TYPE TABLE OF solisti1
WITH HEADER LINE.
wa_rel-sign = 'I'.
wa_rel-option = 'EQ'.
wa_rel-low = c_reltyp.
lo_is_object_a-instid = nast-objky.
lo_is_object_a-typeid = c_botype.
lo_is_object_a-catid = 'BO'.
* get all links to the attached PO documents
CALL METHOD cl_binary_relation=>read_links
EXPORTING
is_object = lo_is_object_a
it_relation_options = lt_rel
IMPORTING
et_links = lt_links.
retcode = 1.
* attach all GOS documents to the mail
LOOP AT lt_links
INTO ls_links
.
document_id = ls_links-instid_b.
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = document_id
IMPORTING
document_data = document_data
object_content = object_content
EXCEPTIONS
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
OTHERS = 4.
* Packing List(GOS-Att)
DESCRIBE TABLE bin_tab LINES i.
DESCRIBE TABLE object_content LINES tlines.
READ TABLE object_content INDEX tlines.
* calc the true length
pack_tab-doc_size = ( tlines - 1 ) * 255
+ STRLEN( object_content ).
pack_tab-transf_bin = 'X'.
pack_tab-head_start = 1 + i .
pack_tab-head_num = 0.
pack_tab-body_start = 1 + i .
pack_tab-body_num = tlines.
pack_tab-doc_type = document_data-obj_type.
pack_tab-obj_name = document_data-obj_name.
pack_tab-obj_descr = document_data-obj_descr.
APPEND LINES OF object_content
TO bin_tab
.