ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - System Classes → 

CL_OSQL_REPLACE - Replacement Service

The system class CL_OSQL_REPLACE implements a replacement service that can be used to redirect access to data sources in Open SQL statements during the execution of unit tests ABAP Unit. The system class CL_OSQL_REPLACE can only be used in test classes by ABAP Unit.

Defining Replacement Rules

The static method ACTIVATE_REPLACEMENT of the system class CL_OSQL_REPLACE is used to define replacement rules.

The redirection can be to any database objects, in particular variants of the database tables or views defined in the ABAP Dictionary. The database objects that are redirected to must have the same structure as the object that is redirected from, otherwise the result is database specific and exceptions may arise.

A successful redirection applies for the entire execution of a module test until the internal session is ended or there is another redirection. A redirection is ended explicitly if an empty internal table is passed to the method ACTIVATE_REPLACEMENT.


Additional Methods

As well as the method ACTIVATE_REPLACEMENT, CL_OSQL_REPLACE has the following methods:

Restrictions and Special Features

Data Sources of Reads

The following applies to data sources of reads:

Targets of Writes

The same restrictions apply to the target of a write as to the data sources of reads, if applicable. In addition, targets of writes cannot be redirected to the following objects defined in the ABAP Dictionary:

Writes to a projection view cannot be redirected if the rows to be changed are defined by a work area or an internal table. Therefore, it is only possible to redirect accesses to the database table of a projection view if there are no writes to the view (except with the statements DELETE with a WHERE condition or UPDATE with the addition SET). Otherwise, a runtime error occurs.


See the program DEMO_CL_OSQL_REPLACE.

Execution of the module test should always be successful, regardless of the content of SCARR.