0% found this document useful (0 votes)
118 views26 pages

Exercises Wtih Solution

Here are the steps to create a basic CDS BO model for a policy based on table ZAXX_POLICY: 1. Create a new CDS view called ZAXX_BO_POLICY in your package: @AbapCatalog.sqlViewName: 'ZAXX_BO_POLICY' 2. Add the model category annotation to define it as a BO view: @ObjectModel.modelCategory: #BUSINESS_OBJECT 3. Select the relevant fields from table ZAXX_POLICY: define view ZAXX_BO_POLICY as select from ZAXX_POLICY as Policy { key Policy.PolicyNumber, Policy.InsuredName, Policy.StartDate

Uploaded by

Fayazu Palagiri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views26 pages

Exercises Wtih Solution

Here are the steps to create a basic CDS BO model for a policy based on table ZAXX_POLICY: 1. Create a new CDS view called ZAXX_BO_POLICY in your package: @AbapCatalog.sqlViewName: 'ZAXX_BO_POLICY' 2. Add the model category annotation to define it as a BO view: @ObjectModel.modelCategory: #BUSINESS_OBJECT 3. Select the relevant fields from table ZAXX_POLICY: define view ZAXX_BO_POLICY as select from ZAXX_POLICY as Policy { key Policy.PolicyNumber, Policy.InsuredName, Policy.StartDate

Uploaded by

Fayazu Palagiri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Table of Contents

Exercise 1.....................................................................................................................................................2
Exercise 2.....................................................................................................................................................4
Exercise 3.....................................................................................................................................................5
Exercise 4.....................................................................................................................................................6
Exercise 5.....................................................................................................................................................7
Exercise 6.....................................................................................................................................................8
Exercise 7...................................................................................................................................................10
Exercise 8...................................................................................................................................................11
Exercise 9...................................................................................................................................................13
Exercise 10.................................................................................................................................................16
Exercise 11.................................................................................................................................................17
Exercise 12.................................................................................................................................................19
Exercise 13.................................................................................................................................................21
Final CDS Views (Exercises 14 and 15).......................................................................................................23
Policy BO View.......................................................................................................................................23
Person Insured BO View........................................................................................................................23
Policy Consumption View......................................................................................................................24
Person Insured Consumption View........................................................................................................25
Exercise 1
• Create a new program ZAXX_SELECT_CARRIER in your development package (ZXX_ABAP_HANA)
 Select all fields from the carrier table SCARR
 Output your selection on the screen (WRITE and NEW-LINE statements)
• Open the SQL console and select all carriers with currency code USD (field currcode)

Program

*&---------------------------------------------------------------------*
*& Report zzmh_ex01
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zzmh_ex01.

DATA lt_carr TYPE TABLE OF scarr.

SELECT * FROM scarr INTO TABLE lt_carr.

LOOP AT lt_carr ASSIGNING FIELD-SYMBOL(<lfs_carr>).


WRITE: <lfs_carr>-carrid, <lfs_carr>-carrname, <lfs_carr>-currcode.
NEW-LINE.
ENDLOOP.
CDS View

@AbapCatalog.sqlViewName: 'ZMH_SEL_CARR_01'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Select Carrier'
define view ZMH_SELECT_CARRIER_01 as select from scar
{
carrid,
carrname,
currcode,
url
}

Program using CDS View

*&---------------------------------------------------------------------*
*& Report ZZMH_CARR_01_SEL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZZMH_CARR_01_SEL.

  DATA cx_sql TYPE REF TO CX_SY_SQL_ERROR.
  DATA lt_carr TYPE TABLE OF ZMH_SELECT_CARRIER_01.

  TRY.
      SELECT * FROM ZMH_SELECT_CARRIER_01
        INTO TABLE @lt_carr
        WHERE currcode = 'USD'.

      LOOP AT lt_carr ASSIGNING FIELD-SYMBOL(<lfs_carr>).
        WRITE: <lfs_carr>-carrid, <lfs_carr>-carrname, <lfs_carr>-currcode.
        NEW-LINE.
      ENDLOOP.
    CATCH cx_sy_sql_error INTO cx_sql.
      REFRESH lt_carr.

      MESSAGE cx_sql->get_text( ) TYPE 'E' RAISING error.
  ENDTRY.
