# Cost Element Management

## Overview

Cost Element Management provides the foundational classification layer for management accounting within the accounting module. Cost elements define the types of costs that can be recorded, allocated, and analyzed across cost centers, profit centers, and internal orders. The module distinguishes two fundamental categories: primary cost elements, which are mapped one-to-one to GL accounts from coa-management and represent costs that appear in both financial and management accounting (e.g., material costs, labor costs, depreciation), and secondary cost elements, which exist exclusively within the controlling domain and are used solely for internal cost allocation activities such as assessment, distribution, and settlement.

Every cost posting or allocation in the accounting module requires a valid cost element, making this feature a prerequisite for all downstream management accounting processes. Primary cost elements bridge financial accounting and controlling by linking each cost type to its corresponding GL account, ensuring consistency between the general ledger and cost reports. Secondary cost elements enable internal cost flows that have no counterpart in financial reporting, allowing organizations to model overhead distribution, activity-based costing, and inter-departmental service charges. Cost elements are scoped to a Company and carry validity periods to support time-dependent cost classifications.

## Business Purpose

Organizations need a structured cost element catalog to classify and control cost flows in management accounting:

- **Cost type classification**: Cost elements categorize expenditures into meaningful types (overhead, material, labor, depreciation for primary; assessment, distribution, internal activity allocation, settlement for secondary), enabling consistent cost reporting and analysis across the organization
- **Bridge between financial and management accounting**: Primary cost elements maintain a mandatory one-to-one mapping to GL accounts from coa-management, ensuring that every cost recorded in the general ledger can be consumed by controlling processes without discrepancy
- **Internal allocation enablement**: Secondary cost elements provide cost types that exist only within controlling, allowing organizations to model internal cost flows (e.g., IT department charging other departments for services) without polluting financial statements
- **Prerequisite for cost postings**: No cost can be posted to a cost center, profit center, or internal order without a valid cost element. This gating mechanism enforces a complete and auditable cost classification before any transaction occurs
- **Time-dependent validity**: Valid-from and valid-to dates on cost elements allow organizations to phase in new cost types or retire obsolete ones without deleting historical data, supporting period-accurate cost reporting
- **Company-scoped isolation**: Cost elements are defined per company, ensuring that each legal entity maintains its own cost classification structure aligned with its chart of accounts and management reporting requirements
- **Regulatory and ERP alignment**: The primary/secondary distinction mirrors the cost element model used by SAP, Oracle, and other major ERP systems, facilitating migration, integration, and compliance with established management accounting practices

## Process Flow

```mermaid
stateDiagram-v2
    [*] --> Draft: createCostElement
    Draft --> Draft: updateCostElement
    Draft --> Active: activateCostElement
    Active --> Inactive: deactivateCostElement
    Inactive --> Active: reactivateCostElement
    Draft --> [*]: deleteCostElement
```

```mermaid
flowchart TD
    A[Identify cost type to classify] --> B{Primary or Secondary?}
    B -- Primary --> C[Select GL account from coa-management]
    C --> D[Create primary cost element with GL account reference]
    B -- Secondary --> E[Create secondary cost element without GL account]
    D --> F[Set category, validity period, and description]
    E --> F
    F --> G[Activate cost element]
    G --> H[Cost element available for cost postings and allocations]
```

```mermaid
flowchart TD
    A[Cost posting or allocation initiated] --> B{Cost element specified?}
    B -- No --> C[Reject: cost element required]
    B -- Yes --> D{Cost element active and within validity period?}
    D -- No --> E[Reject: invalid or expired cost element]
    D -- Yes --> F{Primary cost element?}
    F -- Yes --> G{Referenced GL account active in active CoA?}
    G -- No --> H[Reject: GL account invalid]
    G -- Yes --> I[Accept cost posting]
    F -- No --> J{Used in allocation context only?}
    J -- No --> K[Reject: secondary elements for internal allocation only]
    J -- Yes --> I
```

## Scenario Patterns

