‎2008 Aug 07 11:44 AM
hi experts
I have to give email support to my created form
please give me detail procedure
thanks
rohan
‎2008 Aug 07 3:17 PM
&----
*& Report Z_MAIL_PDF_SPOOL
&----
REPORT z_mail_pdf_spool.
PARAMETERS: jobname TYPE btcjob,
jobcount TYPE btcjobcnt,
mail_to TYPE ad_smtpadr
DEFAULT '<EMAIL>'.
DATA: ps_print_parameters TYPE pri_params,
local_job TYPE tbtcjob,
pdf TYPE TABLE OF tline,
lv_rqident TYPE tsp01-rqident,
numbytes TYPE i,
pdfspoolid LIKE tsp01-rqident,
ls_message_body TYPE soli,
gt_message_body TYPE bcsy_text,
gt_recipient TYPE rmps_recipient_bcs,
lo_recipient TYPE REF TO if_recipient_bcs,
job_head LIKE tbtcjob,
job TYPE TABLE OF tbtcstep WITH HEADER LINE,
lv_tabix LIKE sy-tabix.
CALL FUNCTION 'BP_JOB_READ'
EXPORTING
job_read_jobname = jobname
job_read_jobcount = jobcount
job_read_opcode = '20'
IMPORTING
job_read_jobhead = job_head
TABLES
job_read_steplist = job
EXCEPTIONS
job_doesnt_exist = 1
job_doesnt_have_steps = 2
OTHERS = 99.
DESCRIBE TABLE job LINES lv_tabix.
READ TABLE job INDEX lv_tabix.
lv_rqident = job-listident.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = lv_rqident
no_dialog = ' '
DST_DEVICE =
PDF_DESTINATION =
IMPORTING
pdf_bytecount = numbytes
pdf_spoolid = pdfspoolid
list_pagecount = lv_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
OTHERS = 12.
create recipient
lo_recipient =
cl_cam_address_bcs=>create_internet_address( mail_to ).
APPEND lo_recipient TO gt_recipient.
body email message
ls_message_body-line = 'ENJOY THIS GREAT PROGRAM'.
APPEND ls_message_body TO gt_message_body.
ls_message_body-line = ''.
APPEND ls_message_body TO gt_message_body.
ls_message_body-line = 'ENJOY THIS GREAT PROGRAM'.
APPEND ls_message_body TO gt_message_body.
CALL FUNCTION 'Z_MAIL_PDF'
EXPORTING
sender_user = sy-uname " user_name ls_message_subject = 'Your Are The Best' " subject mail
attach_subject = 'TEST' " name attach file
TABLES
i_otf_2 = pdf[]
gt_message_body = gt_message_body " body mail
gt_recipient = gt_recipient. " recipient
FUNCTION z_mail_pdf.
*"----
""Local Interface:
*" IMPORTING
*" REFERENCE(SENDER_USER) TYPE SY-UNAME DEFAULT SY-UNAME
*" REFERENCE(LS_MESSAGE_SUBJECT) TYPE SO_OBJ_DES
*" REFERENCE(ATTACH_SUBJECT) TYPE SO_OBJ_DES
*" TABLES
*" I_OTF_1 STRUCTURE ITCOO OPTIONAL
*" I_OTF_2 STRUCTURE TLINE OPTIONAL
*" GT_MESSAGE_BODY STRUCTURE SOLI
*" GT_RECIPIENT TYPE RMPS_RECIPIENT_BCS
*"----
Convert Otf / The file to be sent
IF i_otf_1[] IS NOT INITIAL.
PERFORM conv_otf_1 USING i_otf_1[]
CHANGING i_record[].
i_objbin[] = i_record[].
ELSE.
PERFORM conv_otf_2 USING i_otf_2[]
CHANGING i_objbin[].
ENDIF.
Create send request
PERFORM send_request.
Message body and subject
PERFORM body_subject USING ls_message_subject
gt_message_body[].
Add attachment
PERFORM attatch_pdf USING attach_subject.
Create & set sender
PERFORM create_sender USING sender_user.
Create recipients
PERFORM create_recipients USING gt_recipient[].
Send email
PERFORM send_email_now.
ENDFUNCTION.
&----
*& Form conv_otf_1
&----
FORM conv_otf_1 USING pt_otf TYPE gtyp_itcoo
CHANGING pt_record TYPE gtyp_record.
DATA: lt_tline TYPE TABLE OF tline,
v_len_in TYPE sood-objlen.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = v_len_in
TABLES
otf = pt_otf
lines = lt_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc <> 0.
error handling
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'QCE1_CONVERT'
TABLES
t_source_tab = lt_tline
t_target_tab = pt_record
EXCEPTIONS
convert_not_possible = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "conv_otf_1
&----
*& Form send_request
&----
FORM send_request .
lo_send_request = cl_bcs=>create_persistent( ).
ENDFORM. " send_request
&----
*& Form body_subject
&----
FORM body_subject USING
ps_message_subject TYPE so_obj_des
pt_message_body TYPE bcsy_text.
lo_document =
cl_document_bcs=>create_document( i_type = 'RAW'
i_text = pt_message_body
i_subject = ps_message_subject ).
ENDFORM. " body_subject
&----
*& Form attatch_pdf
&----
FORM attatch_pdf USING pv_attach_subject TYPE so_obj_des.
DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.
TRY.
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = pv_attach_subject
i_att_content_text = i_objbin ) .
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
Pass the document to send request
lo_send_request->set_document( lo_document ).
ENDFORM. " attatch_pdf
&----
*& Form create_sender
&----
FORM create_sender USING p_sender TYPE sy-uname.
lo_sender = cl_sapuser_bcs=>create( p_sender ).
Set sender
lo_send_request->set_sender( EXPORTING
i_sender = lo_sender ).
ENDFORM. " create_sender
&----
*& Form create_recipients
&----
FORM create_recipients USING pt_recipient TYPE rmps_recipient_bcs.
FIELD-SYMBOLS: <fs_recipient> TYPE REF TO if_recipient_bcs.
LOOP AT pt_recipient ASSIGNING <fs_recipient>.
Set recipient
lo_send_request->add_recipient( EXPORTING
i_recipient = <fs_recipient>
i_express = '' ).
ENDLOOP.
ENDFORM. " create_recipients
&----
*& Form send_email_now
&----
FORM send_email_now.
DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.
lo_send_request->set_send_immediately( 'X' ).
lo_send_request->set_status_attributes(
EXPORTING
i_requested_status = 'N'
i_status_mail = 'N' ).
lo_send_request->send(
EXPORTING
i_with_error_screen = ''
RECEIVING
result = lv_sent_to_all ).
COMMIT WORK .
ENDFORM. "send_email_now
&----
*& Form conv_otf_2
&----
FORM conv_otf_2 USING pt_otf TYPE tsftext
CHANGING pt_record TYPE soli_tab.
CALL FUNCTION 'QCE1_CONVERT'
TABLES
t_source_tab = pt_otf
t_target_tab = i_objbin
EXCEPTIONS
convert_not_possible = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " conv_otf_2
‎2008 Aug 19 6:28 AM