Exercise 2
• Create a new CDS view ZAXX_CDS_SCARR in your package
• DDIC view name is ZAXX_SCARR
• Select the fields carrid, carrname and currcode from table scarr
• Use aliases for all tables and fields:
• carrid = carrierID – Key field
• carrname = carrierName
• currcode = currencyCode
• scarr = carrier
• Save the view and activate it. Execute the data browser and look at the result (F8)
• Also have a look at the created DDIC view (place cursor on DDIC view name and press F3)
• Add the currency code text from table TCURT to your CDS view
• Add an inner join to table TCURT (alias currencyText) to the CDS view. Join on the fields
currcode and waers
• Add the currency long text to the fields (table field ltext, alias currencyLongText)
• Add a where clause to the CDS view which only select English currency texts (spras = ‘E’)

CDS View

@AbapCatalog.sqlViewName: 'ZMH_SEL_CARR_02'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Example 2'
define view ZMH_SELECT_CARRIER_02 as select from scarr as carrier
inner join tcurt as currencyText on
currencyText.waers = carrier.currcode and currencyText.spras = 'E'
{
key carrier.carrid as carrierID,
carrier.carrname as carrierName,
carrier.currcode as currencyCode,
currencyText.ltext as currencyLongtext
}
Exercise 3
• Create a new CDS view ZAXX_CDS_SCARR_ASSOC in your package
 DDIC view name: ‘ZAXX_SCA_ASSOC’
 Rebuild the view of exercise 2. Use an association instead of a join
 Instead of the currency long text, include the link to the TCURT table
• View the result of the view in the data browser (F8)

CDS View

@AbapCatalog.sqlViewName: 'ZMH_SEL_CARR_03'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Example 3'
define view ZMH_SELECT_CARRIER_03 as select from scarr as carrier
association [1..1] to tcurt as _currencyText on
carrier.currcode = _currencyText.waers and _currencyText.spras = 'E'
{
key carrier.carrid as carrierID,
carrier.carrname as carrierName,
carrier.currcode as currencyCode,
_currencyText
}
Exercise 4
• Create a new CDS view ZAXX_CDS_SPFLI_CASE in your package
 DDIC view: ‘ZAXX_SPF_CASE’
 Select the carrid, connid and distance columns from table spfli
 Create a new Case statement which categorizes the flight distance
• If the distance is more than 3000 then the category should be ‘Long-Haul ‘
• If the distance is between 1000 and 3000 then the category should be
‘Medium-Haul’
• If the distance is less than 1000 the category should be ‘Short-Haul’

CDS View

@AbapCatalog.sqlViewName: 'ZMH_SEL_CARR_04'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Example 3'
define view ZMH_SELECT_CARRIER_04 as select from spfli as schedule
association [1..1] to scarr as _carrier
on schedule.carrid = _carrier.carrid
{
_carrier,
key schedule.carrid,
key schedule.connid,
_carrier.carrname,
schedule.cityfrom,
schedule.cityto,
schedule.distance,
case when schedule.distance > 3000 then 'Long Haul'
when schedule.distance > 1000 then 'Medium Haul'
else 'Short Haul'
end as distance_rating
}
Exercise 5
• Create a new CDS view ZAXX_CDS_SFLIGHT_CURR in your package
 Select the columns carrid, connid, fldate, price, currency from table sflight
 Convert the price into USD. Use the currency_conversion function
• Source currency is the currency field
• Amount is the price field
• Use the fldate as exchange rate date
• Target currency is USD. Since USD is a char type and the target currency field is a
cuky field you have to cast here: cast ('USD' as abap.cuky( 5 ))

CDS View

@AbapCatalog.sqlViewName: 'ZMH_SEL_CARR_05'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Example 5'
define view ZMH_SELECT_CARRIER_05 as select from sflight as flight
{
key flight.carrid,
key flight.connid,
key flight.fldate,
@Semantics.amount.currencyCode: 'flight.currency'
flight.price,
@Semantics.currencyCode: true
flight.currency,
currency_conversion(
amount => price,
source_currency => currency,
target_currency => cast ( 'USD' as abap.cuky( 5 )),
exchange_rate_date => fldate,
error_handling => 'SET_TO_NULL'
) as usdPrice
}
Exercise 6
Exercise 7
• Create the CDS BO model ZAXX_BO_POLICY for your policy BO based on table ZAXX_POLICY
 Define the view as a BO view: @ObjectModel.modelCategory: #BUSINESS_OBJECT
 Define the view as the root of the BO model: @ObjectModel.compositionRoot: true
 Enable transactional processing for the view:
