Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in sending the Smartform Output as PDF through Mail

Former Member
0 Kudos

Dear All,

I am sending the Smartform Output as an attachment by converting it into PDF. But when I am recieve this attachment I am unable to open the PDF file, it is giving error that FILE IS DAMAGED. Below is the code:


REPORT  Y_SEND_MAIL2.

TABLES: vbrk, vbrp.
TYPE-POOLS: abap.

DATA: it_vbrk TYPE TABLE OF vbrk WITH HEADER LINE.

DATA: i_formname      TYPE       tdsfname,
      i_fm_name       TYPE       rs38l_fnam,
      it_vbak TYPE TABLE OF vbak WITH HEADER LINE,
      it_ekko TYPE TABLE OF ekko WITH HEADER LINE.

DATA:  is_bil_invoice TYPE lbbil_invoice,
       output_options      TYPE ssfcompop,
       control_parameters  TYPE ssfctrlop,
       e_devtype           TYPE rspoptype,
       job_output_info     TYPE ssfcrescl,
       bin_file            TYPE xstring,
       lines               TYPE TABLE OF tline WITH HEADER LINE,
       doctab_archive      TYPE TABLE OF docs WITH HEADER LINE,
       filelength          TYPE i,
       bin_filesize        TYPE i,
       docs          TYPE TABLE OF docs WITH HEADER LINE.

*"Types
TYPES: t_document_data TYPE sodocchgi1,
       t_packing_list TYPE sopcklsti1,
       t_attachment TYPE solisti1,
       t_body_msg TYPE solisti1,
       t_receivers TYPE somlreci1,
       t_pdf TYPE tline.
*"Workareas
DATA :w_document_data TYPE t_document_data,
      w_packing_list TYPE t_packing_list,
      w_attachment TYPE t_attachment,
      w_body_msg TYPE t_body_msg,
      w_receivers TYPE t_receivers,
      w_pdf TYPE t_pdf.
*internal tables
DATA : i_document_data TYPE STANDARD TABLE OF t_document_data,
       i_packing_list TYPE STANDARD TABLE OF t_packing_list,
       i_attachment TYPE STANDARD TABLE OF t_attachment,
       i_body_msg TYPE STANDARD TABLE OF t_body_msg,
       i_receivers TYPE STANDARD TABLE OF t_receivers,
       i_pdf TYPE STANDARD TABLE OF t_pdf.


DATA: BEGIN OF line_bin,
         data(1024) TYPE x,
      END OF line_bin.
DATA: data_tab_bin LIKE STANDARD TABLE OF line_bin.

So please suggest a solution.

Regards,

Vishal

12 REPLIES 12

Former Member
0 Kudos

Continued:


SELECT-OPTIONS: s_vbeln FOR vbrk-vbeln,
                s_fkdat FOR vbrk-fkdat OBLIGATORY DEFAULT sy-datum.

SELECT * FROM vbrk
INTO TABLE it_vbrk
WHERE fkdat IN s_fkdat
      AND vbeln IN s_vbeln.

i_formname = 'Z_SD_JINDAL_INVOICE10'.

output_options-tddest        = 'LP02'.
output_options-tdimmed       = 'X'.
output_options-tdnewid       = 'X'.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    formname           = i_formname
  IMPORTING
    fm_name            = i_fm_name
  EXCEPTIONS
    no_form            = 1
    no_function_module = 2
    OTHERS             = 3.

IF sy-subrc <> 0.          "checking subrc
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.                     "IF sy-subrc <> 0

READ TABLE it_vbrk INDEX 1.
IF sy-subrc = 0.
  is_bil_invoice-hd_gen-bil_number = it_vbrk-vbeln.
ENDIF.

control_parameters-no_dialog = 'X'.
control_parameters-getotf = 'X'.

CALL FUNCTION i_fm_name        "'/1BCDWB/SF00000097'
  EXPORTING
   control_parameters         = control_parameters
   output_options             = output_options
   user_settings              = space
   is_bil_invoice             = is_bil_invoice
 IMPORTING
   job_output_info            = job_output_info
 TABLES
   it_vbak                    = it_vbak
 EXCEPTIONS
   formatting_error           = 1
   internal_error             = 2
   send_error                 = 3
   user_canceled              = 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.

*FORM convert_otf_2_pdf.
  CALL FUNCTION 'CONVERT_OTF_2_PDF'
*      EXPORTING
*        USE_OTF_MC_CMD               = 'X'
*        ARCHIVE_INDEX                =
    IMPORTING
      bin_filesize                 = bin_filesize
    TABLES
      otf                          = job_output_info-otfdata[]
      doctab_archive               = docs[]
      lines                        = lines[]
    EXCEPTIONS
      err_conv_not_possible        = 1
      err_otf_mc_noendmarker       = 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.
*ENDFORM.                    "convert_otf_2_pdf

0 Kudos

