AS ABAP Release 758, ©Copyright 2024 SAP SE. All rights reserved.
ABAP - Keyword Documentation → ABAP - Dictionary (DDIC) → DDIC - Built-In Functions → DDIC - SQL Functions → DDIC - SQL Functions for Strings →DDIC - SQL Function UPPER
This example demonstrates the SQL function UPPER in ABAP SQL and ABAP CDS.
Source Code
* Public class definition
CLASS cl_demo_sql_upper DEFINITION
INHERITING FROM cl_demo_classrun
PUBLIC
CREATE PUBLIC.
PUBLIC SECTION.
METHODS main REDEFINITION.
ENDCLASS.
* Public class implementation
CLASS cl_demo_sql_upper IMPLEMENTATION.
METHOD main.
DATA:
query TYPE string VALUE `ERROR`,
rows TYPE i VALUE 100.
cl_demo_input=>new(
)->add_field( CHANGING field = query
)->request( CHANGING field = rows ).
query = `%` && to_upper( query ) && `%`.
IF rows < 1 OR rows > 1000.
out->write( 'Enter rows between 1 and 1000' ).
RETURN.
ENDIF.
"UPPER in CDS view entity
SELECT arbgb, msgnr, text
FROM demo_cds_upper_ve
WHERE sprsl = 'E' AND
upper_text LIKE @query
ORDER BY arbgb, msgnr, text
INTO TABLE @FINAL(result1)
UP TO @rows ROWS.
"UPPER in ABAP SQL
SELECT arbgb, msgnr, text
FROM t100
WHERE sprsl = 'E' AND
upper( text ) LIKE @query
ORDER BY arbgb, msgnr, text
INTO TABLE @FINAL(result2)
UP TO @rows ROWS.
ASSERT result1 = result2.
out->write( result1 ).
ENDMETHOD.
ENDCLASS.
Description
A SELECT statement accesses the following CDS view entity, which uses the SQL function UPPER:
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view entity DEMO_CDS_UPPER_VE
as select from t100
{
key sprsl,
key arbgb,
key msgnr,
text,
upper(text) as upper_text
}
Another SELECT statement uses the SQL function UPPER directly to access the same data source T100.
Since SQL functions cannot yet be used on the left side of LIKE in the DDL of ABAP CDS, the view returns a helper field, which is evaluated in ABAP SQL. The results are the same. The search effected by the examples is not case-sensitive.