@ObjectModel.transactionalProcessingEnabled: true
 Define your ZAXX_POLICY table as the DDIC table for the view:
@ObjectModel.writeActivePersistence: 'ZAXX_POLICY‘
 Enable Create, Update and Delete options: @ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true @ObjectModel.updateEnabled: true
 Define the Policy ID as the representative key: @ObjectModel.representativeKey:
'Policy_ID’
 Add the policy_id, status, type and policyholder fields of the ZAXX_POLICY table to the
view
 Define the policy_id field as the key of the view

CDS View

@AbapCatalog.sqlViewName: 'ZMH_BO_POL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Policy BO View'

@ObjectModel.modelCategory: #BUSINESS_OBJECT
@ObjectModel.compositionRoot: true
@ObjectModel.transactionalProcessingEnabled: true

@ObjectModel.writeActivePersistence: 'ZMH_POLICY'
@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.representativeKey: 'policy_id'

define view ZMH_BO_POLICY as select from zmh_policy


{
key policy_id,
status,
poltype,
pol_holder
}
Exercise 8
• Create the CDS BO model ZAXX_BO_PERS_INSURED for your insured person BO based on table
ZAXX_PERS_INS
 Define the view as a BO view: @ObjectModel.modelCategory: #BUSINESS_OBJECT
 Define your ZAXX_PERS_INS table as the DDIC table for the view:
@ObjectModel.writeActivePersistence: 'ZAXX_PERS_INS‘
 Enable Create, Update and Delete options: @ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true @ObjectModel.updateEnabled: true
 Add the policy_id, person_id, last_name, first_name, sum_insured and currency fields of
the ZAXX_PERS_INS table to the view
 Define the currency field as currencyCode: @Semantics.currencyCode: true
 Define the currency field as the currency for the sum_insured field:
@Semantics.amount.currencyCode: 'Currency‘
 Define the policy_id and person_id fields as the key of the view
 Define an association to CDS view ZAXX_BO_POLICY
 Cardinality [0..1]
 Join on policy_id

• Define the association type as composition root and parent: @ObjectModel.association.type:


