SAP Cost Center and PM Order Actual and Planned Cost Tables: COSP/COSS Report Generator
This generator writes an ABAP report for SAP ECC 6.0 that reads CO totals for a cost center or an order (internal, maintenance or production) from COSP and COSS and prints plan, actual and variance per cost element for a period range. It shows how CO objects are keyed by OBJNR and how period value fields WKG001 to WKG016 are summed.
Fill in
KS = cost center, OR = internal, PM or production order
WKG controlling area currency, WOG object currency, WTG transaction currency
ABAP report: COSP and COSS plan vs actual
REPORT z_co_plan_actual_cosp_coss.
* Plan vs actual per cost element for a cost center (KS) or order (OR)
* from CO totals tables COSP (primary) and COSS (secondary).
* WRTTP 01 = plan, 04 = actual. LEDNR 00 = standard CO ledger.
TYPES: BEGIN OF ty_res,
kstar TYPE kstar,
plan TYPE p LENGTH 15 DECIMALS 2,
actual TYPE p LENGTH 15 DECIMALS 2,
END OF ty_res.
DATA: lt_cosp TYPE STANDARD TABLE OF cosp,
ls_cosp TYPE cosp,
lt_coss TYPE STANDARD TABLE OF coss,
ls_coss TYPE coss,
lt_res TYPE STANDARD TABLE OF ty_res,
ls_res TYPE ty_res,
lv_objnr TYPE j_objnr,
lv_kostl TYPE kostl,
lv_aufnr TYPE aufnr,
lv_ktopl TYPE ktopl,
lv_ktext TYPE csku-ktext,
lv_var TYPE p LENGTH 15 DECIMALS 2,
lv_tplan TYPE p LENGTH 15 DECIMALS 2,
lv_tact TYPE p LENGTH 15 DECIMALS 2.
START-OF-SELECTION.
* Object number: KS + controlling area + cost center (10), or OR + order (12)
IF 'KS' = 'KS'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = '4110'
IMPORTING
output = lv_kostl.
CONCATENATE 'KS' '1000' lv_kostl INTO lv_objnr.
ELSE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = '4110'
IMPORTING
output = lv_aufnr.
CONCATENATE 'OR' lv_aufnr INTO lv_objnr.
ENDIF.
SELECT * FROM cosp INTO TABLE lt_cosp
WHERE lednr = '00'
AND objnr = lv_objnr
AND gjahr = '2026'
AND versn = '000'
AND wrttp IN ('01', '04').
SELECT * FROM coss INTO TABLE lt_coss
WHERE lednr = '00'
AND objnr = lv_objnr
AND gjahr = '2026'
AND versn = '000'
AND wrttp IN ('01', '04').
LOOP AT lt_cosp INTO ls_cosp.
PERFORM add_periods USING ls_cosp.
ENDLOOP.
LOOP AT lt_coss INTO ls_coss.
PERFORM add_periods USING ls_coss.
ENDLOOP.
SELECT SINGLE ktopl FROM tka01 INTO lv_ktopl
WHERE kokrs = '1000'.
SORT lt_res BY kstar.
WRITE: / 'Object', lv_objnr, 'Year', '2026',
'Periods 1 to 9', 'Value field WKG'.
ULINE.
LOOP AT lt_res INTO ls_res.
CLEAR lv_ktext.
SELECT SINGLE ktext FROM csku INTO lv_ktext
WHERE spras = sy-langu
AND ktopl = lv_ktopl
AND kstar = ls_res-kstar.
lv_var = ls_res-actual - ls_res-plan.
lv_tplan = lv_tplan + ls_res-plan.
lv_tact = lv_tact + ls_res-actual.
WRITE: / ls_res-kstar, lv_ktext, ls_res-plan, ls_res-actual, lv_var.
ENDLOOP.
ULINE.
lv_var = lv_tact - lv_tplan.
WRITE: / 'Total', lv_tplan, lv_tact, lv_var.
* Sums value fields WKG001..016 for the selected periods into lt_res
FORM add_periods USING is_rec TYPE any.
FIELD-SYMBOLS: <lv_val> TYPE any,
<lv_kstar> TYPE any,
<lv_wrttp> TYPE any.
DATA: lv_per TYPE n LENGTH 3,
lv_fname TYPE c LENGTH 30,
ls_line TYPE ty_res.
ASSIGN COMPONENT 'KSTAR' OF STRUCTURE is_rec TO <lv_kstar>.
ASSIGN COMPONENT 'WRTTP' OF STRUCTURE is_rec TO <lv_wrttp>.
ls_line-kstar = <lv_kstar>.
lv_per = 1.
WHILE lv_per <= 9.
CONCATENATE 'WKG' lv_per INTO lv_fname.
ASSIGN COMPONENT lv_fname OF STRUCTURE is_rec TO <lv_val>.
IF sy-subrc = 0.
IF <lv_wrttp> = '01'.
ls_line-plan = ls_line-plan + <lv_val>.
ELSE.
ls_line-actual = ls_line-actual + <lv_val>.
ENDIF.
ENDIF.
lv_per = lv_per + 1.
ENDWHILE.
COLLECT ls_line INTO lt_res.
ENDFORM.
Check in SE11 that COSP and COSS on your release have LEDNR, OBJNR, GJAHR, WRTTP, VERSN, KSTAR and WKG001 to WKG016. ECC uses CO ledger 00; S/4HANA moves actuals to ACDOCA and keeps COSP/COSS only as compatibility views. WTG values are split by transaction currency (TWAER), so summing WTG across currencies is not meaningful. Periods 13 to 16 are special periods.
Get your CO reporting checked
Send us the cost centers, order types and versions you report on and we will confirm which value types and tables reproduce your standard reports.
Optional. The tool and every export work without this. No spam.
Where CO costs are stored in ECC
Controlling stores totals per object, year, value type, version and cost element. COSP holds primary costs posted from FI and MM (cost elements that are G/L accounts) and COSS holds secondary costs from allocations, settlements and activity confirmations, including partner object fields. Every object has an object number OBJNR: KS plus controlling area plus cost center for cost centers, OR plus the 12-digit order number for orders. Amounts sit in one column per period: WKG in controlling area currency, WOG in object currency, WTG in transaction currency.
- WRTTP 01 plan, 04 actual, 21 purchase requisition commitment, 22 purchase order commitment.
- COEP holds actual CO line items for drill-down by document.
- PMCO holds maintenance order costs by value category.
How to use it
Choose KS and enter controlling area, cost center, year, periods and plan version 000, or choose OR and enter a maintenance or production order number (leading zeros are added). Paste the report into SE38 and run it. Each line shows cost element, text from CSKU via the chart of accounts in TKA01, plan, actual and variance (actual minus plan). For commitments, add 21 and 22 to the WRTTP list and a third column. For line items, select COEP with the same OBJNR, GJAHR and period and WRTTP 04.
- Orders have plan values only if planned (unit costing or plan on the order).
- Statistical postings use other value types and are not included.
Worked example
Cost center 4110 in controlling area 1000, year 2026, periods 1 to 9, version 000. Suppose COSP has cost element 476000 with WRTTP 01 and WKG001 to WKG009 of 1,000.00 each, and WRTTP 04 rows summing to 10,400.00. COSS has secondary cost element 943000 (assessment) with plan 4,500.00 and actual 4,200.00. The report prints 476000 plan 9,000.00 actual 10,400.00 variance 1,400.00, and 943000 plan 4,500.00 actual 4,200.00 variance -300.00, total variance 1,100.00. The same numbers appear in S_ALR_87013611 for the cost center and period range.
How to check in the system
For cost centers, compare with S_ALR_87013611 (cost centers: actual/plan/variance) or KSB1 for actual line items. For orders, KOB1 shows line items and the order cost analysis in IW33 or CO03 shows plan and actual by cost element. If the totals differ, check the version, the currency field you summed and whether the standard report includes statistical or commitment values. Remember that settled orders carry the settlement credit under the settlement cost element (in COSS for a secondary settlement cost element, in COSP for a primary one), so an order fully settled can show near-zero net actuals unless you exclude the settlement cost element.
Frequently Asked Questions
Which table stores actual costs of a PM order in SAP ECC?
Totals are in COSP (primary costs such as material and external services) and COSS (secondary costs such as internal activity confirmations), keyed by OBJNR OR plus the order number with WRTTP 04. Line items are in COEP. PMCO summarises maintenance order costs by value category, which the order cost overview uses.
Where are planned costs for a PM order stored?
Estimated and planned costs for maintenance orders are in COSP and COSS with WRTTP 01 and the order's OBJNR, and summarised in PMCO by value category. Planned costs come from the order's operations and components when the order is saved and costed.
Which transaction shows a cost center report in SAP?
S_ALR_87013611 shows cost centers actual/plan/variance, KSB1 shows actual line items, and KSBP plan line items. For a quick total per cost element they read the same COSP and COSS data this report queries. Report Painter reports from GR55 also run on these tables.
What is the OBJNR for a cost center in SAP?
The object number is KS followed by the four-character controlling area and the ten-character cost center, so cost center 4110 in controlling area 1000 is KS10000000004110. Orders use OR plus the 12-digit order number. Every CO totals and line item table uses OBJNR instead of separate cost center or order fields.
If controllers and maintenance planners want to ask ECC about plan versus actual costs in plain English on your own servers, we can build that layer on these CO tables.
Related Tools
SAP ECC Cost Center Hierarchy and Group ABAP Generator (SETHEADER, SETNODE, SETLEAF)
Choose set class, controlling area or chart of accounts and the top node to get ABAP that prints the full group tree, expanding cost center ranges with names.
SAPSAP Controlling (CO) Database Tables Reference
A searchable reference of the SAP tables behind cost centers, internal orders, product costing and material valuation.
SAPSAP Cost Element Categories Reference
A searchable list of SAP CO cost element categories, S/4HANA account types and the master data objects around them.
Developer ToolsSAP ECC BAPI_ACC_DOCUMENT_POST G/L and Vendor Posting ABAP Generator
Enter company code, dates, accounts and amount to get an ABAP report that checks or posts a G/L or vendor invoice document with BAPI_ACC_DOCUMENT_POST.
More Developer Tools tools
See all- SAP ECC Enhancement Transactions and Exit Tables Reference (SMOD, CMOD, SE18, MODSAP, SXC_EXIT)
- SAP ECC Data Dictionary and Repository Tables Reference (DD02L, DD03L, T100, E070, TSTC)
- SAP ECC ABAP Runtime Errors (ST22 Dumps) and Error Log Transactions Reference
- SAP ECC Background Job History ABAP Query Generator (TBTCO + TBTCP)
- SAP ECC Background Job Creation ABAP Generator (JOB_OPEN, SUBMIT, JOB_CLOSE)
- SAP ECC IDoc Segment Data Reader ABAP Generator (EDIDC, EDID4, EDIDS)
- SAP ECC Custom Inbound IDoc Function Module Skeleton Generator
- SAP ECC BAPI_SALESORDER_CHANGE ABAP Generator
- SAP ECC BAPI_PO_CHANGE ABAP Generator
Keep exploring
Free tools
- SAP ECC Cost Center Hierarchy and Group ABAP Generator (SETHEADER, SETNODE, SETLEAF)Choose set class, controlling area or chart of accounts and the top node to get ABAP that prints the full group tree, expanding cost center ranges with names.
- SAP ECC BAPI_PO_CHANGE ABAP GeneratorGenerate a working ABAP program that changes an SAP purchase order item with BAPI_PO_CHANGE, with POITEM/POITEMX, schedule line date conversion, test run and commit handling.
- SAP ECC Private AI Layer Blueprint GeneratorFill in your version, database, hosting and use cases to get an architecture plan for adding a private, on-prem AI assistant to SAP ECC 6.0, with components, security controls and a three-phase rollout.
ERP fixes and how-tos
- SAP KI 235: G/L Account Requires an Assignment to a CO ObjectSAP KI 235 fires when a P&L G/L account has no cost element or the posting carries no valid CO account assignment. Fix it with KA01/KA02 or a default assignment.
- How to add AI to SAP ECC 6.0 on-prem without moving data to a cloudReference architecture for a private on-prem AI assistant on SAP ECC 6.0: RFC and BAPI reads, SLT replica, retrieval index, local LLM, permission mirroring.
- How to create a routing, work center and production supervisor in SAP PPSet up SAP PP master data: create a work center with CR01, a routing with CA01, and a production supervisor with OPJ2, plus the production version link.
Runs with your ERP
- Loftware with SAP ECC and S/4HANA: label design and printing from SAP transactionsHow Loftware and the NiceLabel ABAP package drive labels from SAP ECC and S/4HANA, including SAP GLM Plus, data flows, setup steps and pitfalls to avoid.
- PROGATE 6.0 Interface with SAP ECC and S/4HANAPROGATE is an SAP-certified web service interface that sends master data and orders from SAP to third-party MES and returns confirmations. Setup and pitfalls.
Integrations
- How to use ChatGPT with SAP ECC 6.0Using ChatGPT with SAP ECC 6.0: custom GPT actions, exports versus live access, an OData or MCP bridge, enterprise data controls, and when a private model is safer.
- How to add AI agents to SAP ECC 6.0How to add AI agents to SAP ECC 6.0: a tool layer over BAPIs, RFC and IDocs, human approval before any posting, and an on-prem model that never leaves your network.