Skip to Content
0
Former Member
Oct 29, 2010 at 09:54 AM

Error in opening PDF.

19 Views

Hello Experts,

I have created one smartforms which containt some terms and condition which i want to send as a pdf to set of people. Now i am able to send the smartform as PDF . But when i am trying to open the PDF its shows me some error like 'PDF file is currupt'.

I search in SDN and try every option but i dont know where is my mistake . I am attaching my code , please have a look into it and suggest .

Thanks In Advance.

Satya

 



*&---------------------------------------------------------------------*
*& Report  Z_PDF_FORM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  Z_PDF_FORM.

"tables : YTCPG.
DATA: "it_otf TYPE STANDARD TABLE OF YTCPG,
it_docs TYPE STANDARD TABLE OF docs,
it_lines TYPE STANDARD TABLE OF tline,
st_job_output_info TYPE ssfcrescl,
st_document_output_info TYPE ssfcrespd,
st_job_output_options TYPE ssfcresop,
st_output_options TYPE ssfcompop,
st_control_parameters TYPE ssfctrlop,
v_len_in TYPE so_obj_len,
v_language TYPE sflangu VALUE 'E',
v_e_devtype TYPE rspoptype,
v_bin_filesize TYPE i,
v_name TYPE string,
v_path TYPE string,
v_fullpath TYPE string,
v_filter TYPE string,
v_uact TYPE i,
v_guiobj TYPE REF TO cl_gui_frontend_services,
v_filename TYPE string,
v_fm_name TYPE rs38l_fnam.

data: T_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,
w_doc_data type SODOCCHGI1,
ld_sender_address type SOEXTRECI1-RECEIVER,
ld_sender_address_type type SOEXTRECI1-ADR_TYP,
w_sent_all type SONV-FLAG,

t_packing_list like SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
t_attachment like SOLISTI1 OCCURS 0 WITH HEADER LINE,
it_message like SOLISTI1 OCCURS 0 WITH HEADER LINE.
*t_receivers like SOMLRECI1.

CONSTANTS c_formname TYPE tdsfname VALUE 'ZTEST'.
CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
  EXPORTING
    i_language    = v_language
    i_application = 'SAPDEFAULT'
  IMPORTING
    e_devtype     = v_e_devtype.
st_output_options-tdprinter = v_e_devtype.
*st_output_options-tdprinter = 'locl'.
st_control_parameters-no_dialog = 'X'.
st_control_parameters-getotf = 'X'.

**.................GET SMARTFORM FUNCTION MODULE NAME.................

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    formname           = 'Y_TC_PGOODS'
  IMPORTING
    fm_name            = v_fm_name
  EXCEPTIONS
    no_form            = 1
    no_function_module = 2
    OTHERS             = 3.
IF sy-subrc NE 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

**...........................CALL SMARTFORM............................

CALL FUNCTION v_fm_name
  EXPORTING
    control_parameters   = st_control_parameters
    output_options       = st_output_options
  IMPORTING
    document_output_info = st_document_output_info
    job_output_info      = st_job_output_info
    job_output_options   = st_job_output_options
  EXCEPTIONS
    formatting_error     = 1
    internal_error       = 2
    send_error           = 3
    user_canceled        = 4
    OTHERS               = 5.
IF sy-subrc NE 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
***.........................CONVERT TO OTF TO PDF.......................
  CALL FUNCTION 'CONVERT_OTF_2_PDF'
    IMPORTING
      bin_filesize           = v_bin_filesize
    TABLES
      otf                    = st_job_output_info-otfdata
      doctab_archive         = it_docs
      lines                  = it_lines
    EXCEPTIONS
      err_conv_not_possible  = 1
      err_otf_mc_noendmarker = 2
      OTHERS                 = 3.
  IF sy-subrc NE  0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

*2. Sending PDF as mail.

w_doc_data-obj_name  = 'MAIL_TO_HEAD'.
w_doc_data-obj_descr = 'Terms And Condition'.

t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num   = 1.
t_packing_list-body_start = 1.
t_packing_list-doc_type   = 'PDF'.
t_packing_list-obj_descr  = 'PDF Attachment'.
t_packing_list-obj_name   = 'PDF_ATTACHMENT'.
APPEND t_packing_list .
*CLEAR  w_packing_list.


CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = 'mailID.
t_receivers-rec_type = 'B'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
  EXPORTING
    document_data              = w_doc_data
    put_in_outbox              = 'X'
    sender_address             = ld_sender_address
    sender_address_type        = ld_sender_address_type
    commit_work                = 'X'
  IMPORTING
    sent_to_all                = w_sent_all
  TABLES
    packing_list               = t_packing_list
    contents_bin               = t_attachment
    contents_txt               = it_message
    receivers                  = t_receivers
  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 .
*  MESSAGE 'Mail has been Successfully Sent.' .
*ENDIF.

Edited by: satya pujahari on Oct 29, 2010 3:29 PM