Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Subroutinepool YFAKTURA_EMAIL by TRON *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
* WARNING : NO POPUPS - NO COMMIT WORK IN HERE !!!!!!!!!!!!!!!!!!!!!!!!!
REPORT yfaktura_email.
DATA: retcode LIKE sy-subrc. "Returncode
DATA: xscreen(1) TYPE c. "Output on printer or screen
TABLES: nast, "Messages
tnapr. "Programs & Forms
*&---------------------------------------------------------------------*
*& Form ENTRY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RETURN_CODE text
* -->US_SCREEN text
*----------------------------------------------------------------------*
FORM entry USING return_code TYPE i
us_screen TYPE c.
FIELD-SYMBOLS: <f> TYPE itcpp,
<p> TYPE ssfcrescl.
DATA pgnam TYPE na_pgnam." Programname
DATA ronam TYPE na_ronam."Formname
DATA fm_name TYPE rs38l_fnam. "genr.Druckbaustein
DATA lv_vec(80).
DATA spoolid TYPE rspoid.
CLEAR retcode.
xscreen = us_screen.
* Call the "Original" Printroutine
* RVADIN01 = Sapscript
* RLB_INVOICE = Smartforms
*-Orig program------+
* |
*-Orig Form-+ |
* | |
PERFORM entry(RLB_INVOICE) USING return_code us_screen.
* Try Sapscript
ASSIGN ('(SAPLSTXC)ITCPP') TO <f>.
IF sy-subrc = 0 AND
NOT <f>-tdspoolid IS INITIAL AND
us_screen IS INITIAL.
PERFORM processing USING <f>-tdspoolid.
UNASSIGN <f>.
ELSE.
* Try Smartforms
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.
IF sy-subrc <> 0.
retcode = 1.
EXIT.
ENDIF.
SELECT SINGLE pname FROM tfdir INTO lv_vec
WHERE funcname = fm_name.
IF sy-subrc = 0.
CONCATENATE '(' lv_vec ')JOB_OUTPUT_INFO' INTO lv_vec.
ASSIGN (lv_vec) TO <p>.
IF sy-subrc = 0 AND
NOT <p>-spoolids[] IS INITIAL AND
us_screen IS INITIAL.
LOOP AT <p>-spoolids INTO spoolid.
PERFORM processing USING spoolid.
EXIT.
ENDLOOP.
UNASSIGN <p>.
ENDIF. " have Ids
ENDIF." tfdir entry
ENDIF." sapscript/smartforms
IF retcode NE 0.
return_code = 1.
ELSE.
return_code = 0.
ENDIF.
ENDFORM. "ENTRY
*&---------------------------------------------------------------------*
*& Form PROCESSING
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM processing USING spoolid TYPE itcpp-tdspoolid.
DATA: numbytes TYPE i,
pdfspoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount.
DATA: BEGIN OF pdf OCCURS 0,
t(134),
END OF pdf.
DATA:
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.
* for Invoice Header Text
data:
lv_ID type THEAD-TDID value 'YEML',
lv_LANGUAGE type THEAD-TDSPRAS,
lv_NAME type THEAD-TDNAME,
lv_OBJECT type THEAD-TDOBJECT value 'VBBK',
lt_lines type table of tline,
ls_line type tline.
* For partner Email
constants:
lv_ITEM_NUMBER type VBUP-POSNR value '000000',
lv_PARTNER_ROLE type VBPA-PARVW value 'RE'.
data:
lv_DOCUMENT_NUMBER type VBUK-VBELN,
ls_vbpa type vbpa.
**** Main - Email ****
* Title and Description
document_data-obj_name = 'INVOICE'.
document_data-obj_descr = nast-objky.
* Text of Email
CONCATENATE 'Rechnung' nast-objky INTO object_txt
SEPARATED BY space.
APPEND object_txt.
lv_language = nast-spras.
lv_NAME = nast-objky.
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = lv_ID
LANGUAGE = lv_LANGUAGE
NAME = lv_NAME
OBJECT = lv_OBJECT
TABLES
LINES = lt_lines
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
ENDIF.
loop at lt_lines into ls_line.
append ls_line-TDLINE to object_txt.
endloop.
* 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'.
APPEND object_pack.
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
TABLES
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.
IF sy-subrc = 0.
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.
ELSE.
EXIT.
ENDIF.
* 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.
APPEND object_pack.
* generate the receiver list
lv_DOCUMENT_NUMBER = nast-objky.
* Get Partner RE Email
CALL FUNCTION 'SD_VBPA_SELECT'
EXPORTING
I_DOCUMENT_NUMBER = lv_DOCUMENT_NUMBER
I_ITEM_NUMBER = lv_ITEM_NUMBER
I_PARTNER_ROLE = lv_PARTNER_ROLE
IMPORTING
E_VBPA = ls_vbpa
EXCEPTIONS
PARTNER_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
* Internet User
clear receiver_list.
select single SMTP_ADDR from adr6 into receiver_list-receiver where
ADDRNUMBER = ls_vbpa-adrnr and FLGDEFAULT = 'X'.
if sy-subrc = 0 and not receiver_list-receiver is initial.
receiver_list-rec_type = 'U'.
receiver_list-com_type ='INT'.
APPEND receiver_list.
else.
receiver_list-receiver = 'SAPUSER@LOCALHOST'.
receiver_list-rec_type = 'U'.
receiver_list-com_type ='INT'.
APPEND receiver_list.
endif.
* Send the mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = document_data
* put_in_outbox = 'X' not really
commit_work = ' '
TABLES
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.
IF sy-subrc <> 0.
retcode = 1.
ENDIF.
ENDFORM. "PROCESSING
Code: Alles auswählen.
PERFORM entry(RLB_INVOICE) USING return_code us_screen.
Code: Alles auswählen.
PERFORM entry(rvadin01) USING return_code us_screen.
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Subroutinepool YFAKTURA_EMAIL by TRON *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
* WARNING : NO POPUPS - NO COMMIT WORK IN HERE !!!!!!!!!!!!!!!!!!!!!!!!!
REPORT yfaktura_email.
DATA: retcode LIKE sy-subrc. "Returncode
DATA: xscreen(1) TYPE c. "Output on printer or screen
TABLES: nast, "Messages
tnapr. "Programs & Forms
*&---------------------------------------------------------------------*
*& Form ENTRY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RETURN_CODE text
* -->US_SCREEN text
*----------------------------------------------------------------------*
FORM entry USING return_code TYPE i
us_screen TYPE c.
FIELD-SYMBOLS: <f> TYPE itcpp,
<p> TYPE ssfcrescl.
DATA pgnam TYPE na_pgnam." Programname
DATA ronam TYPE na_ronam."Formname
DATA fm_name TYPE rs38l_fnam. "genr.Druckbaustein
DATA lv_vec(80).
DATA spoolid TYPE rspoid.
CLEAR retcode.
xscreen = us_screen.
* Call the "Original" Printroutine
* RVADIN01 = Sapscript
* RLB_INVOICE = Smartforms
*-Orig program------+
* |
*-Orig Form-+ |
* | |
PERFORM entry(rvadin01) USING return_code us_screen.
* Try Sapscript
ASSIGN ('(SAPLSTXC)ITCPP') TO <f>.
IF sy-subrc = 0 AND
NOT <f>-tdspoolid IS INITIAL AND
us_screen IS INITIAL.
PERFORM processing USING <f>-tdspoolid.
UNASSIGN <f>.
ELSE.
* Try Smartforms
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.
IF sy-subrc <> 0.
retcode = 1.
EXIT.
ENDIF.
SELECT SINGLE pname FROM tfdir INTO lv_vec
WHERE funcname = fm_name.
IF sy-subrc = 0.
CONCATENATE '(' lv_vec ')JOB_OUTPUT_INFO' INTO lv_vec.
ASSIGN (lv_vec) TO <p>.
IF sy-subrc = 0 AND
NOT <p>-spoolids[] IS INITIAL AND
us_screen IS INITIAL.
LOOP AT <p>-spoolids INTO spoolid.
PERFORM processing USING spoolid.
EXIT.
ENDLOOP.
UNASSIGN <p>.
ENDIF. " have Ids
ENDIF." tfdir entry
ENDIF." sapscript/smartforms
IF retcode NE 0.
return_code = 1.
ELSE.
return_code = 0.
ENDIF.
ENDFORM. "ENTRY
*&---------------------------------------------------------------------*
*& Form PROCESSING
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM processing USING spoolid TYPE itcpp-tdspoolid.
DATA: numbytes TYPE i,
pdfspoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount.
DATA: BEGIN OF pdf OCCURS 0,
t(134),
END OF pdf.
DATA:
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.
* for Invoice Header Text
data:
lv_ID type THEAD-TDID value 'YEML',
lv_LANGUAGE type THEAD-TDSPRAS,
lv_NAME type THEAD-TDNAME,
lv_OBJECT type THEAD-TDOBJECT value 'VBBK',
lt_lines type table of tline,
ls_line type tline.
* For partner Email
constants:
lv_ITEM_NUMBER type VBUP-POSNR value '000000',
lv_PARTNER_ROLE type VBPA-PARVW value 'RE'.
data:
lv_DOCUMENT_NUMBER type VBUK-VBELN,
ls_vbpa type vbpa.
**** Main - Email ****
* Title and Description
document_data-obj_name = 'INVOICE'.
document_data-obj_descr = nast-objky.
* Text of Email
CONCATENATE 'Rechnung' nast-objky INTO object_txt
SEPARATED BY space.
APPEND object_txt.
lv_language = nast-spras.
lv_NAME = nast-objky.
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = lv_ID
LANGUAGE = lv_LANGUAGE
NAME = lv_NAME
OBJECT = lv_OBJECT
TABLES
LINES = lt_lines
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
ENDIF.
loop at lt_lines into ls_line.
append ls_line-TDLINE to object_txt.
endloop.
* 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'.
APPEND object_pack.
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
TABLES
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.
IF sy-subrc = 0.
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.
ELSE.
EXIT.
ENDIF.
* 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.
APPEND object_pack.
* generate the receiver list
lv_DOCUMENT_NUMBER = nast-objky.
* Get Partner RE Email
CALL FUNCTION 'SD_VBPA_SELECT'
EXPORTING
I_DOCUMENT_NUMBER = lv_DOCUMENT_NUMBER
I_ITEM_NUMBER = lv_ITEM_NUMBER
I_PARTNER_ROLE = lv_PARTNER_ROLE
IMPORTING
E_VBPA = ls_vbpa
EXCEPTIONS
PARTNER_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
* Internet User
clear receiver_list.
select single SMTP_ADDR from adr6 into receiver_list-receiver where
ADDRNUMBER = ls_vbpa-adrnr and FLGDEFAULT = 'X'.
if sy-subrc = 0 and not receiver_list-receiver is initial.
receiver_list-rec_type = 'U'.
receiver_list-com_type ='INT'.
APPEND receiver_list.
else.
receiver_list-receiver = 'SAPUSER@LOCALHOST'.
receiver_list-rec_type = 'U'.
receiver_list-com_type ='INT'.
APPEND receiver_list.
endif.
* Send the mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = document_data
* put_in_outbox = 'X' not really
commit_work = ' '
TABLES
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.
IF sy-subrc <> 0.
retcode = 1.
ENDIF.
ENDFORM. "PROCESSING
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Subroutinepool INVOICE EMAIL AS PDF ATTACHMENT *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
* WARNING : NO POPUPS - NO COMMIT WORK ALLOWED !!!!!!!!!!!!!!!!!!!!!!!!!
REPORT yfaktura_email.
DATA: retcode LIKE sy-subrc. "Returncode
DATA: xscreen(1) TYPE c. "Output on printer or screen
TABLES: nast, "Messages
tnapr. "Programs & Forms
*&---------------------------------------------------------------------*
*& Form ENTRY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RETURN_CODE text
* -->US_SCREEN text
*----------------------------------------------------------------------*
FORM entry USING return_code TYPE i
us_screen TYPE c.
FIELD-SYMBOLS: <f> TYPE itcpp,
<p> TYPE ssfcrescl.
DATA pgnam TYPE na_pgnam." Programname
DATA ronam TYPE na_ronam."Formname
DATA fm_name TYPE rs38l_fnam. "genr.Druckbaustein
DATA lv_vec(80).
DATA spoolid TYPE rspoid.
CLEAR retcode.
xscreen = us_screen.
* Call the "Original" Printroutine
* RVADIN01 = Sapscript
* RLB_INVOICE = Smartforms
*-Orig program------+
* |
*-Orig Form-+ |
* | |
PERFORM entry(rlb_invoice) USING return_code us_screen.
* Try Sapscript
ASSIGN ('(SAPLSTXC)ITCPP') TO <f>.
IF sy-subrc = 0 AND
NOT <f>-tdspoolid IS INITIAL AND
us_screen IS INITIAL.
PERFORM processing USING <f>-tdspoolid.
UNASSIGN <f>.
ELSE.
* Try Smartforms
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.
IF sy-subrc <> 0.
retcode = 1.
EXIT.
ENDIF.
SELECT SINGLE pname FROM tfdir INTO lv_vec
WHERE funcname = fm_name.
IF sy-subrc = 0.
CONCATENATE '(' lv_vec ')JOB_OUTPUT_INFO' INTO lv_vec.
ASSIGN (lv_vec) TO <p>.
IF sy-subrc = 0 AND
NOT <p>-spoolids[] IS INITIAL AND
us_screen IS INITIAL.
LOOP AT <p>-spoolids INTO spoolid.
PERFORM processing USING spoolid.
EXIT.
ENDLOOP.
UNASSIGN <p>.
ENDIF. " have Ids
ENDIF." tfdir entry
ENDIF." sapscript/smartforms
IF retcode NE 0.
return_code = 1.
ELSE.
return_code = 0.
ENDIF.
ENDFORM. "ENTRY
*&---------------------------------------------------------------------*
*& Form processing
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->SPOOLID text
*----------------------------------------------------------------------*
FORM processing USING spoolid TYPE itcpp-tdspoolid.
DATA numbytes TYPE i.
DATA lbuffer TYPE xstring.
DATA: BEGIN OF lt_pdf OCCURS 0,
t(134),
END OF lt_pdf.
* for Invoice Header Text
DATA:
lv_id TYPE thead-tdid VALUE 'YEML',
lv_language TYPE thead-tdspras,
lv_name TYPE thead-tdname,
lv_object TYPE thead-tdobject VALUE 'VBBK',
lt_lines TYPE TABLE OF tline,
ls_line TYPE tline.
* For partner Email
CONSTANTS:
lv_item_number TYPE vbup-posnr VALUE '000000',
lv_partner_role TYPE vbpa-parvw VALUE 'RE'.
DATA:
lv_document_number TYPE vbuk-vbeln,
ls_vbpa TYPE vbpa.
* For Email contents
DATA contents_hex TYPE solix_tab.
DATA lv_internetadr TYPE adr6-smtp_addr.
DATA lv_subject TYPE so_obj_des.
DATA lv_attname TYPE sood-objdes.
DATA send_request TYPE REF TO cl_bcs.
DATA text TYPE bcsy_text.
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.
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
TABLES
pdf = lt_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.
IF sy-subrc = 0.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = numbytes
IMPORTING
buffer = lbuffer
TABLES
binary_tab = lt_pdf
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lbuffer
TABLES
binary_tab = contents_hex[].
ENDIF.
TRY.
* create the send request
send_request = cl_bcs=>create_persistent( ).
* create the email body
lv_language = nast-spras.
lv_name = nast-objky.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = lv_id
language = lv_language
name = lv_name
object = lv_object
TABLES
lines = lt_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
ENDIF.
LOOP AT lt_lines INTO ls_line.
APPEND ls_line-tdline TO text.
ENDLOOP.
lv_document_number = nast-objky.
* Get Partner RE Email
CALL FUNCTION 'SD_VBPA_SELECT'
EXPORTING
i_document_number = lv_document_number
i_item_number = lv_item_number
i_partner_role = lv_partner_role
IMPORTING
e_vbpa = ls_vbpa
EXCEPTIONS
partner_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
CLEAR lv_internetadr.
SELECT SINGLE smtp_addr FROM adr6 INTO lv_internetadr WHERE
addrnumber = ls_vbpa-adrnr AND flgdefault = 'X'.
* Email subject
CONCATENATE 'Invoice:' nast-objky INTO lv_subject .
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_subject = lv_subject ).
* add list attachment to document
CONCATENATE nast-objky '.pdf' INTO lv_attname.
document->add_attachment( i_attachment_type = 'PDF'
i_attachment_subject = lv_attname
i_att_content_hex = contents_hex ).
*=============== Prep Send
* add document to send request
send_request->set_document( document ).
* create recipient and add to send request
IF lv_internetadr IS INITIAL.
recipient = cl_sapuser_bcs=>create( sy-uname ).
ELSE.
recipient = cl_cam_address_bcs=>create_internet_address( lv_internetadr ).
ENDIF.
send_request->add_recipient( i_recipient = recipient ).
* send
send_request->set_send_immediately( i_send_immediately = 'X' ).
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
IF sent_to_all = 'X'.
MESSAGE s022(so).
ENDIF.
CATCH cx_bcs INTO bcs_exception.
MESSAGE e865(so) WITH bcs_exception->error_type.
ENDTRY.
ENDFORM. "processing
Code: Alles auswählen.
:
:
* send
send_request->set_send_immediately( i_send_immediately = 'X' ).
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
IF sent_to_all = 'X'.
MESSAGE s022(so).
ENDIF.
CATCH cx_bcs INTO bcs_exception.
MESSAGE e865(so) WITH bcs_exception->error_type.
ENDTRY.
CLEAR:
document,
recipient,
send_request.
:
:
Code: Alles auswählen.
CLEAR:
document,
recipient,
send_request.
Code: Alles auswählen.
* create recipient and add to send request
* TEST TEST
recipient = cl_sapuser_bcs=>create( sy-uname ).
* IF lv_internetadr IS INITIAL.
* recipient = cl_sapuser_bcs=>create( sy-uname ).
* ELSE.
* recipient = cl_cam_address_bcs=>create_internet_address( lv_internetadr ).
* ENDIF.