- The number of components must match.
- The names of the components must match (except for the client column) and must be in the same order.
- The technical type properties predefined data type, length and number of decimal places must match for every component.
- The CDS view cannot have any input parameters.
- It is not possible to simultaneously have a replacement object defined and SAP buffering switched on for a database view with a changeable maintenance status.
- Use as a data source of a SELECT statement in Open SQL. This also applies to subqueries in any open SQL statement and to the statements OPEN CURSOR and FETCH. This bypasses any SAP buffering defined for the database table or the classic view.
- Checking a foreign key relationship for (Web) Dynpros.
- Writes in Open SQL
- Modifying writes in Open SQL
- Use of addition SINGLE FOR UPDATE in statement SELECT
- Writes like this produce a syntax check warning and are forbidden in strict mode from Release 7.50.
- Use in other database objects, such as:
- Use as a data source of a view defined on the database
- Access from database procedures or database functions
- Other access types than with Open SQL, for example:
- Access with IMPORT FROM DATABASE or EXPORT TO DATABASE.
- Access with Native SQL ( ADBC, AMDP, EXEC SQL)
No replacement objects can be defined for global temporary tables. In customer systems, replacement objects can only be defined for self-defined database views but not for database tables.
Notes
- You should be extremely careful when specifying a proxy object for a database table or a database view. Incorrect usage can cause inconsistencies.
- Replacement objects are mainly intended for existing aggregate tables. These are database tables, which contain aggregated data from other tables. Instead of aggregating data in an ABAP program and writing data to an aggregate table, which can be exclusively accessed by reads in programs, the aggregation can be performed for every read using the CDS view. This prevents redundant data from being stored. In addition, aggregation on the database can improve performance if it is necessary to read large volumes of data for aggregation in ABAP. Replacement objects can make this possible without invalidating the programs.
- The prerequisite for assigning a replacement object to an existing database table or database view is that the CDS view returns the expected data and that, apart from aggregation, only Open SQL reads are performed on the aggregate table.
- After the definition of a replacement object, no further writes should be performed on an aggregate table. These writes result in a warning from the syntax check and have been banned in the upcoming release.
- Make sure that apart from the use of Open SQL, no other type of access is performed on an aggregate table with a replacement object. The CDS view used as a replacement object in particular is not allowed to access the represented object, because the content is usually no longer updated.
- We do not recommend transporting table content for which a replacement object is defined. These contents are automatically no longer transported in the upcoming release.
- SAP buffering should be deactivated for an aggregate table for which a replacement object is defined, in order to prevent buffer invalidations.
- In customer systems, it may be useful to define a replacement object for a self-defined classic database view, if a replacement object has been defined for one of their basis tables at SAP. In this case, the replacement object of the view must access the replacement object of the basis table.
- The classic projection view, maintenance views and help views are not defined on the database. Access to their basis tables is carried out on AS ABAP by using Open SQL. If a basis table has a replacement object, its reads are redirected as required.
- Frameworks that use Open SQL, such as the Data Browser, automatically access replacement objects, if these objects are defined for a database table or a database view. Frameworks that use Native SQL, such as SADL, have to make sure that they access a replacement object rather than the database table or the database view.
- Wherever possible, any programs, which have been directly accessing aggregate tables or views with aggregate tables as basis tables, should be modified so that they directly access the CDS views that are used as replacement objects. However, this can usually not be done by simply replacing the data source in the relevant SELECT statements. This is because a client-specific CDS view does not have a client column and therefore the used target objects no longer match.
Replacement Object for Database Table
This example demonstrates a database table with a replacement object.
Source Code
REPORT demo_table_replacement_object.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
class_constructor,
main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA(out) = cl_demo_output=>new( ).
"Aggregate table (GTT)
SELECT FROM demo_sumdist_agg
FIELDS *
ORDER BY PRIMARY KEY
INTO TABLE @DATA(result_agg).
DELETE FROM demo_sumdist_agg.
"Table with replacement object
SELECT FROM demo_sumdist
FIELDS *
ORDER BY PRIMARY KEY
INTO TABLE @DATA(result).
ASSERT result = result_agg.
"Direct access to CDS view
SELECT FROM demo_cds_sumdist
FIELDS @sy-mandt AS mandt, demo_cds_sumdist~*
ORDER BY PRIMARY KEY
INTO TABLE @DATA(result_cds).
ASSERT result_cds = result.
out->write( result ).
"Classic view on demo_sumdist without replacement object
SELECT FROM demo_sumdist_obs
FIELDS *
ORDER BY PRIMARY KEY
INTO TABLE @DATA(result_view_obs).
IF result <> result_view_obs.
out->write(
'Classic view without replacement object differs.' ).
ENDIF.
"Classic view on demo_sumdist with replacement object
SELECT FROM demo_sumdistview
FIELDS *
ORDER BY PRIMARY KEY
INTO TABLE @DATA(result_view).
IF result = result_view.
out->write(
'Classic view with replacement object is the same.' ).
ENDIF.
out->display( ).
ENDMETHOD.
METHOD class_constructor.
DELETE FROM demo_sumdist_agg.
INSERT demo_sumdist_agg FROM
( SELECT
FROM scarr AS s
INNER JOIN spfli AS p ON s~carrid = p~carrid
FIELDS s~carrname,
p~distid,
SUM( p~distance ) AS sum_distance
GROUP BY s~mandt, s~carrname, p~distid ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
Description
This program accesses two database tables, DEMO_SUMDIST_AGG and DEMO_SUMDIST. These tables are identical except for the fact that the CDS view DEMO_CDS_SUMDIST is defined as a replacement object for DEMO_SUMDIST.
The database table DEMO_SUMDIST_AGG is filled with aggregated data (done here in the static constructor of the class demo). When DEMO_SUMDIST is accessed, the replacement object performs exactly the same aggregation:
@AbapCatalog.sqlViewName: 'DEMO_CDS_SUDI'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_sumdist
(client, carrname, distid, sum_distance)
as select from scarr as s
join spfli as p on s.carrid = p.carrid
{ key s.mandt,
key s.carrname,
key p.distid,
sum(p.distance) }
group by s.mandt, s.carrname, p.distid
Similar access to the database tables produce similar results, which can be verified using the statement ASSERT.
A third SELECT statement accesses the CDS view DEMO_CDS_SUMDIST directly. To produce the same results set for the comparison with the other results as when accessing the database tables, the client column must be added, since the results set of a client-specific CDS view does not contain a column of this type.
A classic database view DEMO_SUMDIST_OBS contains the database table DEMO_SUMDIST as a basis table. There is no redirect to the replacement object of DEMO_SUMDIST in a SELECT. A classic database view DEMO_SUMDISTVIEW that is otherwise similar has the following CDS view as a replacement object:
@AbapCatalog.sqlViewName: 'DEMO_CDS_SUDIV'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_sumdistview
as select from demo_cds_sumdist
{ key client,
key carrname,
key distid,
sum_distance }
This view accesses the replacement object of the database table DEMO_SUMDIST. When DEMO_SUMDISTVIEW is accessed using SELECT, its replacement object is evaluated and the result again matches the preceding result.
No comments:
Post a Comment