0% found this document useful (0 votes)
81 views5 pages

18 Hierarchies

This document contains definitions for several CDS views and a hierarchy for modeling employee and manager data. It defines views for flight meal consumption, basic employee and manager data, joining employee hours with the employee hierarchy, and interfaces for the employee hierarchy. It also includes the code for an action class for approving flight meals and a report to retrieve data from the employee hierarchy.

Uploaded by

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

18 Hierarchies

This document contains definitions for several CDS views and a hierarchy for modeling employee and manager data. It defines views for flight meal consumption, basic employee and manager data, joining employee hours with the employee hierarchy, and interfaces for the employee hierarchy. It also includes the code for an action class for approving flight meals and a report to retrieve data from the employee hierarchy.

Uploaded by

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

@AbapCatalog.

sqlViewName: 'ZCJANFLIGHTM'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Flight Meal Consumption CDS view'
@VDM.viewType: #CONSUMPTION
@OData.publish: true

@ObjectModel: {
modelCategory: #BUSINESS_OBJECT,compositionRoot: true,
transactionalProcessingEnabled: true,
createEnabled: true,
updateEnabled: true,
deleteEnabled: true,
writeActivePersistence: 'ZOFT_MEAL',
draftEnabled: true,
writeDraftPersistence: 'ZOFT_MEALJAN'
}

define view ZC_JAN_FLIGHT_M as select from zoft_meal as fmeal


association [1] to scarr as _Carrier
on $projection.carrid = _Carrier.carrid
association[1] to sflight as _Connection
on $projection.connid = _Connection.connid and
$projection.carrid = _Connection.carrid
association[1] to smeal as _Meals
on $projection.meal = _Meals.mealnumber
{
key meal_id,
@UI.selectionField: [{position: 10 }]
@UI.lineItem: [{ position: 10 }]
@UI.identification: [{position: 10 }]
@ObjectModel.foreignKey.association: '_Carrier'
carrid,
@UI.selectionField: [{position: 20 }]
@UI.lineItem: [{ position: 10 }]
@UI.identification: [{position: 11 }]
connid,
@UI.lineItem: [{ position: 30 }]
@UI.identification: [{position: 20 }]
meal,
@UI.lineItem: [{ position: 40 }]
@UI.identification: [{position: 30 }]
total_seats,
@UI.lineItem: [{ position: 50, type: #FOR_ACTION,
label: 'Approve', dataAction: 'BOPF:APPRO' }]
@UI.identification: [{position: 40 }]
status,
_Carrier,
_Connection,
_Meals
}

Hierarchy Classical

@AbapCatalog.sqlViewName: 'ZJANPEMP'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Basic Private view on emp manager'
@VDM.viewType: #BASIC
@Analytics.dataCategory: #DIMENSION

define view ZATS_P_EMPLOYEE as select from zoft_emp_mgr {


//ZOFT_EMP_MGR
key empid,
empname,
managerid,
costcenter
}

class ZCL_C_A_APPROVE definition


public
inheriting from /BOBF/CL_LIB_A_SUPERCL_SIMPLE
final
create public .

public section.

methods /BOBF/IF_FRW_ACTION~EXECUTE
redefinition .
protected section.
private section.
ENDCLASS.

CLASS ZCL_C_A_APPROVE IMPLEMENTATION.


method /BOBF/IF_FRW_ACTION~EXECUTE.
"Step 1: Hey bopf gime the data
data: lt_data type ZTCJAN_FLIGHT_M.
io_read->retrieve(
EXPORTING
iv_node = is_ctx-node_key
it_key = it_key
* iv_before_image = abap_false
* iv_fill_data = abap_true
* it_requested_attributes =
IMPORTING
* eo_message =
et_data = lt_data
* et_failed_key =
* et_node_cat =
).
"Step 2: Modify
READ table lt_data REFERENCE INTO data(lo_data) INDEX 1 .
lo_data->status = abap_true.
"Step 3: Before anything happens update
io_modify->update(
EXPORTING
iv_node = is_ctx-node_key
iv_key = lo_data->key
* iv_root_key =
is_data = lo_data
* it_changed_fields =
).
endmethod.
ENDCLASS.

