@AbapCatalog.sqlViewName: 'FINOCV_RULE_ORDB'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@ClientHandling.algorithm: #SESSION_VARIABLE
@ObjectModel.usageType.dataClass: #TRANSACTIONAL
@ObjectModel.usageType.serviceQuality: #C
@ObjectModel.usageType.sizeCategory: #XL
@Metadata.ignorePropagatedAnnotations: true
@EndUserText.label: 'Orgl Change-Rule: Order Base'
// This view returns all orders with necessary attributes to be used in rules:
// - FINOC_RULE_ORD_DEFAULT is the default implementation, identifying all orders that have derived their profit center (PRCTR) from the material.
// - FINOC_RULE_ORD_EXAMPLE demonstrates how a customer implementation could look like.
// It identifies orders that have have either a cost object assignment which is active and not marked for deletion or similarly,
// or that have no cost object assignment, but which are not completed or within a certain customizable time period after creation and completed.
// The result is cross-joined with all non-completed org changes to identify an effective date to join potential entries from runtime tables to determine a
// prctr old, i.e. the profit center that has been assigned to the object before org change processing.
// The runtime engine of "Organizational Changes" will call the view with a restriction to the organizational changes, so that the cross join does not
// effect in a table with more than one org change.
define view FINOC_RULE_ORD_BASE
as
// select production cost controlling orders, dependent on material
select from aufk as AufkOrder
inner join finoc_orglchg as OrglChange on OrglChange.processing_status <> 'CMP' // only not yet completed org changes
left outer join afpo as AufkOrderItem on AufkOrder.aufnr = AufkOrderItem.aufnr
and AufkOrderItem.posnr = '0001'
left outer join jest as StatusObject on AufkOrder.objnr = StatusObject.objnr
and(
StatusObject.inact = ' '
and(
StatusObject.stat = 'I0046' // closed
or StatusObject.stat = 'I0076' // deletion flag
or StatusObject.stat = 'I0013' // deletion indicator
)
)
left outer to one join finoc_rt_ord as RuntimeOrder on RuntimeOrder.aufnr = AufkOrder.aufnr
and RuntimeOrder.orgl_change = OrglChange.orgl_change
and RuntimeOrder.reassgmt_status = 'DONE'
{
key AufkOrder.aufnr,
key OrglChange.orgl_change,
AufkOrder.kokrs,
AufkOrder.bukrs,
coalesce( RuntimeOrder.prctr_old, AufkOrder.prctr ) as prctr_old,
cast( ' ' as finoc_prctr_new preserving type ) as prctr, // new profit center
AufkOrder.autyp,
cast( ' ' as finoc_prctr_drvtn_source_type preserving type ) as prctr_drvtn_source_type,
cast( ' ' as finoc_srce_werks preserving type ) as srce_werks,
cast( ' ' as finoc_srce_matnr preserving type ) as srce_matnr,
cast(' ' as finoc_srce_kostl preserving type) as srce_kostl,
cast('00000000' as finoc_srce_ps_psp_pnr preserving type) as srce_ps_psp_pnr,
cast('00000000' as finoc_srce_ps_prj_pnr preserving type) as srce_ps_prj_pnr,
AufkOrderItem.matnr,
AufkOrderItem.dwerk as werks,
AufkOrder.pspel as ps_psp_pnr,
AufkOrder.objnr,
OrglChange.effective_date,
AufkOrder.kostv,
AufkOrder.kostl
}
where
StatusObject.stat is null // not closed or having deletion flag or indicator
// in scope of reorg, i.e. material related orders
and(
(
AufkOrder.autyp = '04' // CO Production Order
or AufkOrder.autyp = '05' // Production Cost Collector
or AufkOrder.autyp = '10' // PP Production Order
or AufkOrder.autyp = '40' // Process Order
)
and AufkOrderItem.posnr is not null
// or non-material related orders
or(
AufkOrder.autyp = '01' // Internal Order
or AufkOrder.autyp = '06' // QM Order
or AufkOrder.autyp = '30' // Maintenance Order
or AufkOrder.autyp = '20' // Network
)
)
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"AFPO",
"AUFK",
"FINOC_ORGLCHG",
"FINOC_RT_ORD",
"JEST"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/