Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Converting to OTF and emailing

I am using the below code to convert a SAP output to OTF and then send in an email as an attachement. The email, works and the attachement is added but when I try to open the pdf attachement I get an error saying the file can not open or must be damaged. Other outputs work fine, I can't see what I am doing wrong?

CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
*      max_linewidth         = 132
    IMPORTING
      bin_filesize          = gv_binfilesize
    TABLES
      otf                   = gt_otf
      lines                 = gt_tline
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf           = 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.


  LOOP AT GT_TLINE.
    TRANSLATE GT_TLINE USING '~'.
    CONCATENATE GS_BUFFER GT_TLINE INTO GS_BUFFER.
  ENDLOOP.

  TRANSLATE GS_BUFFER USING '~'.

  DO.
    GT_RECORD = GS_BUFFER.
    APPEND GT_RECORD.
    SHIFT GS_BUFFER LEFT BY 255 PLACES.
    IF GS_BUFFER IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.

  REFRESH: GT_RECLIST,
           GT_OBJTXT,
           GT_OBJBIN,
           GT_OBJPACK.

  CLEAR GS_OBJHEAD.

  GT_OBJBIN[] = GT_RECORD[].

  DESCRIBE TABLE GT_OBJBIN LINES LV_LINES_BIN.

  gs_doc_chng-obj_name   = 'Test Order Confirmation'.
  gs_doc_chng-expiry_dat = sy-datum + 10 .


* email body
  CONCATENATE 'Please find your Order Confirmation for'
              'your reference (see attached)'
               INTO gt_objtxt SEPARATED BY space.
  APPEND gt_objtxt.

  DESCRIBE TABLE gt_objtxt LINES lv_lines_txt.

  gs_doc_chng-obj_descr  = 'Order Confirmation'.
  gs_doc_chng-sensitivty = 'F'.
  gs_doc_chng-doc_size   = lv_lines_txt * 255.

  CLEAR gt_objpack-transf_bin.

  gt_objpack-head_start = 1.
  gt_objpack-head_num   = 0.
  gt_objpack-body_start = 1.
  gt_objpack-body_num   = lv_lines_txt.
  gt_objpack-doc_type   = 'RAW'.
  APPEND gt_objpack.

  gt_objpack-transf_bin = 'X'.
  gt_objpack-head_start = 1.

  gt_objpack-head_num   = 1.
  gt_objpack-body_start = 1.
  gt_objpack-body_num   = lv_lines_bin.
  gt_objpack-doc_type   = 'PDF'.
  gt_objpack-obj_name   = 'Order'.
  gt_objpack-obj_descr  = 'Order.pdf'.
*  gt_objpack-doc_size   = lv_lines_bin * 255.
  gt_objpack-doc_size   =  ( lv_lines_bin - 1 ) *
                            255 + STRLEN( GT_OBJBIN ).
  APPEND gt_objpack.

  CLEAR gt_reclist.

  gt_reclist-receiver = lv_email.
  gt_reclist-express  = 'X'.
  gt_reclist-rec_type = 'U'.
  APPEND gt_reclist.


  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = gs_doc_chng
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = gt_objpack
      contents_bin               = gt_objbin
      object_header              = gs_objhead
      contents_txt               = gt_objtxt
      receivers                  = gt_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 NE 0.
    WRITE:/ 'Error When Sending the File', sy-subrc.
  ENDIF.

Edited by: showthousand on May 11, 2011 7:00 AM

Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question