cancel
Showing results for 
Search instead for 
Did you mean: 

Extension of attached pdf file in mail appears as .PDF.TXT

Former Member
0 Kudos

When I try to send email with attacment using function module SO_NEW_DOCUMENT_ATT_SEND_API1, I receive the pdf file with extension .PDF.TXT. for eg Filename.PDF.TXT

FORM CONVERT_OTF_TO_PDF USING LV_KUNNR TYPE KNA1-KUNNR.

DATA: LV_DESCRIPTION(30) TYPE C,

LV_ADRNR TYPE ADRC-ADDRNUMBER,

LV_EMAIL TYPE ADRC-EXTENSION2.

*-- If 'Send e-mail aatchment' read Spool Request Number.

IF P_EMAIL EQ 'X'.

*-- FM to convert the document from OTF to PDF format

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = ITCPP-TDSPOOLID

IMPORTING

PDF_BYTECOUNT = GV_BYTECOUNT

PDF_SPOOLID = GV_PDFSPOOLID

BTC_JOBNAME = GV_JOBNAME

BTC_JOBCOUNT = GV_JOBCOUNT

TABLES

PDF = GT_PDF

EXCEPTIONS

ERR_NO_OTF_SPOOLJOB = 1

ERR_NO_SPOOLJOB = 2

ERR_NO_PERMISSION = 3

ERR_CONV_NOT_POSSIBLE = 4

ERR_BAD_DSTDEVICE = 5

USER_CANCELLED = 6

ERR_SPOOLERROR = 7

ERR_TEMSEERROR = 8

ERR_BTCJOB_OPEN_FAILED = 9

ERR_BTCJOB_SUBMIT_FAILED = 10

ERR_BTCJOB_CLOSE_FAILED = 11

OTHERS = 12.

*-- FM to send the attachment via email.

IF SY-SUBRC IS INITIAL.

CLEAR GS_DOC_DATA.

*-- Title and Description

GS_DOC_DATA-OBJ_NAME = 'Forward contract'.

*-- Subject of the email

CONCATENATE 'Forward Contract:' BELEG-ZUONR INTO LV_DESCRIPTION.

GS_DOC_DATA-OBJ_DESCR = LV_DESCRIPTION.

GS_DOC_DATA-OBJ_PRIO = 1.

*-- Refresh binary object

CLEAR gt_objbin.

REFRESH gt_objbin.

CALL FUNCTION 'QCE1_CONVERT'

TABLES

T_SOURCE_TAB = GT_PDF

T_TARGET_TAB = GT_OBJBIN

EXCEPTIONS

CONVERT_NOT_POSSIBLE = 1

OTHERS = 2.

IF SY-SUBRC IS INITIAL.

DESCRIBE TABLE GT_OBJBIN LINES gv_lin1.

IF gv_lin1 GT 0.

GT_OBJTXT-line = 'THIS IS BODY OF THE EMAIL'.

APPEND GT_OBJTXT.

CLEAR GT_OBJTXT.

ENDIF.

  • DESCRIBE TABLE GT_OBJTXT LINES GV_TAB_LIN.

ENDIF.

*-- creation of the entry for the compressed document

DESCRIBE TABLE GT_OBJTXT LINES GV_TAB_LIN.

CLEAR gt_objpack.

gt_objpack-transf_bin = ' ' .

gt_objpack-head_start = 1.

gt_objpack-head_num = 0.

gt_objpack-body_start = 1.

gt_objpack-body_num = GV_TAB_LIN.

gt_objpack-doc_type = 'RAW'.

gt_objpack-doc_size = ( GV_TAB_LIN - 1 ) * 255 + STRLEN(

gt_objtxt ).

APPEND gt_objpack.

*-- creation of the entry for the attachment

DESCRIBE TABLE gt_objbin LINES GV_TAB_LIN.

CLEAR 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 = GV_TAB_LIN.

gt_objpack-doc_type = 'RAW'.

