Post

ABAP: Validate Email Addresses Using CL_BCS_EMAIL_ADDRESS

Learn how to validate email addresses in ABAP using CL_BCS_EMAIL_ADDRESS instead of writing custom regex, conforming to RFC 5322.

ABAP: Validate Email Addresses Using CL_BCS_EMAIL_ADDRESS

Don’t write custom regex for email validation — SAP provides a standard class that validates against RFC 5322.

Using cl_bcs_email_address=>validate()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
CLASS lcl_email DEFINITION CREATE PUBLIC.
  PUBLIC SECTION.
    CLASS-METHODS validate
      IMPORTING iv_email        TYPE string
      RETURNING VALUE(rv_valid) TYPE abap_boolean.
ENDCLASS.

CLASS lcl_email IMPLEMENTATION.
  METHOD validate.
    TRY.
        cl_bcs_email_address=>validate( iv_email ).
        rv_valid = abap_true.
      CATCH cx_address_exception.
        rv_valid = abap_false.
    ENDTRY.
  ENDMETHOD.
ENDCLASS.

Usage

1
2
3
4
5
IF lcl_email=>validate( 'user@example.com' ) = abap_true.
  " Valid email
ELSE.
  " Invalid email
ENDIF.

Test Cases

EmailResult
user@example.comValid
user.name+tag@domain.coValid
user@domainInvalid (no TLD)
@domain.comInvalid (no local part)
user@Invalid
plaintextInvalid

Why Use the Standard Class?

  • Implements RFC 5322 — the actual email standard
  • No maintenance — SAP keeps it up to date
  • Handles edge cases that custom regex often misses (quoted strings, internationalized domains)
  • Works in both on-premise and BTP ABAP Environment

One try-catch, one method call — clean and reliable.

This post is licensed under CC BY 4.0 by the author.