OTF to PDF to Email--Issues

Question:
Hi,
i am trying to send a PDF file created from an OTF file to external email. I have seen the links provided here but am still facing problems. when i am trying to open the PDF attachment, Eroor message' File is corrupted and cannot be opened comes. i am attachng my code below..
Could somebody please . pleeesssseeee help out and let me know what is the problem.
Here 'OTFDATA 'contains my OTF data file generated from SAPScript
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
* MAX_LINEWIDTH = 132
* ARCHIVE_INDEX = ' '
IMPORTING
BIN_FILESIZE = L_FILESIZE
TABLES
OTF = OTFDATA
LINES = T_LINES1
* EXCEPTIONS
* ERR_MAX_LINEWIDTH = 1
* ERR_FORMAT = 2
* ERR_CONV_NOT_POSSIBLE = 3
* OTHERS = 4
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
BIN_FILESIZE = L_FILESIZE
* CODEPAGE = ' '
* FILENAME = ' '
FILETYPE = 'BIN'
* ITEM = ' '
* MODE = ' '
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* FILEMASK_MASK = ' '
* FILEMASK_TEXT = ' '
* FILETYPE_NO_CHANGE = ' '
* FILEMASK_ALL = ' '
* FILETYPE_NO_SHOW = ' '
* SILENT = 'S'
* COL_SELECT = ' '
* COL_SELECTMASK = ' '
* NO_AUTH_CHECK = ' '
* IMPORTING
* ACT_FILENAME =
* ACT_FILETYPE =
* FILESIZE =
* CANCEL =
TABLES
DATA_TAB = T_LINES1
* FIELDNAMES =
* EXCEPTIONS
* INVALID_FILESIZE = 1
* INVALID_TABLE_WIDTH = 2
* INVALID_TYPE = 3
* NO_BATCH = 4
* UNKNOWN_ERROR = 5
* GUI_REFUSE_FILETRANSFER = 6
* CUSTOMER_ERROR = 7
* OTHERS = 8
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
append lines OF T_LINES1 TO i_pdf.
**************
loop at i_pdf.
translate i_pdf using ' ~'.
concatenate w_buffer i_pdf into w_buffer.
*w_buffer type string
endloop.
translate w_buffer using '~ '.
do.
i_contents_bin = w_buffer.
* i_contents_bin like solisti1 occurs 0 with header line,
append i_contents_bin.
shift w_buffer left by 255 places.
if w_buffer is initial.
exit.
endif.
enddo.
****
OBJTXT = 'The Unearned Discount Invoice report'.
APPEND OBJTXT.
OBJTXT = 'is included as attachment'.
APPEND OBJTXT.
DESCRIBE TABLE objtxt lines w_lines.
READ TABLE OBJTXT INDEX W_LINES.
DOC_CHNG-DOC_SIZE = ( W_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
* Creation of the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = W_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
* Prepare the attributes for the send API
describe table i_contents_bin lines w_lines.
OBJPACK-TRANSF_BIN = 'X'.
OBJHEAD = 'FILE100.PDF'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = W_LINES.
OBJPACK-DOC_TYPE = 'PDF'.
OBJPACK-obj_name = 'Message'.
OBJPACK-obj_descr = 'Email subject line'.
objpack-doc_size = w_lines * 255 .
APPEND OBJPACK.
***
CLEAR RECLIST.
RECLIST-RECEIVER = SY-UNAME. " replace with <login name>
RECLIST-REC_TYPE = 'B'.
RECLIST-EXPRESS = 'X'.
APPEND RECLIST.
CLEAR RECLIST.
RECLIST-RECEIVER = 'arvindsahu@yahoo.com'.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
CLEAR RECLIST.
*-----------------------------------------------------------------------
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X' "TO BE REMOVED
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = i_contents_bin
CONTENTS_TXT = OBJTXT
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = 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
.
CASE SY-SUBRC.
WHEN 0.
WRITE: / 'Result of the send process:'.
LOOP AT RECLIST.
WRITE: / RECLIST-RECEIVER(4, ':'.
IF RECLIST-RETRN_CODE = 0.
WRITE 'The document was sent'.
ELSE.
WRITE 'The document could not be sent'.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / 'No authorization for sending to the specified number'.
WRITE: 'of recipients'.
WHEN 2.
WRITE: / 'Document could not be sent to any recipient'.
WHEN 4.
WRITE: / 'No send authorization'.
WHEN OTHERS.
WRITE: / 'Error occurred while sending'.
ENDCASE.
ENDFORM. " CALL_FORM_EMAIL
Answer:
hi
1) Before using the open_form fm. Add the line as
ITCPO-TDGETOTF = 'X'. and include ITCPO as options.
2) when u use the Close_form. close usr otf data table in the
tables section.
regards,
venkat.
chennai.
_________________
Venkat.
Chennai.
Answer:
Is your SAP customised to accept PDF as an acceptable transmission format, if only RAW is is entered then PDF will never be sent properly. I think from memory the Transaction to check this is SCOT.
_________________
Hope this helps
Answer:
I am able to convert the SAPScript output from OTF to PDF . But when I am trying to convert the PDF to a format acceptable to the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1', parameter OBJBIN
and sending the output to an Internet email, the attachment shows up as a PDf file in the internet address. When i try to open the file, it gives the message that the file is damaged and cannot be opened.
Our SAP system is set up for sending PDF files also. Checked that out.
Please help me out and let me know .
Thanks
Answer:
I'm interested in hearing a solution to this problem...
Answer:
Have the same problem...
Using the standard conversion from OTF to PDF : everything works fine ... but including a pdf file does not even work in transactions SO01
Regards,
Ice
Answer:
I am able to send a text file to SAP Inbox and outside world but whenever I am attaching a PDF file I am unable to open it even in SO01
Has anyone done this before i.e. sent a PDF file as an attachment from SAP to SO01 and outsideworld ?
Thanks
Answer:
I am able to send a text file to SAP Inbox and outside world but whenever I am attaching a PDF file I am unable to open it even in SO01
Has anyone done this before i.e. sent a PDF file as an attachment from SAP to SO01 and outsideworld ?
Thanks
Answer:
The following code is an example that can send PDF to external mail, if you change the reciever type to a 'B', it will send to SAP mail (as long as the P_TO parameter is a valid user). The PDF file can be opened through external mail or SAP mail fine as long as everything is set up on your system. I believe this code has been posted previously.
Hello friends,
I have got the solution!! Thanks for your help...I had to use three function modules for doing this but got it at the end!!
Could you please let me know how u did this?????
I am having the exact problem.
I am on 46B and what FM I need to use and where???
Thnaks
Answer:
I too am facing problems getting a successful PDF attachment.
I want to send a PDF version of a SAP script output as an attachment.
I tried some of the code that I found on SAPFans,
but when I open the attachment received in MS Outlook,
I get the following error.
Adobe Reader could not open 'Attachment.PDF' because it is either not a
supported file type or because the file has been damaged.
The table SXFORMATG is blank, I am not sure if that is the problem.
When I download the data just before calling the send mail function
module, the pdf file is just fine....During debug too, sy-subrc is also
always zero....IT IS ONLY when I try opening the attachment, that
the above message is got.
Could someone please help?
DATA: BEGIN OF gt_pdf_output OCCURS 0.
        INCLUDE STRUCTURE tline.