Continued 2:


DATA: lines_255 TYPE TABLE OF solisti1.
DATA: g_tab_lines TYPE i.

*then to send it as Email attachemnt we need to format the PDF data
CALL function 'SX_TABLE_LINE_WIDTH_CHANGE'
  exporting
*    LINE_WIDTH_SRC              = '134'
    line_width_dst              = '255'
  TABLES
    content_in                  = lines
    CONTENT_OUT                 = LINES_255
  exceptions
    ERR_LINE_WIDTH_SRC_TOO_LONG = 1
    err_line_width_dst_too_long = 2
    ERR_CONV_FAILED             = 3
    others                      = 4.

*LINES_255[] = LINES[].

*then put your mail details for example
*Subject of the mail.
*w_document_data-obj_name = 'MAIL_TO_HEAD'.
w_document_data-obj_name = 'ATTACHMENT'.
w_document_data-obj_descr = 'Billing Invoice'.
*Fill the document data and get size of attachment
w_document_data-obj_langu = sy-langu.
*Body of the mail
w_body_msg = 'Hello,'.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.

w_body_msg = ' '.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.

w_body_msg = 'Please find the attached file'.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.

w_body_msg = ' '.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.

w_body_msg = 'Regards,'.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.

*w_body_msg = sy-uname. APPEND w_body_msg TO i_body_msg. CLEAR w_body_msg.

*"Write Packing List for Body
CLEAR w_pdf. DESCRIBE TABLE i_body_msg LINES g_tab_lines.
READ TABLE lines_255 INTO w_pdf INDEX g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).
w_packing_list-head_start = 1.
w_packing_list-head_num = 0.
w_packing_list-body_start = 1.
w_packing_list-body_num = g_tab_lines
.
w_packing_list-doc_type = 'RAW'.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.

Vishal

0 Kudos

Continued 3:


*"Write Packing List for Attachment
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num = 1.
w_packing_list-body_start = 1.

DESCRIBE TABLE lines_255 LINES w_packing_list-body_num.
w_packing_list-doc_type = 'PDF'.
w_packing_list-obj_descr = 'PDF Attachment'.
w_packing_list-obj_name = 'LINES_255'.
w_packing_list-doc_size = w_packing_list-body_num * 255.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.

* receivers list.
* completing the recipient list for email

CLEAR w_receivers.
REFRESH:i_receivers.
w_receivers-receiver = 'mail_id'.
w_receivers-rec_type = 'U'.
w_receivers-notif_read = 'X'.
APPEND w_receivers TO i_receivers .
CLEAR:w_receivers.

break sddev.
* send the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data              = w_document_data
    put_in_outbox              = 'X'
    commit_work                = 'X'
  TABLES
    packing_list               = i_packing_list
    contents_bin               = lines_255
    contents_txt               = i_body_msg
    receivers                  = i_receivers
  EXCEPTIONS
    too_many_receivers         = 1
    document_not_sent          = 2
    operation_no_authorization = 4
    OTHERS                     = 99.
IF sy-subrc = 0.
  MESSAGE 'Error When Sending the File' TYPE 'I'.
ELSE.
  MESSAGE 'Email sent' TYPE 'I'.
ENDIF.
*END ADDED ON 30.03.2010

Please help.

Regards,

Vishal

0 Kudos

Dear All,

When I am downloading the PDF file on my computer, it is perfectly fine. So I think there is a problem in function module 'SO_NEW_DOCUMENT_ATT_SEND_API1'. Or it is also possible that I am creating document data, packing list etc. in a wrong manner.

Please suggest some solution.

Regards,

Vishal

0 Kudos

Dear All,

Please suggest some solution.

Regards,

Vishal

0 Kudos

Hi Vishal,

I think the code which defines packing i.e. the head and the body has some problem.

Also to be on the safer side, check the configuration in the TCode SCOT for SAPScript / Smartofrms under internet.

Regards,

Sagar

0 Kudos

Vishal, did you find what the problem was?

Thanks

0 Kudos

Hi,

Try using the function module SO_OBJECT_SEND instead of 'SO_NEW_DOCUMENT_ATT_SEND_API1'

Regards,

Soumya.

0 Kudos

Dear Sandra,

Earlier I was using this FM 'CONVERT_OTF_2_PDF'. Now I am using 'CONVERT_OTFSPOOLJOB_2_PDF'. Then problem is solved.

Regards,

Vishal

0 Kudos

Hi Vishal,

Could you please send the logic with detail manner.

Thanks you very much.

Venkat.

0 Kudos

Hi Venkat,

Sorry, I don't have the code with me now as this was long time back. You should be able find some help on Google / SCN portal. There are many similar posts.

Regards,

Vishal

0 Kudos

Hi Vishal,

Can you please post that code which you used for calling FM 'CONVERT_OTFSPOOLJOB_2_PDF'

thanks,

Snehal