Skip to Content

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

How to Convert internal table data into text output and send mail in ABAP

Hi All,

Good Morning.

Taking a glance at a code that converts internal table data to an Excel file in ABAP. also checked how to send this excel to mailing list as attachment.

But thought of doing it without excel.

I mean, I have an internal table which contains fields of all types (character,integer,date,time). Since it is only around 4 to 5 rows in it (output),why to convert it to excel. not required!!.  Instead I  want to send this output to User's mails as Normal mail body with No attachments.

Could anybody please suggest me a way as to how to send internal table data as a mail ( not as an excel or PDF etc).

as of now my findings are, it is quite complex to convert internal table data to email (Text) format. but i believe if there is some way of doing it.

Best Regards

Dileep VT

Former Member
replied

here's something I have used in the past where we send out information about failed precalculation settings (which are stored in internal table gt_fail)

notice we use gt_text as "mail body"

TRY.

*     -------- create persistent send request ------------------------

       gv_send_request = cl_bcs=>create_persistent( ).

*     -------- create and set document -------------------------------

*     create text to be sent

       wa_line = text-001.

       APPEND wa_line TO gt_text.

       CLEAR wa_line.

       APPEND wa_line TO gt_text.

       LOOP AT gt_fail ASSIGNING <fs_fail>.

         MOVE <fs_fail>-retry_count TO gv_count.

         CONCATENATE text-002

                     <fs_fail>-setting_id

                     text-003

                     gv_count

                     INTO wa_line SEPARATED BY space.

         APPEND wa_line TO gt_text.

         CLEAR wa_line.

       ENDLOOP.

       APPEND wa_line TO gt_text.

       wa_line = text-007.

       APPEND wa_line TO gt_text.

*     create actual document

       gv_document = cl_document_bcs=>create_document(

                       i_type    = 'RAW'

                       i_text    = gt_text

                       i_length  = '12'

                       i_subject = 'Failed Precalculation Settings!' ).

*     add document to send request

       CALL METHOD gv_send_request->set_document( gv_document ).

*     --------- set sender -------------------------------------------

       gv_sender = cl_sapuser_bcs=>create( sy-uname ).

       CALL METHOD gv_send_request->set_sender

         EXPORTING

           i_sender = gv_sender.

*     --------- add recipient (e-mail address) -----------------------

       LOOP AT s_email INTO wa_email.

         MOVE wa_email-low TO gv_email.

         gv_recipient = cl_cam_address_bcs=>create_internet_address(

                                           gv_email ).

         CALL METHOD gv_send_request->add_recipient

           EXPORTING

             i_recipient = gv_recipient

             i_express   = 'X'.

       ENDLOOP.

*     ---------- set to send immediately -----------------------------

       CALL METHOD gv_send_request->set_send_immediately( 'X' ).

*     ---------- send document ---------------------------------------

       CALL METHOD gv_send_request->send(

         EXPORTING

           i_with_error_screen = 'X'

         RECEIVING

           result              = gv_sent_to_all ).

       IF gv_sent_to_all = 'X'.

         WRITE text-004.

       ENDIF.

       COMMIT WORK.

*   exception handling

     CATCH cx_bcs INTO gv_bcs_exception.

       WRITE: text-005.

       WRITE: text-006, gv_bcs_exception->error_type.

       EXIT.

   ENDTRY.


with the following declarations


* -------------------------------------------------------------------- *

* TABLES                                                               *

* -------------------------------------------------------------------- *

TABLES:

   adr6,

   rsr_prec_sett.

* -------------------------------------------------------------------- *

* INTERNAL TABLES & WORK AREAS                                         *

* -------------------------------------------------------------------- *

DATA:

   gt_fail          TYPE SORTED TABLE OF rsr_prec_sett

                         WITH UNIQUE KEY setting_id run_date,

   gt_text          TYPE bcsy_text,

   wa_fail          LIKE LINE OF gt_fail,

   wa_line(90)      TYPE c.

FIELD-SYMBOLS:

   <fs_fail>        LIKE LINE OF gt_fail.

* -------------------------------------------------------------------- *

* VARIABLES                                                            *

* -------------------------------------------------------------------- *

DATA:

   gv_count(4)      TYPE n,

   gv_send_request  TYPE REF TO cl_bcs,

   gv_document      TYPE REF TO cl_document_bcs,

   gv_sender        TYPE REF TO cl_sapuser_bcs,

   gv_recipient     TYPE REF TO if_recipient_bcs,

   gv_email         TYPE adr6-smtp_addr,

   gv_bcs_exception TYPE REF TO cx_bcs,

   gv_sent_to_all   TYPE os_boolean.

* -------------------------------------------------------------------- *

* SELECTION-SCREEN                                                     *

* -------------------------------------------------------------------- *

SELECT-OPTIONS:

   s_email          FOR adr6-smtp_addr NO INTERVALS MODIF ID sel.

DATA:

   wa_email         LIKE LINE OF s_email.

1 View this answer in context

Helpful Answer

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