Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

EMail

Former Member
0 Kudos

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

8 REPLIES 8

Former Member
0 Kudos

Hi Pavan,

Your requirement sounds strange.

But you can do it the other way.

While attaching the file to the email convert the file to PDF using FM CONVERT_OTF and then attach it to your email.

0 Kudos

Hi,

Yes my requirement is the same, i think i made mistake in keeping it on the forum.

Can you provide me with the code.

Thanks,

Pavan.

Former Member
0 Kudos

HI

THE FOLLOWING LINKS HAVE SAMPLE PROGRAMS THAT CAN BE <u>USED TO PRINT ANY SPOOL FROM SAP IN PDF FORMAT</u>.

<a href="http://www.sapgenie.com/abap/pdf_creation.htm">http://www.sapgenie.com/abap/pdf_creation.htm</a>

IF IT WORKS OUT FOR YOU PLEASE REWARD POINTS

REGARDS

ANOOP

0 Kudos

HI,

It is giving an error when i am using the FM convert_otf, that adobe reader cannot open the file.

Please help me out.

Thanks,

Pavan.

0 Kudos

Hi,

Can you check the sample protram LSTXWFCC...

CALL FUNCTION "CONVERT_OTF"
       EXPORTING    FORMAT                = "PDF"
       IMPORTING    BIN_FILESIZE          = FILE_LEN
       TABLES       OTF                   = OTFDATA
                    LINES                 = PDFDATA
       EXCEPTIONS   ERR_MAX_LINEWIDTH     = 1                   
                    ERR_FORMAT            = 2
                    ERR_CONV_NOT_POSSIBLE = 3
                    OTHERS                = 4.

0 Kudos

Hi,

Just try to download it to your system using gui_download before sending the mail using the so_new* function module.

If it is downloaded correctly in pdf,then you need to concentrate on the fm for sending mail.

0 Kudos

Crrect me if i am wrong.

Your new requirement is to take a doc or txt file from the local machine and convert it to PDF and email the PDF.

If this is correct,

option a) if loosing the format of the txt or doc file is OK, you could simple at runtime create a spool out of the contents of the file and use the spool with the FMs specified in other posts to convert to PDF

option b) if you want to convert the doc txt files, converted to PDF without loosing the original format, then you have to use some third party tool to convert to PDF before emailing.

Regards

Raja

Former Member
0 Kudos

Hi,

Chk out this link:

http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

They are using fn module :'CONVERT_ABAPSPOOLJOB_2_PDF'

Regards,

Gayathri