Skip to Content
0
Jul 09 at 10:37 PM

Smartform as PDF attachment to mail - Error while opening PDF file

72 Views

I have created a Z program which call the smartform and send it as an PDF attachment to concerned persons. I am able to see the mail in SOST, but when I try to open the attachment it gives me error can't open file.



This is my code for converting SF to PDF

form smartform.
 data:fname type rs38l_fnam,
 wa_cparam type ssfctrlop,
 wa_output type ssfcompop.

 wa_cparam-preview = 'X'.
 wa_cparam-no_dialog = 'X'.
 wa_output-tddest = 'lp01'.
 "break-point.

 LW_CONTROL_PARAMETERS-GETOTF = 'X'.
*/.. To supress preview
 LW_CONTROL_PARAMETERS-NO_DIALOG = 'X'.
 LW_CONTROL_PARAMETERS-PREVIEW = 'X' .
 LW_CONTROL_PARAMETERS-LANGU = SY-LANGU .
 LW_OUTPUT_OPTIONS-TDNOPREV = 'X'.
 LW_OUTPUT_OPTIONS-TDNOPRINT = 'X'.
 LW_OUTPUT_OPTIONS-TDDEST = 'ZPRN'.
IF IT_EPKO-BUKRS EQ '3001'.
IF IT_EPKO-EBELN(2) EQ 43.

 call function 'SSF_FUNCTION_MODULE_NAME'
 exporting
 formname = 'ZMM_PO_FORM_CPY'
 importing
 fm_name = fm_name
 exceptions
 no_form = 1
 no_function_module = 2
 others = 3.
 if sy-subrc <> 0.
 message id sy-msgid type sy-msgty number sy-msgno

 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
 endif.

 if sy-subrc <> 0.
* Implement suitable error handling here
 endif.
 CALL FUNCTION FM_NAME "'/1BCDWB/SF00000184'
 EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
 CONTROL_PARAMETERS = LW_CONTROL_PARAMETERS
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
 OUTPUT_OPTIONS = LW_OUTPUT_OPTIONS
 USER_SETTINGS = 'X'
 PO_HEADER = PO_HEADER
 PO_FOOTER = PO_FOOTER
 PO_BOX_LOC = PO_BOX_LOC
 STREET = STREET
 HOUSE = HOUSE
 REMARK = REMARK
 C_CODE = C_CODE
 IMPORTING
* DOCUMENT_OUTPUT_INFO =
 JOB_OUTPUT_INFO = LW_SSFCRESCL
* JOB_OUTPUT_OPTIONS =
 TABLES
 IT_EPKO = IT_EPKO
 EXCEPTIONS
 FORMATTING_ERROR = 1
 INTERNAL_ERROR = 2
 SEND_ERROR = 3
 USER_CANCELED = 4
 OTHERS = 5
 .
 IF SY-SUBRC <> 0.
* Implement suitable error handling here
 ENDIF.

 PERFORM OTF_DATA.
FORM OTF_DATA .

 REFRESH LI_OTF[].
 LI_OTF[] = LW_SSFCRESCL-OTFDATA[].
 CLEAR : LV_BIN_FILESIZE.
 CALL FUNCTION 'CONVERT_OTF'
 EXPORTING
 FORMAT = GC_DOCTY_PDF
 IMPORTING
 BIN_FILESIZE = LV_BIN_FILESIZE
 TABLES
 OTF = LI_OTF
 LINES = LI_PDF_TAB
 EXCEPTIONS
 ERR_MAX_LINEWIDTH = 1
 ERR_FORMAT = 2
 ERR_CONV_NOT_POSSIBLE = 3
 ERR_BAD_OTF = 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.
 DESCRIBE TABLE LI_PDF_TAB LINES LV_PDFLINES.
 REFRESH LI_CONTENT_TXT.
 LOOP AT LI_OTF INTO LW_OTF.
 CLEAR LW_CONTENT.
 CONCATENATE LW_OTF-TDPRINTCOM LW_OTF-TDPRINTPAR
 INTO LW_CONTENT.
 APPEND LW_CONTENT TO LI_CONTENT_TXT.
 ENDLOOP.
 REFRESH : LI_CONTENT_HEX,
 LI_OBJHEAD.
 CLEAR : LV_TRANSFER_BIN,
 LV_LEN.

 CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
 EXPORTING
 FORMAT_SRC = 'OTF'
 FORMAT_DST = 'PDF'
 CHANGING
 TRANSFER_BIN = LV_TRANSFER_BIN
 CONTENT_TXT = LI_CONTENT_TXT
 CONTENT_BIN = LI_CONTENT_HEX
 OBJHEAD = LI_OBJHEAD
 LEN = LV_LEN
 EXCEPTIONS
 ERR_CONV_FAILED = 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.

Attachments

ekmaq.png (32.3 kB)