CONCATENATE BELEG-ZUONR '.PDF' INTO gt_objpack-obj_name.

gt_objpack-obj_descr = gt_objpack-obj_name.

gt_objpack-doc_size = ( GV_TAB_LIN - 1 ) * 255 + STRLEN(

gt_objbin ).

APPEND gt_objpack.

ENDIF.

  • READ TABLE objtxt INDEX gv_tab_lines.

DESCRIBE TABLE gt_objtxt LINES gv_tab_lin.

  • Calculating doc. size which is email

gs_doc_data-doc_size = ( GV_TAB_LIN - 1 ) * 255 + STRLEN( gt_objbin

).

*-- Read email address of the customer.

CLEAR LV_ADRNR.

SELECT SINGLE ADRNR FROM KNA1

INTO LV_ADRNR

WHERE KUNNR EQ LV_KUNNR.

SELECT SINGLE EXTENSION2 FROM ADRC

INTO LV_EMAIL

WHERE ADDRNUMBER EQ LV_ADRNR.

*-- Refresh receiver's list.

REFRESH GT_RECLIST.

*--Move email address to receiving list.

MOVE LV_EMAIL TO GT_RECLIST-RECEIVER.

GT_RECLIST-rec_type = 'U'.

GT_RECLIST-copy = ''.

GT_RECLIST-blind_copy = ''.

APPEND GT_RECLIST.

CLEAR GT_RECLIST.

*FM to send the email.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = GS_DOC_DATA

PUT_IN_OUTBOX = 'X'

TABLES

PACKING_LIST = GT_OBJPACK

CONTENTS_BIN = gt_objbin

CONTENTS_TXT = gt_objtxt

RECEIVERS = GT_RECLIST .

ENDIF.

ENDFORM. " CONVERT_OTF_TO_PDF

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Try this code..

DATA: int_objpack   LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
  DATA: int_objhead   LIKE solisti1 OCCURS 1 WITH HEADER LINE.
  DATA: int_objbin    LIKE soli OCCURS 10 WITH HEADER LINE.
  DATA: int_objtxt    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
  DATA: int_attachment LIKE soli OCCURS 0 WITH HEADER LINE.
  DATA: int_reclist   LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
  DATA: int_lines     LIKE tline OCCURS 0 WITH HEADER LINE.
  DATA: int_pdf      LIKE tline OCCURS 0 WITH HEADER LINE.
  DATA: doc_chng      LIKE sodocchgi1.
  DATA: tab_lines     LIKE sy-tabix.

  DATA : wa_reclist LIKE LINE OF int_reclist,
        wa_int_objhead LIKE LINE OF int_objhead,
        wa_int_objpack LIKE LINE OF int_objpack,
        wa_objtxt LIKE LINE OF int_objtxt,
        wa_objbin LIKE LINE OF int_objbin,
        wa_pdf LIKE LINE OF int_pdf.


  DATA: fs_output_options      TYPE ssfcompop,
        fs_control_parameters  TYPE ssfctrlop,
        fs_output_data         TYPE ssfcrescl,
        fs_devtype              TYPE rspoptype.

  DATA: wf_pdf_len TYPE i,
        wf_attachment_long TYPE string,
        wg_source(2) TYPE p,
        wg_255 TYPE i,
        wf_counter TYPE i.

  DATA: fm_name TYPE rs38l_fnam.


*--> Output options

  fs_output_options-tdprinter  = 'PDF1'.
  fs_output_options-xsf        = ''.        "XSF Output active
  fs_output_options-xsfcmode   = 'X'.       "Get XSF params from program
  fs_output_options-xdfcmode   = 'X'.
  fs_output_options-xdf        = space.
  fs_output_options-xsfcmode   = 'X'.
  fs_output_options-xdfcmode   = 'X'.

  fs_control_parameters-langu = 'E'.
  fs_control_parameters-no_dialog = 'X'.
  fs_control_parameters-getotf    = 'X'.



  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = 'ZMPETS_CHARGEBACK'
    IMPORTING
      fm_name            = fm_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.
  IF sy-subrc <> 0.
