Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8623

Re: sending email issue

$
0
0

Hello Nagendra .

 

Please check my code.

 

 

 

 

FORM pdf_mail .

 

   DATA : wa_tline   LIKE LINE OF i_tline.

   DATA : wa_record  LIKE LINE OF i_record.

   DATA : wa_objtxt  LIKE LINE OF i_objtxt.

   DATA : wa_objpack LIKE LINE OF i_objpack.

   DATA : wa_objbin  LIKE LINE OF i_objbin.

   DATA : wa_reclist LIKE LINE OF i_reclist.

 

   i_otf[]  = w_return-otfdata[].

 

* Function Module CONVERT_OTF is used to convert the OTF format to PDF

 

   CALL FUNCTION 'CONVERT_OTF'

     EXPORTING

       format                = 'PDF'                   " Target format for LINES table

       max_linewidth         = 132                     " For ASCII format: Number of lines in LINES-TDLINE

     TABLES

       otf                   = i_otf[]                 " Input table with OTF format

       lines                 = i_tline                  " Output table with target format

     EXCEPTIONS

       err_max_linewidth     = 1

       err_format            = 2

       err_conv_not_possible = 3

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

 

 

   LOOP AT i_tline INTO wa_tline.

     TRANSLATE wa_tline USING '~'.

     CONCATENATE wa_buffer wa_tline INTO wa_buffer.

     MODIFY i_tline FROM

      wa_tline.

   ENDLOOP.

 

   TRANSLATE wa_buffer USING '~'.

 

   DO.

     wa_record = wa_buffer.

     APPEND wa_record TO i_record.

     SHIFT wa_buffer LEFT BY 255 PLACES.

 

     IF wa_buffer IS INITIAL.

       EXIT.

     ENDIF.

 

   ENDDO.

 

* Attachment

 

   REFRESHi_reclist,

             i_objtxt,

             i_objbin,

             i_objpack.

   CLEAR     wa_objhead.

 

   i_objbin[] = i_record[].

* Create Message Body Title and Description

   wa_objtxt = 'test with pdf-Attachment!'..

 

   APPEND wa_objtxt TO i_objtxt.

   DESCRIBE TABLE i_objtxt LINES v_lines_txt.

   READ TABLE i_objtxt INDEX v_lines_txt TRANSPORTING NO FIELDS.

 

* Title text and description of Smartform.

   wa_doc_chng-obj_name   = 'PACKING SLIP'.                    " Attachment name

   wa_doc_chng-expiry_dat = sy-datum + 10.                     " Attachment description

   wa_doc_chng-obj_descr  = 'PACKING SLIP'.                    " Attachment title

   wa_doc_chng-sensitivty = 'F'.                               " Sensitivity : Functional, can be forwarded functionally

   wa_doc_chng-doc_size   = v_lines_txt * 255.                 " Attachment

 

   CLEAR wa_objpack-transf_bin.

 

   wa_objpack-head_start   = 1.                                 " Start row of the table OBJECT_HEADER.

   wa_objpack-head_num     = 0.                                 " No. of rows in the table OBJECT_HEADER

   wa_objpack-body_start   = 1.                                 " Start row of the table on of which the object content is stored.

   wa_objpack-body_num     = v_lines_txt.                       " No. of rows of the table dependent.

   wa_objpack-doc_type     = 'RAW'.

 

   " Attachment type

   APPEND wa_objpack TO i_objpack.

* Attachment (pdf-Attachment)

 

   wa_objpack-transf_bin   = 'X'.                               " Object stored in binary format

   wa_objpack-head_start   = 1.                                 " Requires the start row of the table OBJECT_HEADER.

   wa_objpack-head_num     = 0.                                 " Requires the number of rows in the table OBJECT_HEADER

   wa_objpack-body_start   = 1.                                 " Requires the start row of the table dependent on the TRANSF_BIN.

   DESCRIBE TABLE i_objbin LINES v_lines_bin.

   READ TABLE i_objbin  INTO wa_objbin INDEX v_lines_bin.

 

   wa_objpack-doc_size     = v_lines_bin * 255 .                " Document size

   wa_objpack-body_num     = v_lines_bin.                       " Relevant rows arrangements

   wa_objpack-doc_type     = 'PDF'.                             " Document Type

   wa_objpack-obj_name     = 'Packing Slip'.                    " Document Name

   wa_objpack-obj_descr    = 'Packing Slip'.                    " Document Description

 

   APPEND wa_objpack TO i_objpack.

   CLEAR wa_reclist.

 

   wa_reclist-receiver     = 'shailendra.karada@niplindia.com'. " Reciver's email address

   wa_reclist-rec_type     = 'U'.

   APPEND wa_reclist TO i_reclist.

 

   CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

     EXPORTING

       document_data              = wa_doc_chng          " Document to be sent.

       put_in_outbox              = 'X'                  " Newly created document in outbox

       commit_work                = 'X'                  " Commit Work is sent at the end of the function module

     TABLES

       packing_list               = i_objpack            " Info about data in the tables

       object_header              = wa_objhead           " Summarized data dependent on each object type

       contents_bin               = i_objbin             " Summarized content of the objects

       contents_txt               = i_objtxt             " Summarized content of the objects identified as ASCII objects.

       receivers                  = i_reclist            " Receiver's Address

     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 <> 0.

     WRITE:/ 'Error When Sending the File', sy-subrc.

   ELSE.

     WRITE:/ 'Mail sent'.

   ENDIF.

ENDFORM.                    " PDF_MAIL


Viewing all articles
Browse latest Browse all 8623

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>