Skip to Content
0
Former Member
Feb 28, 2006 at 03:49 AM

EMail

26 Views

Hi All,

The below code it will send any file as attachment to external mail id, but as per new requirement i need like, if I attach .txt/doc file while downloading it has to convert the .txt/.doc file to PDF format.

Please help me out.

REPORT ZMAILSEND1.

DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA : filename TYPE string.

data : path type PCFILE-PATH.

data : extension(5) type c.

data : name(100) type c.

PARAMETERS : receiver TYPE somlreci1-receiver lower case.

PARAMETERS : p_file LIKE rlgrap-filename OBLIGATORY.

DATA: docdata LIKE sodocchgi1,

objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objhex LIKE solix OCCURS 10 WITH HEADER LINE,

reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.

DATA: tab_lines TYPE i,

doc_size TYPE i,

att_type LIKE soodk-objtp.

DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CLEAR p_file.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

file_name = p_file.

START-OF-SELECTION.

PERFORM file_attachment USING 'Tst' 'Attachment'.

PERFORM mail_receiver USING receiver 'U'.

PERFORM upload_file.

PERFORM put_data TABLES itab objbin.

PERFORM imported_object_prepare USING 'X' extension name.

PERFORM mail_send.

*----


SUBMIT rsconn01

WITH mode EQ 'INT'

AND RETURN.

if sy-subrc eq 0.

write : / 'Successfully sent to the recipient', receiver.

else.

write : / 'Not sent'.

endif.

&----


*& Form upload_file

&----


  • text

----


FORM upload_file.

filename = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = filename

FILETYPE = 'BIN'

TABLES

DATA_TAB = itab.

path = filename.

CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'

EXPORTING

COMPLETE_FILENAME = path

  • CHECK_DOS_FORMAT =

IMPORTING

  • DRIVE =

EXTENSION = extension

NAME = name

  • NAME_WITH_EXT =

  • PATH =

EXCEPTIONS

INVALID_DRIVE = 1

INVALID_EXTENSION = 2

INVALID_NAME = 3

INVALID_PATH = 4

OTHERS = 5

.

ENDFORM. "upload_file

&----


*& Form file_attachment

&----


  • text

----


  • -->OBJNAME text

  • -->OBJDESC text

----


FORM file_attachment USING objname objdesc.

clear docdata.

docdata-obj_name = objname.

docdata-obj_descr = objdesc.

ENDFORM. "file_attachment

&----


*& Form mail_receiver

&----


  • text

----


  • -->PRECEIVER text

  • -->PREC_TYPE text

----


FORM mail_receiver USING preceiver prec_type.

CLEAR reclist.

reclist-receiver = preceiver.

reclist-rec_type = prec_type.

APPEND reclist.

ENDFORM. "mail_receiver

&----


*& Form imported_object_prepare

&----


  • text

----


  • -->BYPASSMEMORY text

  • -->WHATATT_TYPE text

  • -->WHATNAME text

----


FORM imported_object_prepare USING bypassmemory whatatt_type whatname.

IF bypassmemory = ''.

*----


Fetch List From Memory

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = listobject

EXCEPTIONS

OTHERS = 1.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'LIST_FROM_MEMORY'.

ENDIF.

CALL FUNCTION 'TABLE_COMPRESS'

  • IMPORTING

  • COMPRESSED_SIZE =

TABLES

in = listobject

out = objbin

EXCEPTIONS

OTHERS = 1

.

IF sy-subrc <> 0.

MESSAGE ID '61' TYPE 'E' NUMBER '731'

WITH 'TABLE_COMPRESS'.

ENDIF.

ENDIF.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'TXT'.

APPEND objpack.

  • Packing Info Attachment

att_type = whatatt_type..

DESCRIBE TABLE objbin LINES tab_lines.

READ TABLE objbin INDEX tab_lines.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = whatname.

APPEND objpack.

ENDFORM. "imported_object_prepare

&----


*& Form mail_send

&----


  • text

----


FORM mail_send.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = 'X'

commit_work = 'X' "used from rel. 6.10

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • CONTENTS_HEX = objhex

  • 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

.

ENDFORM. "mail_send

&----


*& Form put_data

&----


  • text

----


  • -->TEXTLINES text

  • -->OUTBIN text

----


FORM put_data TABLES

textlines STRUCTURE tline

outbin STRUCTURE solisti1.

*----


Data

DATA : pos TYPE i.

DATA : len TYPE i.

LOOP AT textlines.

pos = 255 - len.

IF pos > 134.

pos = 134.

ENDIF.

outbin+len = textlines(pos).

len = len + pos.

IF len = 255. "length of out (contents_bin)

APPEND outbin.

CLEAR: outbin, len.

IF pos < 134.

outbin = textlines+pos.

len = 134 - pos.

ENDIF.

ENDIF.

ENDLOOP.

IF len > 0.

APPEND outbin.

ENDIF.

ENDFORM. "put_data

Thanks,

Pavan.

Message was edited by: Pavan Panduru

Message was edited by: Pavan Panduru