DATA: END OF gt_pdf_output.
  g_spoolnr = '27891'.  "Take any already existing spool #
    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
      EXPORTING
        src_spoolid = g_spoolnr
      TABLES
        pdf         = gt_pdf_output.
* I found the following logic in one of the threads
    LOOP AT gt_pdf_output.
      STUFF+POS(134) = gt_pdf_output.
      ADD 134 TO POS.
    ENDLOOP.
    POS = 0.
    LEN = STRLEN( STUFF ).
    WHILE LEN > 0.
      SUBTRACT 255 FROM LEN.
      gs_contents_BIN = STUFF+POS(255).
      APPEND gs_contents_BIN to gt_contents_bin.
      ADD 255 TO POS.
    ENDWHILE.
  g_destn = 'C:\test.txt' .
  if p_dnld eq 'X'.
*  At this point, the downloaded version of PDF is just fine!
    CALL FUNCTION 'DOWNLOAD'
     EXPORTING
       FILENAME                      = g_destn
       FILETYPE                      = 'BIN'
     IMPORTING
       ACT_FILENAME                  = g_destn
      TABLES
        data_tab                      = gt_contents_bin
              .
    IF sy-subrc <> 0.
    ENDIF.
  endif.
*Fill document data
  gs_docdata-doc_size = 1.
  DESCRIBE TABLE gt_contents_bin LINES g_count.
*Fill packing list parameters
  gs_packing_list-transf_bin = 'X'.
  gs_packing_list-obj_descr = 'Sales data'.
  gs_packing_list-head_start = 1.
  gs_packing_list-head_num = 0.
  gs_packing_list-body_start = 1.
  gs_packing_list-body_num = g_count.
  gs_packing_list-doc_size = g_count * 255.
  gs_packing_list-doc_type = 'PDF'.
  APPEND gs_packing_list TO gt_packinglist.
  REFRESH: gt_receivers.
  CLEAR: gs_receivers.
  gs_receivers-receiver = p_email. "Parameter on sel. screen
  gs_receivers-rec_type = 'U'.
  gs_receivers-com_type = 'INT'.
  APPEND gs_receivers TO gt_receivers.
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data                    = gs_docdata
     PUT_IN_OUTBOX                    = 'X'
     COMMIT_WORK                      = 'X'
    tables
      packing_list                     = gt_packinglist
      CONTENTS_BIN                     = gt_contents_bin
      receivers                        = gt_receivers
            .
  IF sy-subrc <> 0.
  ENDIF.
Could some one pls help?

More Articles:

Standard SAP Reports?
Exit to Purchase Requisition before save.?
BAdI?
Transparent Tables for SQP Queries?
Function to Retrieve Error Message?
Printing of files from SAP alongwith printing SAPScript form?