on 02-28-2008 2:21 PM
Hi Experts!!!
How can we mail a pdf file via mail as an attachment?
Hi,
Check this code.
REPORT zsa_adob.
DATA: form TYPE fpwbformname,
fm_name TYPE rs38l_fnam,
interface_type TYPE fpinterfacetype.
DATA: fp_outputparams TYPE sfpoutputparams.
DATA : fp_docparams TYPE sfpdocparams,
fp_result TYPE fpformoutput,
wa_fpformoutput TYPE fpformoutput,
pdf TYPE fpformoutput-pdf,
pdf_data TYPE solix_tab,
attachment TYPE solix_tab,
lv_email TYPE adr6-smtp_addr.
DATA : bcs_exception TYPE REF TO cx_bcs.
DATA : bookings TYPE TABLE OF sbook .
SELECT * FROM sbook INTO TABLE bookings UP TO 5 ROWS WHERE
carrid = 'LH' .
ZSATEST is the adobe form designed in SFP tcode
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = 'ZSATEST'
IMPORTING
e_funcname = fm_name
e_interface_type = interface_type.
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = fp_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
fp_docparams-langu = 'E'.
CALL FUNCTION fm_name
EXPORTING
/1bcdwb/docparams = fp_docparams
booking = bookings
IMPORTING
/1bcdwb/formoutput = fp_result
EXCEPTIONS
USAGE_ERROR = 1
SYSTEM_ERROR = 2
INTERNAL_ERROR = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION fm_name
EXPORTING
/1bcdwb/docparams = fp_docparams
par1 = 'SR'
IMPORTING
/1bcdwb/formoutput = fp_result
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'FP_JOB_CLOSE'
IMPORTING
E_RESULT =
EXCEPTIONS
USAGE_ERROR = 1
SYSTEM_ERROR = 2
INTERNAL_ERROR = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
pdf = wa_fpformoutput-pdf.
pdf_data = cl_document_bcs=>xstring_to_solix( ip_xstring = pdf ).
attachment = pdf_data.
TRY.
DATA : l_subject TYPE so_obj_des,
l_mail_text TYPE bcsy_text,
l_mail_text_row TYPE soli.
l_subject = 'RFQ'.
CONCATENATE 'Please check the' ' Attached file' INTO l_mail_text_row.
APPEND l_mail_text_row TO l_mail_text.
DATA : document TYPE REF TO cl_document_bcs,
num_rows TYPE i,
text_length TYPE so_obj_len.
DESCRIBE TABLE l_mail_text LINES num_rows.
num_rows = num_rows * 255.
MOVE num_rows TO text_length.
TRY.
CALL METHOD cl_document_bcs=>create_document
EXPORTING
i_type = 'RAW'
i_subject = l_subject
i_length = text_length
I_LANGUAGE = SPACE
I_IMPORTANCE =
I_SENSITIVITY =
i_text = l_mail_text
I_HEX =
I_HEADER =
I_SENDER =
RECEIVING
result = document
.
CATCH cx_document_bcs .
ENDTRY.
DATA : attcdoctype TYPE soodk-objtp,
atttitle TYPE sood-objdes,
attsize TYPE sood-objlen,
pdftab TYPE solix_tab.
attcdoctype = 'pdf'.
atttitle = 'RFQ Details'.
attsize = XSTRLEN( pdf ).
*
pdftab = cl_document_bcs=>xstring_to_solix( ip_xstring = pdf ).
*
document->add_attachment( EXPORTING i_attachment_type = attcdoctype
i_attachment_subject = atttitle
i_attachment_size = attsize
i_attachment_language = sy-langu
i_att_content_hex = attachment ).
DATA : send_request TYPE REF TO cl_bcs.
send_request = cl_bcs=>create_persistent( ).
send_request->set_document( document ).
DATA : sender TYPE REF TO cl_sapuser_bcs.
sender = cl_sapuser_bcs=>create( 'SUSER' ).
TRY.
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
CATCH cx_send_req_bcs .
ENDTRY.
DATA : recipent TYPE REF TO if_recipient_bcs.
recipent = cl_cam_address_bcs=>create_internet_address( lv_email ).
send_request->add_recipient( EXPORTING i_recipient = recipent ).
send_request->set_send_immediately( 'X' ).
send_request->send( ).
COMMIT WORK.
WRITE : 'Email containing has been sent successfully'
.
CATCH cx_bcs INTO bcs_exception.
ENDTRY.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.