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: 

Error in opening the PDF file created from the smart form output.

Former Member
0 Kudos

Hi All,

i have a simple smart form which takes 3 values like customer no, name and no of times customer called and gives an out like

Customer 0001000000 with name Ravi called 5 times today.

I have to send this output to mail as an attachment.

for this i am coding as below.

******Call the SSF Function module

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = Form name

VARIANT = ' '

DIRECT_CALL = ' '

IMPORTING

fm_name = lv_fmname

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3

lv_partner_number = '0001000000'.

lv_name_org1 = 'Ravi'.

lv_z_no_calls_day = '5'.

lw_ctrlop-getotf = 'X'.

lw_ctrlop-no_dialog = 'X'.

lw_compop-tdnoprev = 'X'.

lw_compop-tddest = 'LP01'.

*******Call the Form Function module and get the OTF of form output

CALL FUNCTION lv_fmname

EXPORTING

name_org1 = lv_name_org1

partner_number = lv_partner_number

z_no_calls_day = lv_z_no_calls_day

control_parameters = lw_ctrlop

output_options = lw_compop

user_settings = ' '

IMPORTING

job_output_info = w_return

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

i_otf] = w_return-otfdata[.

*********Now here if i look in to the OTF data i got in debug it has the data i aniticipated along with some other data.

the output is in the format

TDPRINTCOM(2) TDPRINTPAR(70)

ST XXXX.. customer 0001000000 with

name.....

i have my data in the above format spread in three lines of the output otf table where XXXX... is some number.

***********To convert to PDF Format

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = lv_len_in

  • BIN_FILE =

TABLES

otf = i_otf

lines = i_tline

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

err_bad_otf = 4

OTHERS = 5

.

*********For testing purpose i created a file on the desktop with the the data in i_tline. it created PDF file but when i tried to open it it's giving an error.

i_objtxt = 'test with pdf-Attachment!'.

APPEND i_objtxt.

DESCRIBE TABLE i_objtxt LINES v_lines_txt.

READ TABLE i_objtxt INDEX v_lines_txt.

wa_doc_chng-obj_name = 'Smart Form'.

wa_doc_chng-obj_descr = 'Frequent Caller Alert_Day'.

wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + STRLEN( i_objtxt ).

*********Creating the Entry for the document

CLEAR i_objpack-transf_bin.

i_objpack-head_start = 1.

i_objpack-head_num = 0.

i_objpack-body_start = 1.

i_objpack-body_num = v_lines_txt.

i_objpack-doc_type = 'RAW'.

APPEND i_objpack.

i_objbin] = i_tline[.

DESCRIBE TABLE i_objbin LINES v_lines_bin.

READ TABLE i_objbin INDEX v_lines_bin.

i_objhead = 'Frequentcaller list_Day.pdf'.

APPEND i_objhead.

************Creating the entry for the attachment.

CLEAR : i_objpack.

i_objpack-transf_bin = 'X'.

i_objpack-head_start = 1.

i_objpack-head_num = 1.

i_objpack-body_start = 1.

i_objpack-body_num = v_lines_bin.

i_objpack-doc_type = 'PDF'.

i_objpack-obj_name = 'ATTACHMENT'.

i_objpack-obj_descr = 'FCA'.

i_objpack-doc_size = v_lines_bin * 255 .

APPEND i_objpack.

CLEAR i_reclist.

i_reclist-receiver = 'mail id'.

i_reclist-rec_type = 'U'.

APPEND i_reclist.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = wa_doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = i_objpack

object_header = i_objhead

contents_bin = i_objbin

contents_txt = i_objtxt

receivers = i_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

This is all i am doing.

It is sending a mail with the attachment but we are not able to open the attachment. it's giving an error like file is damaged and couldn't be repaired.

I serched in the forum but i couldn't get the answer.

I suspect there is a problem in getting the OTF data..

Please help me in resolving this issue....

Thanks in advance.

RK

4 REPLIES 4

Former Member
0 Kudos

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

Make this to

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'BIN'

Should work

santhosh

former_member188685
Active Contributor
0 Kudos

Check the sample , and see where you made the mistake.

REPORT ZPDF_MAIl.
DATA:
  w_fm_name      TYPE rs38l_fnam,
  w_bin_filesize TYPE i,
  w_filesize     TYPE i,
  w_lines_txt    TYPE i,
  w_lines_bin    TYPE i.

DATA:
  wa_ctrlop   TYPE ssfctrlop,
  wa_outopt   TYPE ssfcompop,
  wa_objhead  TYPE soli_tab,
  wa_buffer   TYPE string,
  wa_doc_chng TYPE sodocchgi1.
DATA:
  BEGIN OF t_mail_ids OCCURS 0,
    mailid TYPE ad_smtpadr,
  END OF t_mail_ids,

  t_otfdata TYPE ssfcrescl,
  t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
  t_pdf_tab TYPE tline OCCURS 0 WITH HEADER LINE,
  t_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
  t_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
  t_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
  t_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
  t_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    formname           = 'Z195_TEST'
  IMPORTING
    fm_name            = w_fm_name
  EXCEPTIONS
    no_form            = 1
    no_function_module = 2
    OTHERS             = 3.
IF sy-subrc EQ 0.
ENDIF.                               " IF sy-subrc EQ 0.

wa_ctrlop-getotf = 'X'.
wa_ctrlop-no_dialog = 'X'.
wa_outopt-tdnoprev = 'X'.

CALL FUNCTION w_fm_name
  EXPORTING
    control_parameters = wa_ctrlop
    output_options     = wa_outopt
    user_settings      = 'X'
  IMPORTING
    job_output_info    = t_otfdata
  EXCEPTIONS
    formatting_error   = 1
    internal_error     = 2
    send_error         = 3
    user_canceled      = 4
    OTHERS             = 5.
IF sy-subrc EQ 0.
ENDIF.                               " IF sy-subrc EQ 0.

t_otf[] = t_otfdata-otfdata[].

CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
    format                = 'PDF'
    max_linewidth         = 132
  IMPORTING
    bin_filesize          = w_bin_filesize
  TABLES
    otf                   = t_otf
    lines                 = t_pdf_tab
  EXCEPTIONS
    err_max_linewidth     = 1
    err_format            = 2
    err_conv_not_possible = 3
    err_bad_otf           = 4
    OTHERS                = 5.
IF sy-subrc EQ 0.
ENDIF.                               " IF sy-subrc EQ 0.
LOOP AT t_pdf_tab.
  TRANSLATE t_pdf_tab USING '~'.
  CONCATENATE wa_buffer t_pdf_tab INTO wa_buffer.
ENDLOOP.
TRANSLATE wa_buffer USING '~'.
DO.
  t_record = wa_buffer.
  APPEND t_record.
  SHIFT wa_buffer LEFT BY 255 PLACES.
  IF wa_buffer IS INITIAL.
    EXIT.
  ENDIF.
ENDDO.

t_objtxt = ' To Change the COR, Use the Transaction ZCOR_CHANGE'.
APPEND t_objtxt.
t_objtxt = ' Check the Attached PDF file for COR'.
APPEND t_objtxt.

DESCRIBE TABLE t_objtxt LINES w_lines_txt.
READ TABLE t_objtxt INDEX w_lines_txt.

READ TABLE t_objtxt INDEX w_lines_txt.
wa_doc_chng-obj_name = 'COR Display'.
wa_doc_chng-expiry_dat = sy-datum + 10.

CONCATENATE 'COR' "w_cornr
            '-' "w_stat_descr w_action_desc
       INTO wa_doc_chng-obj_descr SEPARATED BY space.

wa_doc_chng-sensitivty = 'F'.
wa_doc_chng-doc_size =  w_lines_txt  * 255.
CLEAR t_objpack-transf_bin.
t_objpack-head_start = 1.
t_objpack-head_num = 0.
t_objpack-body_start = 1.
t_objpack-body_num = w_lines_txt.
t_objpack-doc_type = 'RAW'.
APPEND t_objpack.

t_objpack-transf_bin = 'X'.
t_objpack-head_start = 1.
t_objpack-head_start = 1.
t_objpack-head_num = 0.
t_objpack-body_start = 1.
DESCRIBE TABLE t_objbin LINES w_lines_bin.
READ TABLE t_objbin INDEX w_lines_bin.
t_objpack-doc_size = w_lines_bin * 255 .
t_objpack-body_num = w_lines_bin.
t_objpack-doc_type = 'PDF'.
t_objpack-obj_name = 'COR'.
t_objpack-obj_descr = 'COR Test'.
* concatenate 'COR' w_cornr into t_objpack-obj_descr
*                           separated by space.
APPEND t_objpack.

*LOOP AT t_mail_ids.
  CLEAR t_reclist.
  t_reclist-receiver = 'INTENATEMAIL'.
  t_reclist-rec_type = 'U'.
  APPEND t_reclist.
*ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data              = wa_doc_chng
    put_in_outbox              = 'X'
    commit_work                = 'X'
  TABLES
    packing_list               = t_objpack
    object_header              = wa_objhead
    contents_bin               = t_objbin
    contents_txt               = t_objtxt
    receivers                  = t_reclist
  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 EQ 0.
ENDIF.

former_member223537
Active Contributor
0 Kudos

HI,

Pass the Spool no. to the program RSTXPDFT4 and check whether the PDF is converted properly.

If yes, then you need to build the logic to convert the data received from PDF Conversion FM to 255 characters from 132 characters.

Refer the following link for more details:

[http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm]

Note 1089995 - No PDF document can be shown

Note 688161 - PDF certifict: The file is damaged and could not be repaired

Best regards,

Prashant

Former Member
0 Kudos

This is what i missed.

we have to decode the convereted PDF.

LOOP AT t_pdf_tab.

TRANSLATE t_pdf_tab USING '~'.

CONCATENATE wa_buffer t_pdf_tab INTO wa_buffer.

ENDLOOP.

TRANSLATE wa_buffer USING '~'.

DO.

t_record = wa_buffer.

APPEND t_record.

SHIFT wa_buffer LEFT BY 255 PLACES.

IF wa_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.