Table structure for Emp and Manager

@EndUserText.label : 'OFT Employee Manager Data'


@AbapCatalog.enhancementCategory : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
define table zoft_emp_mgr {
key mandt : mandt not null;
key empid : zpernr_d not null;
key empname : char100 not null;
managerid : zpernr_d;
costcenter : kostl;

@AbapCatalog.sqlViewName: 'ZATSEMPNEW'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Normal CDS with Self Ref as pre-requisite for hier'
define view ZSELF_REF_FOR_HIER as select from zoft_emp_mgr
association[1..*] to ZSELF_REF_FOR_HIER as _Manager on
$projection.Manager = _Manager.Employee
{
//zoft_emp_mgr
key empid as Employee,
key empname as EmployeeName,
managerid as Manager,
costcenter as CostCenter,
_Manager
}

define hierarchy ZJAN_NEW_HIER


as parent child hierarchy (
source ZSELF_REF_FOR_HIER
child to parent association _Manager
siblings order by Employee ascending
multiple parents allowed
)
{
key Employee,
Manager,
$node.node_id as NodeId,
$node.parent_id as ParentId,
$node.hierarchy_level as HLevel,
$node.hierarchy_is_cycle as Cycle,
$node.hierarchy_is_orphan as Orphan,
$node.hierarchy_parent_rank as ParentRank,
$node.hierarchy_rank as HierRank,
$node.hierarchy_tree_size as TreeSize
}

*&---------------------------------------------------------------------*
*& Report zjan_hier_call
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zjan_hier_call.

PARAMETERS : mgrid type zoft_emp_mgr-managerid.

select * from HIERARCHY_DESCENDANTS( SOURCE ZJAN_NEW_HIER


START WHERE manager = @mgrid ) into table @data(itab).

cl_demo_output=>display_data(
EXPORTING
value = itab
* name =
).

@AbapCatalog.sqlViewName: 'ZJANHCLASS'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Interface Basic Hierarchy Classical'
@Hierarchy.parentChild: [{
name: 'EmployeeMgr',
recurse: { parent: ['Manager' ], child: ['Employee'] }
}]
define view ZATS_I_EMPMGR as select from ZATS_P_EMPLOYEE
association[1..*] to ZATS_P_EMPLOYEE as _Manager on
$projection.empid = _Manager.empid
{
//ZATS_P_EMPLOYEE
@EndUserText.label: 'Employee Id'
@ObjectModel.text.element: ['EmployeeName']
key ZATS_P_EMPLOYEE.empid as Employee,
@EndUserText.label: 'Employee Name'
ZATS_P_EMPLOYEE.empname as EmployeeName,
@EndUserText.label: 'Manager Id'
ZATS_P_EMPLOYEE.managerid as Manager,
@EndUserText.label: 'Cost Center'
ZATS_P_EMPLOYEE.costcenter as CostCenter,
//_Manager
key _Manager
}

@AbapCatalog.sqlViewName: 'ZCOEMPHRS'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'join time recording with Emp Mgr Hierarchy'
@VDM.viewType: #COMPOSITE
@Analytics.dataCategory: #CUBE

define view ZATS_CO_EMPHOURS as select from zoft_emp_hrs as hrs


association[0..1] to ZATS_I_EMPMGR as _Employee on
hrs.empid = _Employee.Employee
association[1] to csks as _CostCenter on
$projection.CostCenter = _CostCenter.kostl
{

key empid,
@DefaultAggregation: #SUM
@EndUserText.label: 'Planned Effort'
planned,
@DefaultAggregation: #SUM
@EndUserText.label: 'Actual Effort'
recorded,
_Employee.CostCenter as CostCenter,
_CostCenter,
_Employee
}

You might also like