How to pass multiple mails in sap into a variable

In SAP, you can pass multiple emails into a variable using the following methods:

Method 1: Using a table

You can create a table with a structure that contains the email addresses and then pass the table to a variable.

For example, you can create a table EMAIL_ADDRESSES with the following structure:

TYPES: BEGIN OF ty_email,
         email TYPE string,
       END OF ty_email.

DATA: lt_email_addresses TYPE STANDARD TABLE OF ty_email.

Then, you can populate the table with multiple email addresses:

lt_email_addresses = VALUE #( ( email = '[email protected]' )
                              ( email = '[email protected]' )
                              ( email = '[email protected]' ) ).

Finally, you can pass the table to a variable:

DATA: lv_emails TYPE string.

LOOP AT lt_email_addresses INTO DATA(ls_email).
  lv_emails = lv_emails && ls_email-email && ', '.
ENDLOOP.

lv_emails = lv_emails && ''.

Method 2: Using a string

You can concatenate multiple email addresses into a single string using the && operator.

For example:

DATA: lv_emails TYPE string.

lv_emails = '[email protected], [email protected], [email protected]'.

Method 3: Using a function module

You can use a function module to concatenate multiple email addresses into a single string.

For example, you can create a function module Z_EMAIL_CONCATENATE with the following code:

FUNCTION Z_EMAIL_CONCATENATE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IV_EMAILS) TYPE  STRING
*"  EXPORTING
*"     VALUE(EV_EMAILS) TYPE  STRING
*"----------------------------------------------------------------------

  DATA: lv_emails TYPE string.

  lv_emails = iv_emails.

  LOOP AT iv_emails INTO DATA(ls_email).
    lv_emails = lv_emails && ls_email && ', '.
  ENDLOOP.

  ev_emails = lv_emails && ''.

ENDFUNCTION.

Then, you can call the function module and pass the email addresses as a string:

DATA: lv_emails TYPE string.

CALL FUNCTION 'Z_EMAIL_CONCATENATE'
  EXPORTING
    iv_emails = '[email protected], [email protected], [email protected]'
  IMPORTING
    ev_emails = lv_emails.

Note that in all cases, you need to ensure that the email addresses are properly formatted and separated by commas or other delimiters, depending on the requirements of your application.