How to send internal table in mail in sap abap

To send an internal table in an email from SAP ABAP, you can use the following steps:

  1. Create an internal table with the data you want to send.
  2. Convert the internal table to a string using the LOOP statement and the WRITE statement.
  3. Use the SAPgui function module to create a new email.
  4. Set the subject, recipient, and body of the email using the SAPgui function module.
  5. Use the SAPgui function module to send the email.

Here is an example code snippet that demonstrates how to send an internal table in an email:

REPORT zsend_internal_table_in_email.

DATA: it_data TYPE STANDARD TABLE OF ty_data,
      lv_string TYPE string.

TYPES: BEGIN OF ty_data,
         col1 TYPE c LENGTH 10,
         col2 TYPE c LENGTH 10,
       END OF ty_data.

" Populate the internal table
SELECT * FROM table_name INTO TABLE it_data.

" Convert the internal table to a string
LOOP AT it_data INTO DATA(ls_data).
  WRITE: / ls_data-col1, ls_data-col2.
ENDLOOP.

" Create a new email using SAPgui
CALL FUNCTION 'SAPgui'
  EXPORTING
    recipient      = '[email protected]'
    subject        = 'Internal Table in Email'
  IMPORTING
    email_id       = DATA(email_id)
  EXCEPTIONS
    error         = 1
    OTHERS        = 2.

" Set the body of the email
CALL FUNCTION 'SAPgui'
  EXPORTING
    email_id       = email_id
    body          = lv_string
  EXCEPTIONS
    error         = 1
    OTHERS        = 2.

" Send the email
CALL FUNCTION 'SAPgui'
  EXPORTING
    email_id       = email_id
  EXCEPTIONS
    error         = 1
    OTHERS        = 2.

In this example, we first create an internal table it_data and populate it with data from a database table. We then convert the internal table to a string using a LOOP statement and the WRITE statement.

Next, we use the SAPgui function module to create a new email with the subject "Internal Table in Email" and the recipient "[email protected]". We then set the body of the email using the SAPgui function module and the lv_string variable.

Finally, we use the SAPgui function module to send the email.

Note that the SAPgui function module is only available in SAP GUI transactions, and it is not available in SAP Web AS or SAP Cloud Platform. If you need to send emails from a non-GUI system, you will need to use a different approach, such as using the SMTPO function module or a third-party email library.