*   error handling
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.


**to get the smartform content***********

  CALL FUNCTION fm_name
    EXPORTING
      control_parameters = fs_control_parameters
      output_options     = fs_output_options
       IMPORTING
      job_output_info    = fs_output_data
    TABLES
      it_shiphdr         = int_shiphdr
    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.


*--> Convert to OTF format

  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
    IMPORTING
      bin_filesize          = wf_pdf_len
    TABLES
      otf                   = fs_output_data-otfdata
      lines                 = int_lines
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf           = 4
      OTHERS                = 5.
  IF sy-subrc <> 0.
    WRITE 'error_otf'.
  ENDIF.


  CLEAR: int_objpack, int_objhead,  int_objtxt, int_reclist.
  REFRESH: int_objpack, int_objtxt, int_reclist.

*--> Logic to conver the 132 into 255 character

  wg_source = '132'.
  wg_255 = '255'.

  int_pdf[] = int_lines[].

  LOOP AT int_pdf INTO wa_pdf.
    TRANSLATE wa_pdf USING ' ~' .
    CONCATENATE wf_attachment_long wa_pdf INTO wf_attachment_long.
  ENDLOOP.
  TRANSLATE wf_attachment_long USING '~ ' .
  CLEAR : wf_counter.

  DO.
    wf_counter = STRLEN( wf_attachment_long ).
    IF wf_counter GE 255.
      wa_objbin = wf_attachment_long(255).
      APPEND wa_objbin TO int_objbin.
      SHIFT wf_attachment_long BY 255 PLACES.
    ELSE.
      wa_objbin = wf_attachment_long(wf_counter).
      APPEND wa_objbin TO int_objbin.
      EXIT.
    ENDIF.
  ENDDO.

*--> Document to be sent

  doc_chng-obj_name = 'Report'.
  doc_chng-obj_descr = 'Charge Back Rate Details'.
  wa_objtxt = 'Charge Back Rate Details is attached in the mail as PDF'.
  APPEND wa_objtxt TO int_objtxt.

  DESCRIBE TABLE int_objtxt LINES tab_lines.
  READ TABLE int_objtxt INTO wa_objtxt INDEX tab_lines.

  CLEAR wa_int_objpack-transf_bin.
  wa_int_objpack-head_start = 1.
  wa_int_objpack-head_num   = 0.
  wa_int_objpack-body_start = 1.
  wa_int_objpack-body_num   = tab_lines.
  wa_int_objpack-doc_type   = 'RAW'.
  APPEND wa_int_objpack TO int_objpack.

  DESCRIBE TABLE int_objbin LINES tab_lines.

  wa_int_objhead = 'Charge Back Rate Details.pdf'.
  APPEND wa_int_objhead TO int_objhead.

*--> Creating the compressed attachment
  wa_int_objpack-transf_bin = 'X'.
  wa_int_objpack-head_start = 1.
  wa_int_objpack-head_num   = 1.
  wa_int_objpack-body_start = 1.
  wa_int_objpack-body_num   = tab_lines.
  wa_int_objpack-doc_type   = 'PDF'.
  wa_int_objpack-obj_name   = 'ATTACHMENT'.
  wa_int_objpack-obj_descr  = 'Just A Test' .
  wa_int_objpack-doc_size   = tab_lines * 255.
  APPEND wa_int_objpack TO int_objpack..


  CLEAR int_reclist.
  wa_reclist-receiver = 'a@xyz.com'.
  wa_reclist-express  = 'X'.
  wa_reclist-rec_type = 'U'.
  APPEND wa_reclist TO int_reclist.

