Full End To End Information On S/4 Hana Database
Full End To End Information On S/4 Hana Database
Full End To End Information On S/4 Hana Database
1. -> Architecture: S/4HANA uses a new, re-architected system design that is optimized for
in-memory computing and real-time data processing. ECC, on the other hand, uses a
traditional, row-based architecture that is optimized for transactional processing.
2. Database: S/4HANA uses the SAP HANA in-memory database, while ECC can be used
with a variety of traditional relational databases.
3. User interface: S/4HANA has a new, modern user interface that is designed to be more
intuitive and user-friendly than the interface in ECC.
4. Analytics and reporting: S/4HANA includes advanced analytics and reporting capabilities
that are built-in to the system, while ECC requires separate reporting tools to be
integrated.
5. Cloud deployment: S/4HANA is designed to be deployed in the cloud, while ECC is
typically deployed on-premises.
6. Simplification: S/4HANA has a simplified data model with less customizing and fewer
tables which means less maintenance and faster performance. ECC has a more complex
data model with more customizing and more tables which means more maintenance
and slower performance.
These are just a few of the major differences between S/4HANA and ECC, and there are
many more differences that can be found in the official SAP documentation. It's
important to note that S/4HANA is the latest version of SAP's ERP software and it brings
a lot of new features, improvements and simplifications.
One major difference between ECC and S/4HANA related to RAM in SAP is the way in
which memory is managed and utilized. Here are two key differences:
Column storage refers to storing data in a columnar format, where each column is
stored separately. This is different from row storage, where each row is stored
separately. Column storage is particularly useful for analytical workloads, where large
amounts of data need to be scanned quickly. This is because column storage allows for
efficient data compression and can reduce the amount of data that needs to be
scanned.
Row storage, on the other hand, is better suited for transactional workloads, where
individual rows need to be updated or inserted quickly. This is because row storage
allows for faster access to individual rows, as they are stored sequentially.
In SAP HANA, column storage is the default storage mode, as it is optimized for
analytical workloads. However, row storage can also be used in certain scenarios, such
as for tables with a small number of columns or when row-level updates are required.
Overall, the choice between column storage and row storage depends on the specific
can improve performance and optimize the use of resources.
ADT TOOLS :-
Note: To quality and production Only the File will be sent not the
CDS SQL view and CDS Entity. Once in the quality and Production
the activation takes place again the Run time objects will get
generate. Hence no HTC and delivery is required.
CDS Data Definition is also known as CDS Document or CDS
Source Code.
Code push down is a feature in CDS (Core Data Services) views in SAP HANA
that allows for filtering, aggregation, and calculation logic to be executed
within the database layer, rather than in the application layer. This results
in improved performance, as the amount of data that needs to be
transferred between the database and application is reduced. Code push
down can be achieved by using SQLScript or by using the HANA-optimized
CDS language syntax.
2) EXECUATION :-
IN CDS EXCUATION WILL BE HAPPENED UNDER DB LAYER.
IN DDIC VIEW EXEUACTION OF VIEW , QUERY OF VIEW , TAKES
CARE IN ABAP LAYER.
4) COMPLEXITY :-
CDS IS EASY TO LEARN AND UNDERSTAND.
DDIC VIEW IS NOT EASY TO LEARN AND UNDERSTAND.
5) OUTER JOIN :-
OUTER JOIN IS POSSIBLE IN CDS
OUTER JOIN IS NOT POSSIBLE IN DDIC VIEW.
6) COMPLEX EXPRESSION(CASE STATEMENT, REUSE FUCNTION) :-
COMPLEX EXPRESSION IS POSSIBLE IN CDS.
COMPLEX EXPRESSION IS NOT POSSIBLE IN DDIC VIEW.
7) ODATA CONNECTION :-
ODATA WE CAN CREATE WITH CDS DIRECTLY WITH SOME
ANNOTAION.
ODATA WE CAN’T CREATE WITH DDIC VIEWS.
8) TYPE DECLEARTION :-
WE CAN DECLEARE TYPE WITH CDS BECAUSE IT IS EXTESION OF
DDL.
WE CAN’T DECLEARE TYPE WITH DDIC TYPE.
9) METDATA :-
METADAT IS POSSIBLE WITH CDS.
METADAT IS NOT POSSIBLE WITH DDIC VIEW.
11) PARAMETER :-
CDS views are based on the Core Data Services (CDS) framework and are used to
define and consume semantically rich data models in SAP. DDIC views, on the
other hand, are based on the Data Dictionary (DDIC) and are used to define and
consume data models at the database level.
CDS views are used to define and consume semantically rich data models, while
DDIC views are used to define and consume data models at the database level.
CDS views support advanced features like associations, annotations, and
calculated fields, while DDIC views do not.
CDS views support the creation of reusable, composable data models, while DDIC
views do not.
CDS views can be consumed by various SAPUI5-based applications and tools,
such as SAP Fiori, while DDIC views can only be consumed by ABAP-based
applications and tools.
CDS views can be used to define and consume data models for both
transactional and analytical use cases, while DDIC views are mainly used for
transactional use cases.
CDS views can be exposed as OData services, while DDIC views cannot.
CDS views support filtering, sorting, and pagination, while DDIC views do not.
CDS views support multi-language support, while DDIC views do not.
CDS views support to create views based on HANA Calculation views, while DDIC
views do not.
VDM :-
Definition: VDM is a special annotation which used when we
create a view in S/4 HANA. (This annotation cannot be used in
ABAP on HANA etc.).
When we design CDS view in S/4, We need to follow best practice
(VDM Annotations).
VDM is an annotation which indicates that, What type of data is
exposed out of this CDS view (XL, L,S) (This will standardize the
code).
VDM stands for Virtual Data Model. It is a feature in SAP's Core Data
Services (CDS) that allows users to define and consume data models in
a simplified, abstracted way. VDM allows users to create views of data
from multiple underlying data sources and to expose these views as
entities, which can then be consumed in other parts of the system, such
as by ABAP programs or in the SAP HANA database.
1. Consuming VDM: This is used to define views of data from one or more
underlying data sources, such as database tables or other CDS views.
2. Providing VDM: This is used to expose a data model as a service,
making it available for consumption by other parts of the system.
Both types of VDM can be defined using the CDS modeling language,
which is similar to SQL.
"X" size: Indicates that a view is expected to be small in size and have simple
logic. This would be a good candidate for a small lookup table or simple data.
"S" size: Indicates that a view is expected to be medium-sized, with moderate
complexity. This would be a good candidate for reporting or other tasks that
require a moderate amount of data.
"XL" size: Indicates that a view is expected to be large in size and have complex
logic. This would be a good candidate for data intensive reporting, analytics or
data warehousing.
TYPES OF CDS VIEWS :-
Basic view
Composite view
Consumption view
PRIVATE VIEW
1) Basic View :-
VDM Basic views are created on the top of DDIC tables or views. It is
the only view that interacts directly with the database.
Annotation: @VDM.Viewtype : #BASIC
1. Basic views can directly access the database tables and other basic views.
2. They have an association with other basic views.
3. Free of redundancies.
4. They expose all business data.
2) Composite view
The composite view is created on top of the VDM Basic view. It interacts
with Basic views for the result set and does not interact with the
database directly.
Annotation: @VDM.Viewtype : #COMPOSITE
1. They can access other Composite views but not database tables.
2. They can have an association with other composite views and basic views.
3. Redundancies might be possible.
4. They should be reusable.
3) Consumption view :-
The consumption views are built on top of Interface views. By the name
Consumption, we can assume that this view is meant to be consumed
by SAP UI5 through OData, Analytical queries, Transactional service
models.
Annotation: @VDM.Viewtype : #CONSUMPTION.
}
where vbeln = '0000000005'
REPORT ZSR_CDS_VIEW_PROGRAM.
SELECT * FROM ZSRNORMAL INTO TABLE @DATA(LT).
WRITE : / LS-VBELN,
LS-AUART,
LS-ERDAT,
LS-ERNAM,
LS-ERZET.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Report zview_select_option
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZVIEW_SELECT_OPTION.
WRITE : / LS-MATNR,
LS-ERNAM,
LS-ERSDA,
LS-ERNAM,
LS-MATKL.
ENDLOOP.
@AbapCatalog.sqlViewName: 'ZPARAMM'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS PARAMETER'
define view ZSR_PARAMETER
with parameters FLIGHT_CODE : s_carr_id
as select from sflight
{
key carrid,
connid,
currency,
fldate,
seatsmax
}
*&---------------------------------------------------------------------*
*& Report zsr_cds_select_option
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSR_CDS_SELECT_OPTION.
START-OF-SELECTION.
CL_DEMO_OUTPUT=>DISPLAY_DATA(
EXPORTING
VALUE = LT
NAME = 'FLIGHT DETAILS'
).
Inner Join/Join
Left Outer Join
Right Outer Join
CROSS JOIN.
INNER JOIN :-
@AbapCatalog.sqlViewName: 'ZINNERJOIN'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'JOINS'
define view ZSR_INNER_JOINS_SAPCODES
as select from spfli as HD inner join sflight as IT
on HD.carrid = IT.carrid
{
key HD.carrid,
HD.airpto,
HD.connid,
HD.cityfrom,
IT.fldate,
IT.price,
IT.currency
}
CROSS JOIN :-
A cross join returns the Cartesian product of rows of the two joined data
sources. All entries on the left side are combined with all entries on the
right side. The number of rows in the result set is the number of rows on
the left side multiplied by the number of rows on the right side.
@AbapCatalog.sqlViewName: 'ZCROSSJOIN'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'JOIN'
define view ZSR_CROSS_JOIN as select from sflight as SF
cross join scarr as SR
{
key SF.carrid,
SF.currency,
SF.fldate,
SR.carrname,
SR.currcode
}
where SF.carrid = 'AA'
Disadvantages of Joins:
1. Whether we need the data at the end for joined table or not, the join
is always be performed, which is a cost to database.
2. When we build on odata service on such view, The service will
expose all the data always, whether u need or not. High network
Traffic.
3. Writing joins is to technical from developer point of view. So, to
overcome these disadvantages, cds views have something called
associations.
CASE STATEMENTS :-
@AbapCatalog.sqlViewName: 'ZCASEST'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CASE STATMENT'
define view ZSR_CASE_STATMENT as select from spfli
{
key spfli.carrid,
spfli.cityfrom,
spfli.countryfr,
spfli.countryto,
case
when distance >=10000 then 'LONG WAY JOURNEY'
when distance >=5000 and distance <=10000 then 'SHORT WAY JOURNEY'
else 'NO LONGER JOURNEY'
end as JOURNEY_TYPE
}
-----------------------------------------------------------------------------
@AbapCatalog.sqlViewName: 'ZCASE2'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CASE STATMENT'
define view ZSR_CASE_STATMENT4 as select from marc
{
key marc.matnr,
marc.matgr,
marc.ausdt,
case
when plifz >=10 then 'GREATER'
when plifz <10 then 'SMALLER'
else 'NOTHING'
end as Planned
}
@AbapCatalog.sqlViewName: 'ZCASE5'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CASE STATMENT'
define view ZSR_CASE_STATMENT5 as select from vbrp
{
key vbrp.vbeln,
vbrp.ernam,
vbrp.erdat,
vbrp.posnr,
case
when netwr>=300 then 'HIGH NET WEIGHT'
when netwr<=100 then 'MIDDLE NET WEIGHT'
else 'SMALL NET WORTH'
end as NET_WEIGHT
}
where vbeln = '0090016826'
Aggregate expression in CDS View :-
Aggregate Functions:
FIRST IT WILL GROUP ALL SAME DATA LATER IT WILL ADD SAME
FIELD DATA ALL.( IF CARRID ARE 4 FIELDS WITH SAME VALUES THAT
TIME IT WILL ADD SAME VALUES FROM THE 4 FIELDS).
@AbapCatalog.sqlViewName: 'ZAGGREGATE_FUN'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'AGGREGTE FUNCTION'
define view ZSR_AGGREGATE_FUN_SUM as select from sflight as A
{
key A.carrid,
key A.connid,
sum(price) as TOTAL_AMT,
A.currency
}
group by carrid, connid, currency
-------------------------------------------------------------------------
@AbapCatalog.sqlViewName: 'ZAGGREGATE2'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'AGGREGTE FUNCTION'
define view ZSR_AGGREGATE_FUN_SUM1 as select from vbrp as M
{
key M.vbeln,
M.posnr,
M.erdat,
M.ernam,
sum(netwr) as AMT
}
group by vbeln, posnr, erdat, ername
@AbapCatalog.sqlViewName: 'ZSRAGGR_COUNT'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'AGGREGTE FUNCTION'
define view ZSR_AGGREGATE_FUN_COUNT as select from sflight as A
{
key A.carrid,
A.connid,
sum(price) as MONEY,
A.currency,
count(*) as LINES
}
group by carrid, connid, currency
@AbapCatalog.sqlViewName: 'ZSRAGGRCOUNT'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'AGGREGTE FUNCTION'
define view ZSR_AGGREGATE_FUN_COUNT1 with parameters P_WERKS: werks_d as select from
mard
{
key mard.werks,
mard.ersda,
mard.lgort,
count( *) as LINES
}
where werks = $parameters.P_WERKS group by matnr, werks, ersda, lgort
@AbapCatalog.sqlViewName: 'ZSRAGGRMAXMIMUM'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'AGGREGTE FUNCTION'
define view ZSR_AGGREGATE_FUN_MAX as select from sflight
{
key sflight.carrid,
key sflight.connid,
max(price) as MAXIMUM,
sflight.currency
}
group by carrid, connid, currency
@AbapCatalog.sqlViewName: 'ZSRAGGRMAXMIMUM'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'AGGREGTE FUNCTION'
define view ZSR_AGGREGATE_FUN_MAX as select from sflight
{
key sflight.carrid,
key sflight.connid,
min(price) as MANIMUM,
sflight.currency
}
group by carrid, connid, currency
AVERGE WILL WORK LIKE FIRST IT WILL ADD THE DATA OF SAME
FIELDS LATER IT WILL DO AVERGE.
@AbapCatalog.sqlViewName: 'ZAGGRAVG'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'AGGREGET FUNCTION'
define view ZSR_AGGREGATE_FUN_AVERGE as select from sflight as S
{
key S.carrid,
key S.connid,
sum( price ) as PRICE,
avg( paymentsum ) as PAYMENT,
count( *) as LINES
}
group by carrid, connid
--------------------------------------------------------------------------------
@AbapCatalog.sqlViewName: 'ZAGGRAVG'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'AGGREGET FUNCTION'
define view ZSR_AGGREGATE_FUN_AVERGE as select from sflight as S
{
// AVERGE //
key S.carrid,
key S.connid,
sum( price ) as PRICE,
avg( paymentsum ) as PAYMENT,
// AFTER AVERGE AGAIN MULTIPLED BY 2//
paymentsum * 2 as MULTI_PAYMENT,
count( *) as LINES
}
group by carrid, connid , paymentsum
@AbapCatalog.sqlViewName: 'ZAVG'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'AGGREGET FUNCTION'
define view ZSR_AGGREGATE_FUN_AVERGE1 as select from vbrp as V
{
key V.vbeln,
V.posar,
sum( netwr ) as NET_WEIGHT,
count (*) as counting,
avg( netwr ) as net
}
group by vbeln, posar
SUBSTRACTION :-
@AbapCatalog.sqlViewName: 'ZSRAIRTHMATIC'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'AIRTHMATIC_OPERATION'
define view ZSR_AIRTHMATIC_OPERATION as select from sflight as S
{
// SUBSTRACTION //
key S.carrid,
key S.connid,
S.fldate,
S.price,
S.currency,
S.seatsmax - S.seatsocc as SEATS_IN_ECONMIC_CLASS,
S.seatsmax_b - S.seatsocc_b as SEATS_IN_BUSINESS_CLASS,
S.seatsmax_f - S.seatsocc_f as SEATS_IN_FIRST_CLASS
}
ADDITION :-
// ADDIATION //
key S.carrid,
key S.connid,
S.fldate,
S.price,
S.currency,
S.seatsmax + S.seatsocc as SEATS_IN_ECONMIC_CLASS,
S.seatsmax_b + S.seatsocc_b as SEATS_IN_BUSINESS_CLASS,
S.seatsmax_f + S.seatsocc_f as SEATS_IN_FIRST_CLASS
MULTIPLICATION :-
// MULTIPLICATION //
key S.carrid,
key S.connid,
S.fldate,
S.price,
S.currency,
S.seatsmax * S.seatsocc as SEATS_IN_ECONMIC_CLASS,
S.seatsmax_b * S.seatsocc_b as SEATS_IN_BUSINESS_CLASS,
S.seatsmax_f * S.seatsocc_f as SEATS_IN_FIRST_CLASS
DIVISION :-
IF WE WANT ACHIEVE THE DIVISION OUR DATA TYPE SHOULD BE
FLOAT TYPE.
CURRENCY CONVERSION :-
@AbapCatalog.sqlViewName: 'ZSRCONVERSION'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CURRENCY_CONVERSION'
define view ZSR_CURRENCY_CONVERSION
with parameters P_CURR: abap.cuky( 5 ),
P_DATE: abap.dats
as select from sflight as A
{
//CURRENCY_CONVERSION//
key A.carrid,
key A.connid,
A.fldate,
currency_conversion ( AMOUNT => A.price,
SOURCE_CURRENCY => A.currency,
TARGET_CURRENCY => $parameters.P_CURR,
EXCHANGE_RATE_DATE => $parameters.P_DATE) as LOCAL_AMT
,
$parameters.P_CURR as LOCAL_CURRENCY
}
where carrid = 'AA'
@AbapCatalog.sqlViewName: 'ZSTRINOPER'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'STRING_OPERATION'
define view ZSR_STRING_FUNCTION as select from kna1 as K
{
key K.kunnr,
K.name1,
K.ort01,
CONCAT(K.kunnr, K.name1) as CONCAT_FUN,
concat_with_space(K.name1, K.ort01, 2) as CONCATING_WITH_SPACE,
SUBSTRING(K.name1, 3, 5) as SUB_STRING,
LENGTH(K.name1) as LENGHT_STRING,
LEFT(K.ort01,3) as LEFT_LENGHT,
RIGHT(K.ort01,3) as RIGHT_LENGHT,
// IT WILL REMOVE THE ZEROS AND AVOIDING SPACE//
LTRIM(K.kunnr, '0') as LEFT_TRIM,
RTRIM(K.kunnr, '0') as RIGHT_TRIM
}
OUTPUT :-
SESSION VARIBLES :-
They are like system variable. In CDS view only 4 different session
variables.
Session Variable ABAPsystem
field
$session.client sy-mandt
$session.system_date sy-datum
$session.system_language sy-langu
$session.user sy-uname
Example:
Output:
Access in CDS Views
Syntax – $Session.vname can be used in CDS views to access the
ABAP-specific session variable. The VNAME are as below:
client – sy-mandt
user – sy-uname
system-language – sy-langu
Example:
@AbapCatalog.sqlViewName: ‘CDS_SESSIONVAR’
define view CDS_SESSIONVAR_DEMO
as select from demo_expressions {
$session.client as sys_client,
$session.user as sys_user
$session.system_language as sys_language
}
ASSOCIATION :-
Associations define relationships between entities such as a
database table or another CDS view. Associations can also be
viewed as a Join-On-Demand. This means that the association will
only be executed when the fields from associated entity are
referred. Typically, CDS associations can be compared to LEFT
OUTER Joins.
TYPES OF ASSOCIATION :-
1) EXPOSED ASSOCIATION :-
2) AD-HOC ASSOCIATION :-
JOINS :-
ASSOCIATION :-
1) ASSOCIATIONS are kind of Joins to fetch data from multiple
tables on Join Conditions but these are ‘JOINS ON-DEMAND’ i.e.
they will only be triggered when user would access the required
data which needs the Association of tables. For example, your
CDS view has 4 Associations configured and user is fetching data
for only 2 tables, the ASSOICATION on other 2 tables will not be
triggered and the system would return the results quickly, so it
enables really high turn-around time as compared to regular
SQL JOINS.
@AbapCatalog.sqlViewName: 'ZASSOCIATIONcar'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'ASSOCIATION'
define view ZSR_ASSOCIATION1 as select from spfli
association [1..1] to scarr as _Scarr
on spfli.carrid = _Scarr.carrid
{
key spfli.carrid,
spfli.connid,
spfli.airpfrom,
spfli.airpto,
_Scarr
//association_name // Make association public
}
IN DDIC VIEW :-
ASSOCIATION WITH [1…1]AD-HOC :-
@AbapCatalog.sqlViewName: 'ZASSOCIATIONcar'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'ASSOCIATION'
define view ZSR_ASSOCIATION1 as select from spfli
association [1..1] to scarr as _Scarr
on spfli.carrid = _Scarr.carrid
{
key spfli.carrid,
spfli.connid,
spfli.airpfrom,
spfli.airpto,
_Scarr.carrname,
_Scarr.currcode
@AbapCatalog.sqlViewName: 'ZASS1MANY'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'ASSOCIATION'
define view ZSR_ASSOCIATION_ONE_TO_MANY as select from scarr
association [1..*] to spfli as _SPFLI
on _SPFLI.carrid = scarr.carrid
{
key scarr.carrid,
scarr.carrname,
scarr.currcode,
_SPFLI.connid // EXPOSING ASSOCIATION
}
IT WILL FETCH ALL DATA FROM THE PRIMARY TABLE NOT FORM
THE ASSOCIATED TABLE .
@AbapCatalog.sqlViewName: 'ZASSC0TOSTAR'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'MANY'
define view ZSR_ASSOCIATION_MANY as select from scarr
association [0..*] to spfli as _SPFLI
on SCARR.carrid = _SPFLI.carrid
{
*
}
@AbapCatalog.sqlViewName: 'ZBASIC_VIEW1'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType:#BASIC
@Analytics.dataCategory: #DIMENSION
@EndUserText.label: 'BASIC VIEW'
define view ZSR_BASIC_VIEW as select from sflight
association [1..1] to spfli as _SPFLI
on sflight.carrid = _SPFLI.carrid
{
key sflight.carrid,
sflight.connid,
sflight.currency,
_SPFLI.airpto,
_SPFLI.airpfrom
COMPOSITE VIEW :-
@AbapCatalog.sqlViewName: 'ZCOMPOSITEVIEW'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #COMPOSITE
@Analytics.dataCategory: #CUBE
@EndUserText.label: 'COMPOSITE_VIEW'
define view ZSR_COMPOSITE_VIEW as select from ZSR_BASIC_VIEW
{
ZSR_BASIC_VIEW.carrid,
@DefaultAggregation: #SUM
ZSR_BASIC_VIEW.seatsmax,
ZSR_BASIC_VIEW.connid,
ZSR_BASIC_VIEW.airpto,
ZSR_BASIC_VIEW.currency
}
COUSMPATION VIEW :-
@AbapCatalog.sqlViewName: 'ZCONSUMPTION'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #CONSUMPTION
@EndUserText.label: 'CONSUMPATION'
define view ZSR_CONSUMPTION_VIEW as select from ZSR_COMPOSITE_VIEW
{
ZSR_COMPOSITE_VIEW.carrid,
ZSR_COMPOSITE_VIEW.seatsmax,
ZSR_COMPOSITE_VIEW.connid,
ZSR_COMPOSITE_VIEW.airpto,
ZSR_COMPOSITE_VIEW.currency
ANNOTATION :-
An annotation enriches a definition in the ABAP CDS with
metadata. Or it is used to define additional characteristics or
capabilities to the ABAP CDS object. It can be specified for a
specific scope of the CDS object such as specific places in a piece of
CDS Source code.
ABAP Annotations:
AbapCatalog Annotations
AccessControl Annotations
ClientDependent Annotations
DataAging Annotations
EndUserText Annotations
Environment Annotations
Component Annotations:
Analytics Annotations
AnalyticsDetails Annotations
Consumption Annotations
DefaultAggregation Annotations
EnterpriseSearch Annotations
Hierarchy Annotations
ObjectModel Annotations
OData Annotations
Search Annotations
SearchIndex Annotations
Semantics Annotations
UI Annotations
VDM Annotations
TYPES OF ANNOTATIONS :-
A header annotation is an annotation that is placed at the top of the CDS view
definition, and it is used to define the overall structure of the view. It can be used to
specify things like the name of the view, the type of data, and the key fields.
A body annotation, on the other hand, is an annotation that is placed inside the body of
the CDS view definition, and it is used to provide additional information about the fields
or entities in the view. It can be used to specify things like the data type, the length, and
the label of a field, or the relationships between different entities.
For example, if you have a CDS view with a header annotation that defines the structure
of the view, and a body annotation that provides additional information about the fields
in the view.
@AbapCatalog.sqlViewName: 'ZSALES_ORDER'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
key so_id,
sales_order_date,
total_amount,
@Semantics.currencyCode: true
currency_code
}
EXTEND (EXTENSION CDS VIEW ) :-
NOTE :- There are also some restriction where the CDS view can’t
be extended if the CDS base view contains GROUP BY clause, etc.
@AbapCatalog.sqlViewName: 'ZEXTENDVIEW'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'EXTESION VIEW'
define view ZSR_EXTEND_VIEW as select from spfli
{
key spfli.carrid,
spfli.connid,
spfli.airpfrom,
spfli.airpto,
spfli.distance
}
OUTPUT :-
NOW WE ARE APPENDING OUR 3 FIELDS TO THE CDS VIEW BY
USING EXTEND VIEW.
NOTE :- WE NEED TO USE “@SQLAPPENDVIEWNAME”
WE HAVE TO PROVIDE THE PREVIOUS VIEW NAME WHICH IS
GOING EXTENDED AND PRESENT VIEW.
@AbapCatalog.sqlViewAppendName: 'ZSR_APPEND'
@EndUserText.label: 'EXTEND'
extend view ZSR_EXTEND_VIEW with ZSR_EXTEND_VIEW_CONTINUE
{
spfli.deptime,
spfli.countryto,
spfli.period
}
OUTPUT :-
DISPLAYING THE DATA IN ALV GRID FORMAT :-
*&---------------------------------------------------------------------*
*& Report zsr_alv_grid1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSR_ALV_GRID1.
data(oalv_obj) = cl_salv_gui_table_ida=>create_for_cds_view(
CONV #('ZSR_EXTEND_VIEW') ).
OALV_obj->fullscreen( )->display( ).
UNION AND UNION ALL BULIT-IN-FUCNTIONS IN CDS VIEW :-
In CDS (Core Data Services) views, the UNION and UNION ALL functions are used to
combine the result sets of two or more SELECT statements.
The UNION function returns distinct rows from the combined result sets, meaning it
eliminates any duplicate rows.
The UNION ALL function returns all rows from the combined result sets, including any
duplicate rows.
@AbapCatalog.sqlViewName: 'ZUNIONFUN'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'UNION FUNCTION'
define view ZSR_UNION_FUN1 as select from sflight
{
carrid,
connid
}
union
select from spfli
{
carrid,
connid
}
@AbapCatalog.sqlViewName: 'ZUNIONFUN'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'UNION FUNCTION'
define view ZSR_UNION_FUN1 as select from sflight
{
carrid,
connid
}
union ALL
select from spfli
{
carrid,
connid
}
AMDP CLASS :-
AMDP METHOD :-
CDS VS AMDP :
INTERFACES : IF_AMDP_MARKER_HDB.
ENDCLASS.
ENDMETHOD.
ENDCLASS.
-----------------------------------------------------------------------------
OBJ->GET_VBRP_DATA (
EXPORTING IV_VBELN = P_VBELN
IMPORTING EX_VBRP = LT_VBRP
).
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
IMPORTING
R_SALV_TABLE = ob_salv
CHANGING
T_TABLE = LT_VBRP
.
CATCH CX_SALV_MSG.
ENDTRY.
ob_salv->display( ).
SECOND PROGRAM :-
PUBLIC SECTION.
INTERFACES : IF_AMDP_MARKER_HDB.
METHODS : GET_FLIGHT_DATA
IMPORTING VALUE(IV_CARRID) TYPE SFLIGHT-CARRID
EXPORTING VALUE(EX_FLIGHT) TYPE TF_SFLIGHT.
ENDCLASS.
ENDMETHOD.
ENDCLASS.
-----------------------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Report zsr_calling_amdp_class1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSR_CALLING_AMDP_CLASS1.
OBJ->GET_FLIGHT_DATA(
EXPORTING IV_CARRID = P_CARRID
IMPORTING EX_FLIGHT = LT_SFLIGHT
).
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
IMPORTING
R_SALV_TABLE = ob_salv
CHANGING
T_TABLE = LT_SFLIGHT
.
CATCH CX_SALV_MSG.
ENDTRY.
ob_salv->display( ).
Important Points:
3. AMDP are a part of native SQL and don't support automatic client
handling.
Check again.
So its updated.
PUBLIC SECTION.
INTERFACES : IF_AMDP_MARKER_HDB.
METHODS : GET_FLIGHT_DETAILS IMPORTING VALUE(IV_CARRID) TYPE SFLIGHT-CARRID
EXPORTING VALUE(EX_FLIGHT) TYPE TF_FLIGHT.
ENDCLASS.
ENDMETHOD.
ENDCLASS.
ABAP PROGRAM :-
*&---------------------------------------------------------------------*
*& Report zsr_calling_amdp_inner_join
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSR_CALLING_AMDP_INNER_JOIN.
OBJ->GET_FLIGHT_DETAILS(
EXPORTING IV_CARRID = P_CARRID
IMPORTING EX_FLIGHT = DATA(LT_DATA)
).
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
IMPORTING
R_SALV_TABLE = o_SALV
CHANGING
T_TABLE = LT_DATA
.
CATCH CX_SALV_MSG.
ENDTRY.
o_salv->display( ).
CLIENT – sy-mandt
APPLICATIONUSER – sy-uname
LOCALE_SAP – sy-langu
Example:
METHOD get_session_variables_amdp
BY DATABASE PROCEDURE FOR HDB
LANGUAGE SQLSCRIPT.
clnt := session_context(‘CLIENT’);
unam := session_context(‘APPLICATIONUSER’);
lang := session_context(‘LOCALE_SAP’);
ENDMETHOD.
AMDP WITH 2 METHODS ONE PUBLIC AND PRIVATE AND HOW TO
CALL :-
PUBLIC SECTION.
INTERFACES : IF_AMDP_MARKER_HDB.
METHODS : GET_FLIGHT_DATA
IMPORTING VALUE(IV_CARRID) TYPE SFLIGHT-CARRID
EXPORTING VALUE(EX_FLIGHT) TYPE TF_SFLIGHT.
PRIVATE SECTION.
METHODS : GET_FLIGHT_DATA_DB
IMPORTING VALUE(IV_CARRID) TYPE SFLIGHT-CARRID
EXPORTING VALUE(EX_FLIGHT) TYPE TF_SFLIGHT.
ENDCLASS.
"WE ARE CALLING PRIVATE AMDP METHOD INSIDE ANOTHER AMDP METHOD"
METHOD GET_FLIGHT_DATA BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT
USING ZCL_AMDP_DEMO1=>GET_FLIGHT_DATA_DB.
CALL "ZCL_AMDP_DEMO1=>GET_FLIGHT_DATA_DB"(iv_carrid => IV_CARRID,
EX_FLIGHT => :ex_flight);
ENDMETHOD.
ENDMETHOD.
ENDCLASS.
CALLING IN ABAP :-
*&---------------------------------------------------------------------*
*& Report zsr_calling_amdp_class1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSR_CALLING_AMDP_CLASS1.
OBJ->GET_FLIGHT_DATA(
EXPORTING IV_CARRID = P_CARRID
IMPORTING EX_FLIGHT = LT_SFLIGHT
).
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
IMPORTING
R_SALV_TABLE = ob_salv
CHANGING
T_TABLE = LT_SFLIGHT
.
CATCH CX_SALV_MSG.
ENDTRY.
ob_salv->display( ).
AMDP FUNCTION IMPLEMENTATION (WITH RETURN ) :-
@ClientDependent: false
@EndUserText.label: 'CDS WITH AMDP'
define table function ZSR_CDS_AMDP
//HERE WE ARE PASSING CLIENT THROUGH PARAMETER//
with parameters P_CLIENT : abap.clnt,
P_CARRID : s_carr_id
// HERE WE ARE RETURNING//
returns {
CLIENT : abap.clnt;
CARRID : s_carr_id;
CARRID1 : s_carr_id;
}
implemented by method ZCL_CDS_AMDP=>GET_DATA;
PUBLIC SECTION.
INTERFACES : IF_AMDP_MARKER_HDB.
class-METHODS : GET_DATA FOR TABLE FUNCTION ZSR_CDS_AMDP.
ENDCLASS.
endmethod.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Report zsr_cds_amdp_calling
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSR_CDS_AMDP_CALLING.
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
IMPORTING
R_SALV_TABLE = oB_SALV
CHANGING
T_TABLE = LT_RESULT
.
CATCH CX_SALV_MSG.
ENDTRY.
oB_SALV->display( ).
CDS VIEW :-
//@ClientDependent: false//
@ClientDependent: true
@EndUserText.label: 'CDS WITH AMDP'
define table function ZSR_CDS_AMDP with parameters @Environment :
{
systemField: #CLIENT
}
//HERE WE ARE PASSING CLIENT THROUGH PARAMETER//
P_CLIENT : abap.clnt,
P_CARRID : s_carr_id
// HERE WE ARE RETURNING//
returns {
CLIENT : abap.clnt;
CARRID : s_carr_id;
CARRID1 : s_carr_id;
PUBLIC SECTION.
INTERFACES : IF_AMDP_MARKER_HDB.
class-METHODS : GET_DATA FOR TABLE FUNCTION ZSR_CDS_AMDP.
ENDCLASS.
endmethod.
ENDCLASS.
ABAP PROGRAM :-
*&---------------------------------------------------------------------*
*& Report zsr_cds_amdp_calling
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSR_CDS_AMDP_CALLING.
PARAMETERS : P_CD TYPE SFLIGHT-CARRID.
"P_CT TYPE SFLIGHT-MANDT.
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
IMPORTING
R_SALV_TABLE = oB_SALV
CHANGING
T_TABLE = LT_RESULT
.
CATCH CX_SALV_MSG.
ENDTRY.
oB_SALV->display( ).
@AbapCatalog.sqlViewName: 'ZCDSWITHREFERNCE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'REFERNCE'
define view ZSR_CDS_WITH_REFERNCE as select from spfli as FLY
association [1] to sflight as _FLIGHT on
_FLIGHT.carrid = FLY.carrid
{
key FLY.carrid,
FLY.connid,
FLY.airpfrom,
FLY.airpto,
_FLIGHT
}
@AbapCatalog.sqlViewName: 'ZCDSREFER'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'REFERNCE'
define view ZSR_CDS_WITH_REFERNCE1 as select from sflight as FLIGHT
association [1] to ZSR_CDS_WITH_REFERNCE as _RE
on $projection.carrid = _RE.carrid
{
key FLIGHT.carrid,
FLIGHT.connid,
FLIGHT.currency,
_RE
Annotations are used in CDS (Core Data Services) Views to provide additional
information about entities, associations, and elements in the data model. They help to
enrich the semantic information of the model and to support tools like code generation
and smart controls in user interfaces.
Annotations can be defined as metadata, i.e., data about data, and are attached to the
elements in the CDS View. They can be used to provide additional information, such as a
description, label, or type, to the elements in the view, as well as to s upport data
validation, data formatting, and access control.
For example, an annotation can be used to specify the label for a field in a CDS View,
which will be displayed as the column header in a table, or to specify the format of a
date field, which will be used to display the date in the desired format in a UI.
UI ANNOATION :-
UI Annotation in CDS view refers to adding additional information to the
view fields and definitions, like labels, descriptions, and restrictions, to
improve the user experience in the UI.
@AbapCatalog.sqlViewName: 'ZSRUI2'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'UI'
@OData.publish: true
define view ZSR_CDS_WITH_UI_2 as select from ekko as KO
left outer join ekpo as PO on KO.ebeln = PO.ebeln
{
key KO.ebeln,
KO.ernam,
coalesce ( ebelp, 'NOEB') as EBB,
PO.matnr
label: A user-friendly label for the field that is displayed in the UI.
position: The order in which the field is displayed in the table or list.
type: The type of the field, such as currency, unit, or measure.
criticality: Specifies if a field is critical or not.
criticalityCalculation: A calculation expression to determine the criticality of a field.
quickInfo: A tooltip text that is displayed when the user hovers over the field.
semanticalObject: Specifies the semantic object of a field, which is used to identify
the field in the UI.
semanticObjectAction: Specifies the semantic object action of a field.
sorting: Specifies the sorting behavior of a field.
filter: Specifies the filter behavior of a field.
width: Specifies the width of a field.
labelPlacement: Specifies the placement of the field label in relation to the field
value.
inline: Specifies if a field should be displayed inline or in a separate row.
visible: Specifies if a field is visible or not.
mandatory: Specifies if a field is required or optional.
@AbapCatalog.sqlViewName: 'ZSRUI4'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'UI'
@OData.publish: true
define view ZSR_CDS_WITH_UI_4 as select from ekko as EE
association [1] to ekpo as _EP
on _EP.ebeln = EE.ebeln
{
@UI.lineItem: [{
position: 1,
label: 'PURCHASE_ORDER',
importance: #HIGH
}]
key EE.ebeln,
@UI.lineItem: [{
position: 3,
label: 'NAME',
importance: #HIGH
}]
EE.ernam,
@UI.lineItem: [{
position: 2,
label: 'PURCHASE_DATA',
importance: #HIGH
}]
_EP.ebelp,
@UI.lineItem: [{
position: 5,
label: 'MATERIAL_NUM',
importance: #HIGH
}]
_EP.matnr,
@UI.lineItem: [{
position: 4,
label: 'ERR',
importance: #HIGH
}]
_EP.erekz
}
@ENDUSERTEXT TO GIVE INFORMATION WHEN WE PLACE THE
CURSOR ON FIELD :
@EndUserText : {
quickInfo: 'CREATED'
@UI.selectionField: [{
position: 1
}]
@AbapCatalog.sqlViewName: 'ZIMG'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'IMAGE DISPLAYING'
@OData.publish: true
define view ZSR_CDS_WITH_IMAGE as select from snwd_employees as EMP
{
key EMP.employee_id as EMP_ID,
EMP.first_name as EMP_FISRT_NAME,
EMP.last_name as EMP_LAST_NAME,
CONCAT('HTTP://183.82.98.9:8057',EMP.employee_pic_url) as EMP_IMG
}
@AbapCatalog.sqlViewName: 'ZIMG'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'IMAGE DISPLAYING'
@Search : {
searchable: true
}
@OData.publish: true
@UI.headerInfo: {
typeName: 'Employee',
typeNamePlural: 'Employees',
title: {
value: 'employee_id'},
description: {
value: 'FullName'},
imageUrl: 'urlIMG'
}
@UI.lineItem: [{
position: 10,
label: 'EMP ID',
importance: #HIGH }]
@UI.selectionField: [{
position: 10 }]
key snwd_employees.employee_id as employee_id ,
@UI.lineItem: [{
position: 20,
label: 'First Name',
importance: #HIGH }] //link is open through mobile at the time this field should mandtory dis
@Search: {
defaultSearchElement: true,
fuzzinessThreshold: 0.6, //fault-tolerant search
ranking: #HIGH
}
snwd_employees.first_name as firstName,
@UI.lineItem: [{
position: 35,
label: 'Last Name',
importance: #HIGH }]
@Search: {
defaultSearchElement: true,
fuzzinessThreshold: 0.6,
ranking: #MEDIUM
}
snwd_employees.last_name as LastName,
concat_with_space(snwd_employees.first_name,snwd_employees.last_name,1) as FullName,
concat('http://183.82.98.9:8057',snwd_employees.employee_pic_url) as urlIMG
}
UI ANNOATION WITH SOME NEW ANNOATIONS BY BINDING THE
SEREVICE IN ADT TOOL ITSELF :-
@AbapCatalog.sqlViewName: 'ZUIANNO'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'ANNOATION'
@OData.publish: true
define view ZSR_UI_ANNOATION as select from mara
{
@UI.lineItem: [{ position: 01 , label: 'MATERIAL_NUM' }]
key matnr,
@UI.lineItem: [{ position: 02 , label: 'MATERIAL_DESC' }]
matkl,
@UI.lineItem: [{ position: 03 , label: 'CREATED_BY' }]
ernam,
@UI.lineItem: [{ position: 04 , label: 'CREATED_ON' }]
ersda
}
@EndUserText.label: 'SERVICE'
define service ZSR_UI_ANNOATION_SRV {
expose ZSR_UI_ANNOATION;
}
@ObjectModel.text.element: ['MATERIALNUM']
@UI.textArrangement: #TEXT_FIRST
@AbapCatalog.sqlViewName: 'ZUIANNO'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'ANNOATION'
@OData.publish: true
define view ZSR_UI_ANNOATION as select from mara as ma
{
@UI.lineItem: [{ position: 01 , label: 'MATERIAL_NUM' }]
@ObjectModel.text.element: ['matkl']
@UI.textArrangement: #TEXT_FIRST
key ma.matnr as MATNR,
@AbapCatalog.sqlViewName: 'ZVALUEHELP'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'PROVIDING VALUE HELP'
define view ZSR_VALUE_HELP as select from mara
{
key matnr,
matkl
}
@ObjectModel.resultSet.sizeCategory: #XS
define view ZSR_VALUE_HELP as select from SPFLI
{
@ObjectModel.text.element: ['CARRID']
key CARRID,
CONNID
}
MAKING THE FIELD AS MANDATORY FIELD
@UI.headerInfo :
{
typeName: 'MATERIAL ', typeNamePlural: 'MATERIALS',
title: {
type: #STANDARD,
value: 'MATERIAL_NUM'
},
description:{
type: #STANDARD,
value: 'MATNR'
}
}
@UI.facet: [{
id: 'MATERIAL_INFO',
type: #COLLECTION,
label: 'MATERIAL',
position: 10 },
{
id: 'MATERIAL_NUM',
type: #IDENTIFICATION_REFERENCE,
label: 'MATERIAL_DATA',
PARENTID: ‘MATERIAL_INFO’
position: 10
}
@UI.identification: [{ position: 10 }]
key ma.matnr as MATERIAL_NUM,
@ObjectModel.resultSet.sizeCategory: #XS
define view ZSR_VALUE_HELP as select from mara
{
@ObjectModel.text.element: ['matnr']
key matnr,
matkl
}
MAKING THE GROUP AND ADD DATA UNDER TAB
//GROUPING FIELDS//
{
id: 'CREATIONINFO',
type: #FIELDGROUP_REFERENCE,
label: 'CREATION_INFO',
parentId: 'MATERIAL_INFO',
targetQualifier: 'TQDATA',
position: 10
}]
@AbapCatalog.sqlViewName: 'ZMARD'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'MARD'
define view ZSR_UI_MARD as select from mard
{
@UI.lineItem: [{ position: 10 , label: 'MATERIAL'}]
key matnr,
@UI.lineItem: [{ position: 20, label: 'PLANT' }]
key werks,
@UI.lineItem: [{ position: 30, label: 'STORAGE' }]
key lgort,
@UI.lineItem: [{ position: 40, label: 'DATE' }]
ersda,
@UI.lineItem: [{ position: 50, label: 'MAINT_STATUS' }]
pstat
}
{
id: 'MARD',
purpose: #STANDARD,
type: #LINEITEM_REFERENCE,
label: 'MAT',
position: 30,
targetElement:'_MD'
}]
@AbapCatalog.sqlViewName: 'ZUIANNO'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'ANNOATION'
@UI.headerInfo :
{
typeName: 'MATERIAL ', typeNamePlural: 'MATERIALS',
title: {
type: #STANDARD,
value: 'MATERIAL_NUM'
},
description:{
type: #STANDARD,
value: 'MATNR'
}
}
define view ZSR_UI_ANNOATION as select from mara
association[1..*] to ZSR_UI_MARD as _MD on $projection.MATERIAL_NUM = _MD.matnr
{
@UI.facet: [{
id: 'MATERIAL_INFO',
type: #COLLECTION,
label: 'MATERIAL',
position: 10 },
{
id: 'MATERIALNUM',
type: #IDENTIFICATION_REFERENCE,
label: 'MATERIAL_DATA',
parentId: 'MATERIAL_INFO',
position: 10
},
//GROUPING FIELDS//
{
id: 'CREATIONINFO',
type: #FIELDGROUP_REFERENCE,
label: 'CREATION_INFO',
parentId: 'MATERIAL_INFO',
targetQualifier: 'TQDATA',
position: 10
},
{
id: 'MARD',
purpose: #STANDARD,
type: #LINEITEM_REFERENCE,
label: 'MAT',
position: 30,
targetElement:'_MD'
}]
//PUBLIC ASSOCIATION//
_MD
Analytics in CDS (Core Data Services) view is a feature of SAP HANA that allows for
the creation and execution of analytical queries on top of the data stored in a CDS
view. It provides a way to perform advanced calculations and data aggregation for
business intelligence and reporting purposes. Analytics in CDS views can be used
in combination with other SAP HANA features, such as the modeling and
calculation views, to create a complete end-to-end data analysis solution.
@AbapCatalog.sqlViewName: 'ZMODELDIM'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'MODEL'
@Analytics.dataCategory: #DIMENSION
key sflight.carrid,
sflight.connid,
sflight.currency,
_SPF.airpto,
_SPF.airpfrom
}
@AbapCatalog.sqlViewName: 'zmodeldim1'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'MODEL1'
@Analytics.dataCategory: #DIMENSION
define view ZSR_MODEL_DIMNISION1 as select from scarr
association [1..1] to sflight as _sf
on $projection.carrid = _sf.carrid
{
key scarr.carrid,
scarr.carrname,
scarr.currcode,
_sf.fldate,
_sf.price
}
@AbapCatalog.sqlViewName: 'ZSRCUBE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CUBE ANALYTIC'
@Analytics.dataCategory: #CUBE
define view ZSR_MODEL_CUBE as select from spfli
association [0..*] to ZSR_MODEL_DIMNISION as _ZSR_MODEL_DIMNISION
on $projection.connid = _ZSR_MODEL_DIMNISION.connid
association[1..1] to ZSR_MODEL_DIMNISION1 as _ZSR_MODEL_DIMNISION1
on $projection.carrid = _ZSR_MODEL_DIMNISION1.carrid
{
key spfli.connid,
_ZSR_MODEL_DIMNISION.airpfrom,
_ZSR_MODEL_DIMNISION1.carrid
GRAPHICS :
Authorization
Authorization Object
Authorization Object is a method of restricting users to access any
particular application created in the system. It will be denying user
for viewing confidential data on screen or denying access to certain
transactions.
Example
Suppose we have a Zcdsview in our system that consists of
confidential data. Which cannot be accessed by all users. Only
authorized persons can have access to the data. So, in case these
tables are being used in any program, for display/write purpose,
that program would be executed only by Authorized users. Please
make sure to disable Table Entries, while creating tables, and not to
create any Table Maintenance Generator also. Only this program
would be used to perform read/write operations on the table.
Authorization Field
Authorization field contains the value that you have defined. It is
connected to the data elements stored with the ABAP dictionary.
Steps:
1. Creating Object Class T-Code SU21.
2. Creating Authorization Object Which contains Authorization field.
You can create authorization field in SU20 or while creating
authorization object also you can create.
3. Creating a Role T-Code PFCG.
4. Assigning Authorization object to the role and generating the
profile.
5. Create custom program using Authority-check.
Object Class contain many authorization objects and select Authorization Object.
The below screen appears, provide the Object name, text and class name is already created and click
on Field maintenance. You can create authorization field in SU20 also.
Then click on Authorization Field
Provide the authorization field and data element once you click on enter button the domain and
output length will come automatically. select save button and go back.
Add the two-authorization field one is ZCARRID and ACTVT and select save button.
ACTVT:ACTVT is a standard field within SAP Table tact that stores Activity information like create,
change, display.
Select Permitted Activities button.
You can select as many activities and click on save. Here I took display authorization.
The next step is to create a role in T-Code PFCG, inside which we will attach our authorization Object.
Enter the role and click on Single Role button.
What is Role:role is assigned to an users the user menu that is displayed after they log on to the sap
system. Roles also contain the authorizations that users can use to access the transaction, reports,
Web-based applications.
Single Role:is created with the profile generator and allows the automatic generation of an
authorization profile. The role contains the authorization data and the logon menu for the user.
Select the Authorization tab and click on the icon next to profile name. Once you click on the icon
system will generate a profile name and a profile text.
What is profile:A profile is the element in the authorization system. It allows a user to access the
system. For authorization check, the system checks on the particular profile which is assigned to user
for the proper authorization.
You will see a new screen with role name on top left. Here you can add your Authorization object
that was created in SU21. Click on the Manually button.
Add the Authorization object and press enter.
Now you need to add values in your object. For those who would be given authorization.
Click on change of ZCARRID
Press f4 and you can select any number of Airline code. Here I have selected AA and press continue
and click on save button.
Do same for ACTVT and select display and click on save button.
Then generate the profile by clicking on generate icon.
Finally, you come out of the screen pressing back button. And you will see the authorizations tab
with a green symbol, meaning, authorization object has been assigned and the role can be used.
After these steps click on the User tab and provide the User Id and click on User Comparison button.
The Authorization and User tab with a green symbol, means you have successfully created the
authorization and assigned the role to the user.
Create custom program using Authority-check.
Authority-check:Authority Check is the statement used in an ABAP program to perform an authorization
check against an authorization object. This statement will return sy-subrc is 4 if user has not authorized.
Authorization in CDS View
We all k now how authorization works in ABAP using ABAP statement AUTHORITY-CHECK, In CDS View
has its own authorization concept CDS access controls using a data control language (DCL).
DCL(Data Control Language):DCL is used to define the authorization for the CDS View which controls
access to the data retrieved based on user.
First step, we can create an implementation CDS View (SPFLI) from this table.
@AbapCatalog.sqlViewName:'ZMMAUTH'
@AbapCatalog.compiler.compareFilter:true
@AbapCatalog.preserveKey:true
@AccessControl.authorizationCheck:#CHECK
@EndUserText.label:'Authorization Check'
defineviewZMM_Authorizationasselectfrom spfli {
//spfli
key carrid,
connid,
cityfrom,
cityto
}
@MappingRole: true
Role is implicitly to all users
Grant select on This is the CDS View on which data restriction are to be applied through a DCL.
Aspect pfcg_auth This is the place to include the authorization object and authorization fields on
which it is applied with the ACTVT permitted activities.The possible value of ACTVT for that
authorization object can be seen in TCODE SU21 as shown below. As most CDS views are used for
reading, 03 is used which is for display.
@EndUserText.label:'Access Control'
@MappingRole:true
definerole ZACCESS_CONTROL {
grant
select
on
ZMM_AUTHORIZATION
where
( CARRID )=aspectpfcg_auth(ZSPF_CARRI, ZCARRID, ACTVT ='03');
FISRT WE HAVE TO OPEN ONE CDS VIEW , DO RIGHT CLICK -> OPEN
WITH -> DEPENDNCY ANALYZER.
IF WE WANT TO SEE IN SQL GRAPH CLICK ON SQL RELATION
1. Code push down: As explained above, code push down can improve performance by
executing filtering, aggregation, and calculation logic within the database layer.
2. Indexes: Creating indexes on the columns used in the filtering and aggregation of the
CDS view can improve query performance.
3. Materialized views: Materializing a CDS view can improve performance by pre-
calculating the result set and storing it in a separate table, allowing for faster access to
the data.
4. Partitioning: Partitioning a CDS view can improve performance by distributing the data
across multiple storage containers, reducing the amount of data that needs to be
loaded into memory.
5. Minimizing data load: Avoid loading unnecessary data into memory by using
appropriate filters in the CDS view definition.
6. Avoiding complex calculations: Complex calculations can impact performance. If
possible, perform calculations outside of the CDS view or use stored procedures to
perform the calculation.
7. Use of appropriate join types: Use inner joins instead of outer joins, as outer joins can be
slower and consume more memory.
UDERSTANDING OF VDM AND IT’S LAYERS :-
@PROJECTION :-
1)SERVICEQUALITY :-
2)SIZECATOGRY :-
HERE DEPENDED ON SIZE DB WILL GIVE SOURCE , IF XXL HAS LOT
OF FIELDS THAT TIME IT WILL TELL TO DB I HAVE THIS MUCH
RECORD LIKE THAT , THAT TIME DB WILL PROVIDE SOURCE.
3)DATACLASS :-
HOW AND WHERE AND WHEN TO USE THESE THREE ANNOTAIONS
:-
CHECKING THE CDS VIEW KIP AND IT’S ALL ANNOTAION ARE
IMPLEMENTED OR NOT:-
BASIC VIEW 1 :-
@AbapCatalog.sqlViewName: 'ZBASICVIEW'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'BASIC VIEW'
@VDM.viewType: #BASIC
@Analytics.dataCategory: #DIMENSION
define view ZSR_BASIC_VIEW1 as select from scarr
{
key scarr.carrid as Airline,
@Semantics.text: true
scarr.carrname as AirName,
@Semantics.currencyCode: true
scarr.currcode as AirCurrency,
scarr.url as AirlineUrl
@AbapCatalog.sqlViewName: 'ZBASICVIEW2'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'BASIC VIEW2'
@VDM.viewType: #BASIC
@Analytics.dataCategory: #DIMENSION
define view ZSR_BASIC_VIEW2 as select from spfli
association [0..1] to ZSR_BASIC_VIEW1 as _SCARR
on $projection.Airline = _SCARR.Airline
{
//@ObjectModel.foreignKey.association: ‘_Scarr’
key spfli.carrid as Airline,
key spfli.connid as AirConnection,
spfli.countryfr as DepartureCountry,
spfli.countryto as ArrivalCountry,
//@Semantics.quantity.unitOfMeasure: ‘AirDistanceUnit’
@DefaultAggregation:#SUM
spfli.distance as AirDistance,
@Semantics.unitOfMeasure: true
spfli.distid as AirDistanceUnit,
_SCARR
@AbapCatalog.sqlViewName: 'ZBASICVIEW3'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'BASIC VIEW3'
@VDM.viewType: #BASIC
@Analytics.dataCategory: #CUBE
define view ZSR_BASIC_VIEW3 as select from sflight
association [0..1] to ZSR_BASIC_VIEW1 as _SCARR
on $projection.Airline = _SCARR.Airline
{
//@ObjectModel.foreignKey.association: ‘_Scarr’
key sflight.carrid as Airline,
//@ObjectModel.foreignKey.association: ‘_Spfli’
key sflight.connid as AirConnection,
key sflight.fldate as FlightDate,
//@Semantics.amount.currencyCode: ‘FlightCurrency’
@DefaultAggregation: #MIN
sflight.price as FlightPrice,
@Semantics.currencyCode: true
sflight.currency as FlightCurrency,
@DefaultAggregation: #SUM
sflight.seatsmax as MaximumAvaSeats,
@DefaultAggregation: #SUM
sflight.seatsocc as NumberOfAvaSeats,
/* Associations */
_SCARR,
_SPFLI
@AbapCatalog.sqlViewName: 'ZCOMPOSITE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'COMPOSITE VIEW'
@VDM.viewType: #COMPOSITE
@Analytics.dataCategory: #CUBE
define view ZSR_COMPOSITE_VIEW_FOR_3BASIC as select from ZSR_BASIC_VIEW3
{
//@ObjectModel.foreignKey.association: ‘_Scarr’
key ZSR_BASIC_VIEW3.Airline,
//@ObjectModel.foreignKey.association: ‘_Spfli’
key ZSR_BASIC_VIEW3.AirConnection,
key ZSR_BASIC_VIEW3.FlightDate,
//@Semantics.amount.currencyCode: ‘FlightCurrency’
@DefaultAggregation:#MIN
ZSR_BASIC_VIEW3.FlightPrice,
@Semantics.currencyCode: true
ZSR_BASIC_VIEW3.FlightCurrency,
@DefaultAggregation: #SUM
ZSR_BASIC_VIEW3.MaximumAvaSeats,
@DefaultAggregation: #SUM
ZSR_BASIC_VIEW3.NumberOfAvaSeats,
/* Associations */
ZSR_BASIC_VIEW3._SCARR,
ZSR_BASIC_VIEW3._SPFLI,
ZSR_BASIC_VIEW3._SCARR.AirName,
ZSR_BASIC_VIEW3._SCARR.AirlineUrl,
ZSR_BASIC_VIEW3._SPFLI.DepartureCountry,
ZSR_BASIC_VIEW3._SPFLI.ArrivalCountry
{
key ZSR_COMPOSITE_VIEW_FOR_3BASIC.Airline,
ZSR_COMPOSITE_VIEW_FOR_3BASIC.AirConnection,
ZSR_COMPOSITE_VIEW_FOR_3BASIC.FlightDate,
ZSR_COMPOSITE_VIEW_FOR_3BASIC.FlightPrice,
ZSR_COMPOSITE_VIEW_FOR_3BASIC.FlightCurrency,
ZSR_COMPOSITE_VIEW_FOR_3BASIC.MaximumAvaSeats,
ZSR_COMPOSITE_VIEW_FOR_3BASIC.NumberOfAvaSeats,
ZSR_COMPOSITE_VIEW_FOR_3BASIC.AirName,
ZSR_COMPOSITE_VIEW_FOR_3BASIC.AirlineUrl,
ZSR_COMPOSITE_VIEW_FOR_3BASIC.DepartureCountry,
ZSR_COMPOSITE_VIEW_FOR_3BASIC.ArrivalCountry,
ZSR_COMPOSITE_VIEW_FOR_3BASIC._SCARR,
ZSR_COMPOSITE_VIEW_FOR_3BASIC._SPFLI
}
TABLE FUCNTION :-
Table functions are useful in CDS views because they allow you to define complex data
models that can be used to provide a unified view of data from multiple tables. They can
also be used to perform calculations on data in the database, which can save time and
reduce the amount of data that needs to be transferred between the database and the
application.
PRERQUSITIES :-
PROCESS TO ACHIEVE THE TABLE FUNCTION :-
ENDCLASS.
ENDMETHOD.
ENDCLASS.
TABLE FUN :-
@EndUserText.label: 'JOINS'
define table function ZSR_TABLE_FUN_JOINS
with parameters P_MATERIAL:matnr,
@Environment.systemField: #CLIENT
clnt:abap.clnt
returns {
client : abap.clnt;
MATERIAL : matnr;
DATE : ersda;
NAME : ernam;
PLANT : werks_d;
STATUS : pstat_d;
}
implemented by method ZCL_TAB_FUN_JOINS=>GET_MATERIAL_DATA;
CLASS :-
ENDMETHOD.
ENDCLASS.
ENDMETHOD.
ENDCLASS.
SOME INTERVIEW QUESTIONS :-
@AbapCatalog.sqlViewName: 'ZPARA2'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'PARAMETER'
define view ZSR_PARAMETRISED_CDS
with parameters P_CARRID : s_carr_id
as select from scarr as SC
{
key SC.carrid as AIRLINE,
SC.mandt as Mandt,
SC.carrid as Carrid,
SC.carrname as Carrname,
SC.currcode as Currcode,
SC.url as Url,
SC.flag as Flag
CDS VIEW :-
@AbapCatalog.sqlViewName: 'ZPARA2'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'PARAMETER'
define view ZSR_PARAMETRISED_CDS
with parameters
P_CARRID : s_carr_id
as select from scarr as SC
{
key SC.carrid as AIRLINE,
SC.mandt as Mandt,
SC.carrid as Carrid,
SC.carrname as Carrname,
SC.currcode as Currcode,
SC.url as Url,
SC.flag as Flag
REPORT PROGRAM :-
REPORT ZSR_EXPOSING_CDS_OPEN_SQL.
select \_spfli-
connid as air_code FROM ZSR_ASSOCIATION_ONE_TO_MANY into TABLE @data(lt)
.
*select \__spfli-
connid FROM ZSR_ASSOCIATION_ONE_TO_MANY into TABLE @data(lt).
BREAK-POINT.
Semantic annotation is the process of adding metadata or tags to content, such as text or
images, to provide additional context and meaning. Semantic annotation is used to make
it easier for machines to understand and interpret the content, and to improve the
accuracy of search results.