- **Overhead Cost Element Setup**: A controller creates a primary cost element for "Office Rent" mapped to the corresponding rent expense GL account. The element is categorized as an overhead cost, given a validity period spanning the fiscal year, and activated. All rent postings to cost centers now reference this cost element for consistent overhead reporting
- **Material Cost Classification**: During initial system setup, the accounting team creates primary cost elements for each material cost category (raw materials, packaging, consumables), each mapped to its respective GL account from the chart of accounts. These elements enable material cost tracking across cost centers and internal orders
- **Labor Cost Tracking**: Primary cost elements are created for different labor cost types (salaries, wages, overtime, benefits), each referencing the appropriate payroll expense GL account. Cost center managers can then analyze labor costs by type within their responsibility areas
- **Depreciation Cost Element**: A primary cost element for asset depreciation is created and mapped to the depreciation expense GL account. This enables depreciation charges calculated by the asset module to flow into cost center reports as a distinct cost type
- **Assessment Cycle Preparation**: A controller creates a secondary cost element of category "assessment" to be used in the monthly overhead assessment cycle. This element does not reference any GL account and will only appear in cost center reports when the assessment allocation distributes shared service costs
- **Internal Activity Allocation**: A secondary cost element of category "internal activity allocation" is created for IT services. When the IT cost center allocates its costs to receiving cost centers based on service hours, this secondary element classifies the allocated amounts, keeping them separate from primary cost postings
- **Settlement to Profitability**: A secondary cost element of category "settlement" is created to settle accumulated costs from an internal order to a profit center. The settlement posting uses this element to classify the cost transfer, which remains invisible in financial accounting
- **Cost Element Retirement**: At the end of a fiscal year, a controller deactivates a cost element that is no longer relevant due to organizational restructuring. Existing historical postings referencing this element remain intact, but no new postings can use it
- **Cross-Company Cost Element Alignment**: Two subsidiaries each maintain their own cost element catalogs. Although the element codes and categories may align for consolidated reporting, each company's primary cost elements reference GL accounts from their respective charts of accounts

## Test Cases

- Cost element can be created in DRAFT status with a unique code within the company scope
- Cost element requires a valid companyId; the company must be in ACTIVE status
- Cost element code must be unique within the same company
- Cost element requires a name and a type (PRIMARY or SECONDARY)
- Cost element requires a category appropriate to its type (overhead, material, labor, depreciation for PRIMARY; assessment, distribution, internal_activity_allocation, settlement for SECONDARY)
- Primary cost element must reference a valid GL account from an ACTIVE Chart of Accounts
- Primary cost element GL account reference must point to an active GL account
- Primary cost element creation fails if the GL account reference is missing
- Primary cost element creation fails if the referenced GL account does not exist or is inactive
- Secondary cost element must not reference a GL account; providing a GL account reference for a secondary element is rejected
- Cost element valid-from date must be before or equal to valid-to date
- Cost element valid-from and valid-to dates are optional; omitting them means the element is valid indefinitely
- Cost element description is optional and can be updated while in DRAFT or ACTIVE status
- Activating a DRAFT cost element transitions its status to ACTIVE
- Activating an already ACTIVE cost element fails with an invalid status transition error
- Deactivating an ACTIVE cost element transitions its status to INACTIVE
- Reactivating an INACTIVE cost element transitions its status back to ACTIVE
- Only DRAFT cost elements can be deleted; ACTIVE and INACTIVE elements cannot be deleted
- Deleting a DRAFT cost element removes it and emits an audit event
- Cost postings referencing a cost element that is INACTIVE or outside its validity period are rejected
- Cost postings referencing a cost element that is ACTIVE and within its validity period are accepted
- A primary cost element cannot be assigned a secondary category (assessment, distribution, internal_activity_allocation, settlement)
- A secondary cost element cannot be assigned a primary category (overhead, material, labor, depreciation)
- Changing the type of a cost element (PRIMARY to SECONDARY or vice versa) after activation is not permitted
- Changing the GL account reference of a primary cost element after activation is not permitted
- Secondary cost elements can only be used in internal allocation contexts (assessment, distribution, activity allocation, settlement)
- Attempting to use a secondary cost element for a direct cost posting (non-allocation) is rejected
- Cost elements are scoped to a company; elements from different companies are fully isolated
- A primary cost element's GL account must belong to the same company's chart of accounts
- Two primary cost elements within the same company cannot reference the same GL account
- Updating the category of an ACTIVE cost element is not permitted
- Cost element creation emits an audit event recording the acting user, timestamp, and initial field values
- Cost element activation emits an audit event recording the status transition and acting user
- Cost element deactivation emits an audit event recording the status transition and acting user

## Reference Links

- [SAP Cost Element Accounting](https://help.sap.com/docs/SAP_S4HANA_ON-PREMISE/ee3509643e954b3da2e0ebfa846c02e1/4cae4c5eecaa7286e10000000a42189b.html)
- [SAP Primary and Secondary Cost Elements](https://help.sap.com/docs/SAP_ERP/ba879a6e2ea04d9bb94c7ccd7cdac446/89d8463bf4f84033e10000000a174cb4.html)
- [Oracle Cost Management Overview](https://docs.oracle.com/en/cloud/saas/financials/24d/oafcf/cost-management.html)
- [Controlling with Cost Elements in SAP S/4HANA](https://community.sap.com/topics/s4hana/cost-elements)