[#TO_COMPOSITION_ROOT, #TO_COMPOSITION_PARENT]

• Define an association to view ZAXX_BO_PERS_INSURED in the ZAXX_BO_POLICY view


 Cardinality [1..*]
 Join on policy_id
 Define the association type as to compositon root and parent:
@ObjectModel.association.type: [#TO_COMPOSITION_CHILD]

Policy View with associations

@AbapCatalog.sqlViewName: 'ZMH_BO_POL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Policy BO View'

@ObjectModel.modelCategory: #BUSINESS_OBJECT
@ObjectModel.compositionRoot: true
@ObjectModel.transactionalProcessingEnabled: true

@ObjectModel.writeActivePersistence: 'ZMH_POLICY'
@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.representativeKey: 'policy_id'

define view ZMH_BO_POLICY as select from zmh_policy as policy


association [1..*] to ZMH_BO_PERS_INS as _personInsured
on policy.policy_id = _personInsured.policy_id
{
key policy_id,
status,
poltype,
pol_holder,
@ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
_personInsured
}

Person Insured View with associations

@AbapCatalog.sqlViewName: 'ZMH_BO_PERSINS'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Person Insured Business Object View'

@ObjectModel.writeActivePersistence: 'ZMH_PERS_INS'
@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.representativeKey: 'person_id'

define view ZMH_BO_PERS_INS as select from zmh_pers_ins as personInsured


association [1..1] to ZMH_BO_POLICY as _policy
on personInsured.policy_id = _policy.policy_id
{
@ObjectModel.foreignKey.association: '_policy'
key policy_id,
key person_id,
name_first,
name_last,
@Semantics.amount.currencyCode: 'curr'
sum_insured,
@Semantics.currencyCode: true
curr,
@ObjectModel.association.type: [#TO_COMPOSITION_ROOT, #TO_COMPOSITION_PARENT]
_policy
}
Exercise 9
• Create a new determination for your ZAXX_BO_POLICY BOPF object which fills the policy ID field
 Name: DETERMINE_ID
 Category: React after modification
 Triggers: Create
 Accept the default for the implementing class
• Implement the EXECUTE method of the determination implementation class
 First retrieve the BO information with the boRetrieve Eclipse template
 Loop over the retrieved BO table lt_zaxx_bo_policy (define a new reference type
lr_zaxx_bo_policy for the loop variable)
 In the loop determine the new policy id via the number range object Z_POL_ID:
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING nr_range_nr = '01'
object = 'ZZMH_POL_ID'
IMPORTING number = lr_zaxx_bo_policy->policy_id.
 Also in the loop, update the BO with Eclipse Template boUpdate. Use the key field of the
lr_zsol_bo_policy variable for the iv_key parameter and the lr_zsol_bo_policy reference
itself for the is_data field
• Define the policy ID in the ZAXX_BO_POLICY view as a read only field: @ObjectModel.readOnly:
true

• Create a new determination for your ZAXX_BO_PERS_INSURED BOPF object which fills the policy
ID field
 Name: DETERMINE_IDS
 Category: React after modification
 Triggers: Create
 Accept the default for the implementing class
• Fill the policy ID with the policy ID of the parent object
 Use the boRetrieveByAssociation Eclipse template
 The template will return a table, you can just read the first entry of that table into a new
reference field lr_zaxx_bo_policy
 In the loop over the person insured, also fill the policy ID before the update
• Define the policy ID and person ID fields in the ZAXX_BO_PERS_INSURED view as read only
fields: @ObjectModel.readOnly: true
• Test your BO

Determination of Policy

CLASS ZCL_MH_D_DETERMINE_ID IMPLEMENTATION.

method /BOBF/IF_FRW_DETERMINATION~EXECUTE.
DATA lt_zmh_bo_policy TYPE ztmhbo_policy.

io_read->retrieve(
EXPORTING
iv_node = zif_mh_bo_policy_c=>sc_node-zmh_bo_policy
it_key = it_key
IMPORTING
et_data = lt_zmh_bo_policy ).

DATA lr_bo_policy TYPE REF TO zsmhbo_policy.

LOOP AT lt_zmh_bo_policy REFERENCE INTO lr_bo_policy.


DATA lv_polid TYPE ZMH_POL_ID.

CALL FUNCTION 'NUMBER_GET_NEXT'


EXPORTING
nr_range_nr = '01'
object = 'ZZMH_POLID'
ignore_buffer = abap_false
quantity = '1'
IMPORTING
number = lv_polid
" quantity =
EXCEPTIONS
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
OTHERS = 7.

IF ( sy-subrc = 0 ).
lr_bo_policy->policy_id = lv_polid.

io_modify->update(
EXPORTING
iv_node = zif_mh_bo_policy_c=>sc_node-zmh_bo_policy
iv_key = lr_bo_policy->key
is_data = lr_bo_policy
).
ENDIF.
ENDLOOP.
endmethod.
ENDCLASS.

Determination of Person Insured

CLASS ZCL_MH_D_DETERMINE_PERS_IDS IMPLEMENTATION.

method /BOBF/IF_FRW_DETERMINATION~EXECUTE.
DATA lt_zmh_bo_pers_ins TYPE ztmhbo_pers_ins.

io_read->retrieve(
EXPORTING
iv_node = zif_mh_bo_policy_c=>sc_node-zmh_bo_pers_ins
it_key = it_key
IMPORTING
et_data = lt_zmh_bo_pers_ins ).

DATA lr_bo_pers_ins TYPE REF TO zsmhbo_pers_ins.

LOOP AT lt_zmh_bo_pers_ins REFERENCE INTO lr_bo_pers_ins.


DATA lt_zmh_bo_policy TYPE ztmhbo_policy.

io_read->retrieve_by_association(
EXPORTING
iv_node = zif_mh_bo_policy_c=>sc_node-zmh_bo_pers_ins
it_key = it_key
iv_association = zif_mh_bo_policy_c=>sc_association-zmh_bo_pers_ins-to_parent
iv_fill_data = abap_true
IMPORTING
et_data = lt_zmh_bo_policy ).

DATA lr_bo_policy TYPE REF TO zsmhbo_policy.

READ TABLE lt_zmh_bo_policy INDEX 1 REFERENCE INTO lr_bo_policy.


IF sy-subrc = 0.
lr_bo_pers_ins->policy_id = lr_bo_policy->policy_id.
ENDIF.

io_modify->update(
EXPORTING
iv_node = zif_mh_bo_policy_c=>sc_node-zmh_bo_pers_ins
iv_key = lr_bo_pers_ins->key
is_data = lr_bo_pers_ins
).
ENDLOOP.

endmethod.
ENDCLASS.
Exercise 10
• Create a new action SET_CANCELLED for the ZAXX_BO_POLICY BO
 Cardinality: Single Instance
 Keep default for implementation class
 Define the exporting parameters of the action (return node ZAXX_BO_POLICY)
• Implement the EXECUTE method of the generated class
 Retrieve the BO
 Loop over the retrieved BO table
 In the loop, set the status field to CANC
 Also, in the loop update the BO
 Test the new action

CLASS ZCL_MH_A_SET_CANCELLED IMPLEMENTATION.

method /BOBF/IF_FRW_ACTION~EXECUTE.
DATA lt_zmh_bo_policy TYPE ztmhbo_policy.

io_read->retrieve(
EXPORTING
iv_node = zif_mh_bo_policy_c=>sc_node-zmh_bo_policy
it_key = it_key
IMPORTING
et_data = lt_zmh_bo_policy ).

DATA lr_bo_policy TYPE REF TO zsmhbo_policy.

READ TABLE lt_zmh_bo_policy INDEX 1 REFERENCE INTO lr_bo_policy.


IF sy-subrc = 0.
lr_bo_policy->status = 'CANC'. " Cancelled

io_modify->update(
EXPORTING
iv_node = zif_mh_bo_policy_c=>sc_node-zmh_bo_policy
iv_key = lr_bo_policy->key
is_data = lr_bo_policy
).
ENDIF.
endmethod.
ENDCLASS.
Exercise 11
• Add a new validation VALIDATE_CURRENCY to the ZAXX_BO_PERS_INSURED BO
 Validation is a consistency check.
 Check has to be executed before saving for the create, update and check triggers
 Keep the default for the implementation class
• Implement the EXECUTE method of the generated class
 Retrieve the BO
 Loop over the retrieved BO table
 If the sum insured field is filled, but the currency field is empty, throw an error message.
• Store message ZAH_MESSAGES 001 with parameters first name and last name in
a local message variable
• Add the message to the eo_message object via the add_message method
(instantiate the eo_message object if that’s not the case yet)
IF eo_message IS NOT BOUND.
eo_message = /bobf/cl_frw_factory=>get_message( ).
ENDIF.
eo_message->add_message( ls_message ).
• Add the key of the BO to the IT_FAILED_KEY table
• Test the validation

CLASS ZCL_MH_V_VALIDATE_CURRENCY IMPLEMENTATION.

method /BOBF/IF_FRW_VALIDATION~EXECUTE.
DATA lt_zmh_bo_pers_ins TYPE ztmhbo_pers_ins.

io_read->retrieve(
EXPORTING
iv_node = zif_mh_bo_policy_c=>sc_node-zmh_bo_pers_ins
it_key = it_key
IMPORTING
et_data = lt_zmh_bo_pers_ins ).

DATA ls_bo_pers_ins TYPE REF TO zsmhbo_pers_ins.


DATA ls_message TYPE symsg.
DATA ls_failed_key TYPE /BOBF/S_FRW_KEY.

LOOP AT lt_zmh_bo_pers_ins REFERENCE INTO ls_bo_pers_ins.


IF ls_bo_pers_ins->sum_insured > 0 AND
ls_bo_pers_ins->curr IS INITIAL.

MESSAGE e001(ZZMH_POL_MESSAGES)
WITH ls_bo_pers_ins->name_first ls_bo_pers_ins->name_last
INTO ls_message.

IF eo_message IS NOT BOUND.


eo_message = /bobf/cl_frw_factory=>get_message( ).
ENDIF.
eo_message->add_message( is_msg = ls_message ).

ls_failed_key-key = ls_bo_pers_ins->key.
APPEND ls_failed_key TO et_failed_key.
ENDIF.
ENDLOOP.
endmethod.
ENDCLASS.
Exercise 12
• Create a new CDS Consumption view ZAXX_C_POLICY based on the policy BO view
 DDIC view ZAXX_C_POL
 Enable Create, Update and Delete processing via annotations
 Delegate transactional processing to the BO view:
@ObjectModel.transactionalProcessingDelegated: true
 Define the Policy ID as the representative key: @ObjectModel.representativeKey:
'Policy_ID‘
 Select all fields of the ZAXX_BO_POLICY view
 Define the Policy ID field as the key and read only field (@ObjectModel.readOnly: true)
 Define the view as consumption view for an Odata service: OData.publish: true
• Register the new service
 Go to the /IWFND/MAINT_SERVICE transaction and click Add Service
 Enter LOCAL as the System Alias in the following screen and search for your service
(name will be ZAXX_C_POLICY_CDS)
 Select your service and click Add Selected Services
• Test your new service in the Gateway client
 In the /IWFND/MAINT_SERVICE select your service and click on SAP Gateway Client in
the ICF Nodes section
 Select the whole connection via
/sap/opu/odata/sap/ZAXX_C_POLICY_CDS/ZAXX_C_POLICY
 Select one entity via /sap/opu/odata/sap/ZAXX_C_POLICY_CDS/ZAXX_C_POLICY(‘<enter
one of the policy IDs you created here>’)

Consumption View

@AbapCatalog.sqlViewName: 'ZMH_C_POL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Policy Consumption View'

@VDM.viewType: #CONSUMPTION
@OData.publish: true

@ObjectModel.transactionalProcessingDelegated: true

@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.representativeKey: 'policy_id'

define view ZMH_C_POLICY as select from ZMH_BO_POLICY as policy


{
key policy_id,
status,
poltype,
pol_holder
}
Exercise 13
• Create a new CDS consumption view ZAXX_C_PERS_INSURED for your person insured BO view
 DDIC view ZAXX_C_PI
 Select all fields of the person insured BO view
 Define the Person ID and Policy ID fields as key fields (read only)
 Create an association _policy to the ZAXX_C_POLICY view on the policy ID field and add
it as a link to the field list
 Define the policy ID field as foreign key with link to the _policy association:
@ObjectModel.foreignKey.association: '_policy‘
 Delegate transactional processing to the BO view
 Enable create, update and delete processing
• Add an association from the ZAXX_C_POLICY view to the ZAXX_C_PERS_INSURED view
• Define the Policy_ID field as the representative key of the view:
@ObjectModel.representativeKey: 'Policy_ID'
• Test your new service in the Gateway client
 Test the association to the _person entity via the policy entity
 Access the _person entity directly via it’s key (Policy_Id=<…>,Person_Id=<…>)

Policy View with Associations

@AbapCatalog.sqlViewName: 'ZMH_C_POL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Policy Consumption View'

@VDM.viewType: #CONSUMPTION
@OData.publish: true

@ObjectModel.transactionalProcessingDelegated: true

@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.representativeKey: 'policy_id'

define view ZMH_C_POLICY as select from ZMH_BO_POLICY as policy


association [1..*] to ZMH_C_PERS_INS as _personInsured
on policy.policy_id = _personInsured.policy_id
{
key policy_id,
status,
poltype,
pol_holder,
_personInsured
}
Person Insured View

@AbapCatalog.sqlViewName: 'ZMH_C_PERSINS'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Person Insured Consumption View'

@VDM.viewType: #CONSUMPTION
@OData.publish: true

@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.representativeKey: 'person_id'

define view ZMH_C_PERS_INS as select from ZMH_BO_PERS_INS as personInsured


association [1..1] to ZMH_C_POLICY as _policy
on personInsured.policy_id = _policy.policy_id
{
key policy_id,
key person_id,
name_first,
name_last,
@Semantics.amount.currencyCode: 'curr'
sum_insured,
@Semantics.currencyCode: true
curr,
_policy
}
Final CDS Views (Exercises 14 and 15)

Policy BO View

@AbapCatalog.sqlViewName: 'ZMH_BO_POL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Policy BO View'

@ObjectModel.modelCategory: #BUSINESS_OBJECT
@ObjectModel.compositionRoot: true
@ObjectModel.transactionalProcessingEnabled: true

@ObjectModel.writeActivePersistence: 'ZMH_POLICY'
@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.representativeKey: 'policy_id'

define view ZMH_BO_POLICY as select from zmh_policy as policy


association [1..*] to ZMH_BO_PERS_INS as _personInsured
on policy.policy_id = _personInsured.policy_id
{
@ObjectModel.readOnly: true
key policy_id,
status,
poltype,
pol_holder,
@ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
_personInsured
}

Person Insured BO View

@AbapCatalog.sqlViewName: 'ZMH_BO_PERSINS'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Person Insured Business Object View'

@ObjectModel.writeActivePersistence: 'ZMH_PERS_INS'
@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.representativeKey: 'person_id'

define view ZMH_BO_PERS_INS as select from zmh_pers_ins as personInsured


association [1..1] to ZMH_BO_POLICY as _policy
on personInsured.policy_id = _policy.policy_id
{
@ObjectModel.foreignKey.association: '_policy'
@ObjectModel.readOnly: true
key policy_id,
key person_id,
name_first,
name_last,
@Semantics.amount.currencyCode: 'curr'
sum_insured,
@Semantics.currencyCode: true
curr,
@ObjectModel.association.type: [#TO_COMPOSITION_ROOT, #TO_COMPOSITION_PARENT]
_policy
}

Policy Consumption View

@AbapCatalog.sqlViewName: 'ZMH_C_POL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Policy Consumption View'

@VDM.viewType: #CONSUMPTION
@OData.publish: true

@ObjectModel.transactionalProcessingDelegated: true

@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.representativeKey: 'policy_id'

@UI.headerInfo.typeName: 'Policy'
@UI.headerInfo.typeNamePlural: 'Policies'
@UI.headerInfo.title.value: 'pol_holder'
@UI.headerInfo.title.type: #STANDARD
@UI.headerInfo.description.value: 'policy_id'
@UI.headerInfo.description.type: #STANDARD

define view ZMH_C_POLICY as select from ZMH_BO_POLICY as policy


association [1..*] to ZMH_C_PERS_INS as _personInsured
on policy.policy_id = _personInsured.policy_id
{
@UI.selectionField.position: 10
@UI.identification.position: 10
@UI.lineItem.position: 10
@UI.lineItem.importance: #HIGH
key policy_id,
@UI.selectionField.position: 20
@UI.identification.position: 20
@UI.lineItem.position: 20
@UI.lineItem.importance: #HIGH
status,
@UI.selectionField.position: 30
@UI.identification.position: 30
@UI.lineItem.position: 30
@UI.lineItem.importance: #HIGH
poltype,
@UI.selectionField.position: 40
@UI.identification.position: 40
@UI.lineItem.position: 40
@UI.lineItem.importance: #HIGH
pol_holder,
_personInsured
}

Person Insured Consumption View

@AbapCatalog.sqlViewName: 'ZMH_C_PERSINS'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Person Insured Consumption View'

@VDM.viewType: #CONSUMPTION
@OData.publish: true

@ObjectModel.createEnabled: true
@ObjectModel.deleteEnabled: true
@ObjectModel.updateEnabled: true

@ObjectModel.representativeKey: 'person_id'

@UI.headerInfo.typeName: 'Person Insured'


@UI.headerInfo.typeNamePlural: 'Persons Insured'
@UI.headerInfo.title.value: 'name_last'
@UI.headerInfo.title.type: #STANDARD
@UI.headerInfo.description.value: 'name_first'
@UI.headerInfo.description.type: #STANDARD

define view ZMH_C_PERS_INS as select from ZMH_BO_PERS_INS as personInsured


association [1..1] to ZMH_C_POLICY as _policy
on personInsured.policy_id = _policy.policy_id
{
@UI.selectionField.position: 10
@UI.identification.position: 10
@UI.lineItem.position: 10
@UI.lineItem.importance: #HIGH
key policy_id,
@UI.selectionField.position: 20
@UI.identification.position: 20
@UI.lineItem.position: 20
@UI.lineItem.importance: #HIGH
key person_id,
@UI.selectionField.position: 30
@UI.identification.position: 30
@UI.lineItem.position: 30
@UI.lineItem.importance: #HIGH
name_first,
@UI.selectionField.position: 40
@UI.identification.position: 40
@UI.lineItem.position: 40
@UI.lineItem.importance: #HIGH
name_last,
@Semantics.amount.currencyCode: 'curr'
@UI.selectionField.position: 50
@UI.identification.position: 50
@UI.lineItem.position: 50
@UI.lineItem.importance: #HIGH
sum_insured,
@Semantics.currencyCode: true
@UI.selectionField.position: 60
@UI.identification.position: 60
@UI.lineItem.position: 60
@UI.lineItem.importance: #HIGH
curr,
_policy
}

You might also like