* copy recipents
  CLEAR int_reclist.
  wa_reclist-receiver = 's@abc.com'.
  wa_reclist-express  = 'X'.
  wa_reclist-rec_type = 'U'.
  wa_reclist-copy     = 'X'.
  APPEND wa_reclist TO int_reclist.

*--> Sending the document
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = doc_chng
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = int_objpack
      object_header              = int_objhead
      contents_bin               = int_objbin
      contents_txt               = int_objtxt
      receivers                  = int_reclist
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      operation_no_authorization = 4
      OTHERS                     = 99.

COMMIT WORK.
SUBMIT rsconn01
       WITH mode = 'INT'
       WITH output = ' '
         AND RETURN.

Rgds,

Ajith

Reward pts if helpful/

Former Member
0 Kudos

Hi ,

i did not follow the code rightly but why are u using an explicit >PDF concatenation u achieve this by convert_OTf in which file type will be PDF...

so, try using this

DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,

i_tline TYPE TABLE OF tline WITH HEADER LINE,

i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,

i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

wa_objhead TYPE soli_tab,

w_ctrlop TYPE ssfctrlop,

w_compop TYPE ssfcompop,

w_return TYPE ssfcrescl,

wa_doc_chng typE sodocchgi1,

w_data TYPE sodocchgi1,

wa_buffer TYPE string,"To convert from 132 to 255

v_form_name TYPE rs38l_fnam,

v_len_in LIKE sood-objlen,

v_len_out LIKE sood-objlen,

v_len_outn TYPE i,

v_lines_txt TYPE i,

v_lines_bin TYPE i.

call function 'SSF_FUNCTION_MODULE_NAME'

exporting

formname = 'ZZZ_TEST1'

importing

fm_name = v_form_name

exceptions

no_form = 1

no_function_module = 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.

w_ctrlop-getotf = 'X'.

w_ctrlop-no_dialog = 'X'.

w_compop-tdnoprev = 'X'.

CALL FUNCTION v_form_name

EXPORTING

control_parameters = w_ctrlop

output_options = w_compop

user_settings = 'X'

IMPORTING

job_output_info = w_return

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.

i_otf[] = w_return-otfdata[].

call function 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = v_len_in

TABLES

otf = i_otf

lines = i_tline

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

others = 4.

if sy-subrc <> 0.

endif.

loop at i_tline.

translate i_tline using '~'.

concatenate wa_buffer i_tline into wa_buffer.

endloop.

translate wa_buffer using '~'.

do.

i_record = wa_buffer.

append i_record.

shift wa_buffer left by 255 places.

if wa_buffer is initial.

exit.

endif.

enddo.

  • Attachment

refresh:

i_reclist,

i_objtxt,

i_objbin,

i_objpack.

clear wa_objhead.

i_objbin[] = i_record[].

              • Create Message Body

        • Title and Description

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 = 'smartform'.

wa_doc_chng-expiry_dat = sy-datum + 10.

wa_doc_chng-obj_descr = 'smartform'.

wa_doc_chng-sensitivty = 'F'.

wa_doc_chng-doc_size = v_lines_txt * 255.

        • Main Text

  • wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + strlen( i_objtxt )

*.

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.

        • Attachment

  • (pdf-Attachment)

i_objpack-transf_bin = 'X'.

i_objpack-head_start = 1.

i_objpack-head_num = 0.

i_objpack-body_start = 1.

  • Länge des Attachment ermitteln

describe table i_objbin lines v_lines_bin.

read table i_objbin index v_lines_bin.

i_objpack-doc_size = v_lines_bin * 255 .

i_objpack-body_num = v_lines_bin.

i_objpack-doc_type = 'PDF'.

i_objpack-obj_name = 'smart'.

i_objpack-obj_descr = 'test'.

append i_objpack.

clear i_reclist.

i_reclist-receiver = give ur 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'

TABLES

packing_list = i_objpack

object_header = wa_objhead

CONTENTS_BIN = i_objbin

contents_txt = i_objtxt

receivers = i_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.