Uderc programming article aggregator sites

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

Tags:
Answers: Have 5 answers
Advertisement
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
Advertisement
The best answer: 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.

Search

Related articles

PDF file created from Oracle Report is attached wrongly

PDF file created from Oracle Report is created wrongly using dbms_lob

I am unable to open PDF files created from another PGM.

Pdf file created in Word 2008 will not open in Acrobat 8.2.6 or any other Adobe program

Problem with PDF files created by Indesign

PDF files created in Preview won't open in Adobe Reader

How to use sdk to get the image in the pdf file created by illustrator?

Will Adobe Reader 11 read older PDF files created in Adobe Acrobat 8?

Why can't I open PDF files created in Adobe X using Adobe XI? How do I fix this?

Strange that I can save a pdf file created in windows 8.1 to my cloud storage

Recommended article

Main Front Panel Cluster reference in Sub VI

IP - end of the road? new product but there is a newer one? my goodness

Error installing premier elements 10 on mac pro

Help newbie here with Mac Airport Extreme

Many songs in my library appear to be duplicates. How did thta happen and what do I do?

At some point my Samsung galaxy3 phone would display 4G on it. For the last month or so it only displays 3G. IS this a known problem and are there any solutions?

Final Cut Pro_lipstick camera

Interest indicator & interest profile

Is it possible To Debug (trace) a Pro C program..in UNIX plattform..?

Gettting 0x800a139e - JavaScript runtime error: SecurityError on creating websocket object in .js page