on 02-08-2014 8:01 PM
Having a bit of a weird problem I've created a form in SPF and I need to write a function module to create the form and email it. I've followed a few tutorials and my code works perfectly as an executable program but when I put it in a function module the pdf generation doesn't seem to be working. I get an error message when opening the pdf that says "Adobe reader could not open xxx.pdf because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)". The email itself isn't the issue because I get the same problem when just trying to generate the pdf and not email it.
My code is below. Any ideas?
FUNCTION Z__SEND_PDF.
data:
t_att_content_hex type SOLIX_TAB.
DATA: fm_name TYPE rs38l_fnam, " CHAR 30 0 Name of Function Module
fp_docparams TYPE sfpdocparams, " Structure SFPDOCPARAMS Short Description Form Parameters for Form Processing
FP_FORMOUTPUT TYPE FPFORMOUTPUT,
fp_outputparams TYPE sfpoutputparams. " Structure SFPOUTPUTPARAMS Short Description Form Processing Output Parameter
fp_outputparams-NODIALOG = 'X'.
fp_outputparams-GETPDF = 'X'.
* Sets the output parameters and opens the spool job
CALL FUNCTION 'FP_JOB_OPEN' "& Form Processing: Call Form
CHANGING
ie_outputparams = fp_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
* <error handling>
ENDIF.
*&---- Get the name of the generated function module
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME' "& Form Processing Generation
EXPORTING
i_name = 'ZPCAR_FORM_EXPAT'
IMPORTING
e_funcname = fm_name.
IF sy-subrc <> 0.
* <error handling>
ENDIF.
*-- Fetch the Data and store it in the Internal Table
* Language and country setting (here US as an example)
fp_docparams-langu = 'E'.
fp_docparams-country = 'US'.
*&--- Call the generated function module
CALL FUNCTION fm_name
EXPORTING
/1bcdwb/docparams = fp_docparams
STUFF = 'X'
IMPORTING
/1BCDWB/FORMOUTPUT = FP_FORMOUTPUT
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3.
IF sy-subrc <> 0.
* <error handling>
ENDIF.
*&---- Close the spool job
CALL FUNCTION 'FP_JOB_CLOSE'
* IMPORTING
* E_RESULT =
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* <error handling>
ENDIF.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = FP_FORMOUTPUT-pdf
* APPEND_TO_TABLE = ' '
* IMPORTING
* OUTPUT_LENGTH =
TABLES
BINARY_TAB = t_att_content_hex .
" CONVERT_PDF_BINARY
CLASS cl_bcs DEFINITION LOAD.
DATA:
lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
lo_send_request = cl_bcs=>create_persistent( ).
* Message body and subject
DATA:
lt_message_body TYPE bcsy_text VALUE IS INITIAL,
lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
APPEND 'Dear,' TO lt_message_body.
append ' ' to lt_message_body.
APPEND 'Please fill the attached form and send it back to us.'
TO lt_message_body.
append ' ' to lt_message_body.
APPEND 'Thank You,' TO lt_message_body.
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_message_body
i_subject = 'Personnel Information Form' ).
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 = 'Personnel Information Form'
* I_ATTACHMENT_SIZE =
* I_ATTACHMENT_LANGUAGE = SPACE
* I_ATT_CONTENT_TEXT =
* I_ATTACHMENT_HEADER =
i_att_content_hex = t_att_content_hex ).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
* Add attachment
* Pass the document to send request
lo_send_request->set_document( lo_document ).
* Create sender
DATA:
lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
l_send type ADR6-SMTP_ADDR value 'ADDRESS@GMAIL.COM'.
* lo_sender = cl_cam_address_bcs=>create_internet_address( l_send ).
lo_sender = cl_sapuser_bcs=>create( sy-uname ).
* Set sender
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
* Create recipient
DATA:
lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
* lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
lo_recipient = cl_cam_address_bcs=>create_internet_address( l_send ).
** Set recipient
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
* lo_send_request->add_recipient(
* EXPORTING
* i_recipient = lo_recipient
* i_express = 'X' ).
* Send email
DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).
COMMIT WORK.
message 'The Personnel Information form has been emailed to the Employee' type 'I'.
" MAIL_ATTACHMENT
ENDFUNCTION.
Found the answer thanks to: http://scn.sap.com/thread/1919745.
Hardcoding sy-cprog = fm_name fixed the issue. Hope this helps someone in the future.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.