Extract the smtp email address

*
* Extract the smtp email address from the User Profile SU01 or
* Vendor Master LFA1
*
* Written by : SAP Basis, ABAP Programming and Other IMG Stuff
*              https://www.erpgreat.com
*
REPORT ZSMTPADR.

TABLES: USR21,
        LFA1,
        ADR6.

DATA: BEGIN OF WA,
         BNAME      TYPE USR21-BNAME,
         LIFNR      TYPE LFA1-LIFNR,
         ADRNR      TYPE LFA1-ADRNR,
         PERSNUMBER TYPE ADR6-PERSNUMBER,
         ADDRNUMBER TYPE ADR6-ADDRNUMBER,
         SMTP_ADDR  TYPE ADR6-SMTP_ADDR,
      END OF WA,
      ITAB LIKE SORTED TABLE OF WA
                 WITH NON-UNIQUE KEY BNAME LIFNR.

SELECT-OPTIONS: UNAME FOR USR21-BNAME.
SELECT-OPTIONS: LIFNR FOR LFA1-LIFNR.

IF UNAME-LOW <> SPACE.
   SELECT  U~BNAME U~PERSNUMBER U~ADDRNUMBER
           A~SMTP_ADDR
       INTO CORRESPONDING FIELDS OF TABLE ITAB
       FROM ( USR21 AS U
          INNER JOIN ADR6 AS A ON A~PERSNUMBER = U~PERSNUMBER
                              AND A~ADDRNUMBER = U~ADDRNUMBER )
       WHERE U~BNAME IN UNAME.

   LOOP AT ITAB INTO WA.
      WRITE:/ WA-BNAME, WA-SMTP_ADDR(50).
   ENDLOOP.
ENDIF.

IF LIFNR-LOW <> SPACE.
   SELECT  L~LIFNR L~ADRNR
           A~SMTP_ADDR
       INTO CORRESPONDING FIELDS OF TABLE ITAB
       FROM ( LFA1 AS L
          INNER JOIN ADR6 AS A ON A~ADDRNUMBER = L~ADRNR )
       WHERE L~LIFNR IN LIFNR.

    LOOP AT ITAB INTO WA.
       WRITE:/ WA-LIFNR, WA-SMTP_ADDR(50).
    ENDLOOP.
ENDIF.
*-- End of Program

See Also
Multiple Email Address For Single Vendor

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Main Index
SAP Basis, ABAP Programming and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.