Sub topic 6
How plants are assigned to company codes
This chapter assumes you know what a client, a company code, and a plant are, as covered in the earlier chapters. You should also be able to read a simple Open SQL SELECT with a join.
The rule in one sentence
Each plant belongs to exactly one company code. Each company code can own any number of plants. The relationship is many-to-one: many plants point to one company code.
This is what ties operations to accounting. A plant is an operational site, such as a factory or distribution centre. A company code is the unit that produces a balance sheet and a profit and loss statement. When a plant receives goods, consumes materials, or ships products, the system must know which company code books the resulting financial postings. The assignment gives that answer without asking the user.
Why exactly one company code
Consider what would happen if a plant could belong to two company codes. A goods receipt of 100 pieces into that plant would create a valuation posting. The system could not decide which legal entity owns the inventory. Stock value, cost of goods sold, and goods receipt/invoice receipt clearing accounts would be ambiguous.
The one-to-one direction from plant to company code removes the ambiguity. The system derives the company code from the plant on every material movement, and the user never enters it.
The reverse direction is flexible. A company code with no plants is valid, for example a holding company that only does financial accounting. A company code with fifty plants is also normal.
The diagram also shows that storage location 0001 appears under two different plants. A storage location is unique only inside its plant. That is covered in its own chapter.
How the assignment is stored: the valuation area link
The assignment is not stored as a direct field "company code" on the plant table. It passes through the valuation area, which is the organisational level at which inventory is valued.
The chain looks like this:
- The plant table
T001Wholds the plant (WERKS) and a fieldBWKEY, the valuation area. - The table
T001Kholds valuation areas. Its key isBWKEY, and it has a fieldBUKRS, the company code. - Joining
T001WtoT001KonBWKEYgives the company code of each plant.
In most installations the valuation area equals the plant, so BWKEY has the same value as WERKS. Then the chain is effectively plant to company code. The indirection exists because SAP lets you choose the valuation level, as described below.
| Table | Content | Relevant fields |
|---|---|---|
| `T001W` | Plants | `WERKS` (plant), `NAME1` (name), `BWKEY` (valuation area) |
| `T001K` | Valuation areas | `BWKEY` (valuation area), `BUKRS` (company code) |
| `T001` | Company codes | `BUKRS`, `BUTXT` (name), `WAERS` (currency) |
Reading the assignment with Open SQL
This report lists plants with their company codes. It uses the join from the topic: valuation area BWKEY links the two tables.
REPORT z_plant_company_code.
SELECT w~werks,
w~name1,
k~bukrs
FROM t001w AS w
INNER JOIN t001k AS k ON k~bwkey = w~bwkey
INTO TABLE @DATA(lt_plants)
UP TO 20 ROWS.
cl_demo_output=>display( lt_plants ).Each row has one plant and one company code. A plant never appears twice, which is the one-company-code rule seen in the data. If you drop UP TO 20 ROWS and group by company code, you can count the plants each company code owns:
REPORT z_plants_per_company_code.
SELECT k~bukrs,
COUNT( * ) AS plant_count
FROM t001w AS w
INNER JOIN t001k AS k ON k~bwkey = w~bwkey
GROUP BY k~bukrs
ORDER BY k~bukrs
INTO TABLE @DATA(lt_counts).
cl_demo_output=>display( lt_counts ).Both queries use an inner join. A plant whose valuation area has no entry in T001K is silently dropped from the result. That usually points to an incomplete configuration, so it is worth checking when a plant seems to be missing.
Valuation level: plant or company code
The valuation level decides how material prices and stock values are kept. You choose it once per client in customizing. There are two options:
- Plant level. Each plant is its own valuation area. A material can have a different price in each plant. This is the standard choice and is almost universal.
- Company code level. All plants of a company code share one valuation area. A material has one price across the company code.
At plant level, T001W-BWKEY equals the plant number. At company code level, BWKEY equals the company code. The join in the examples above works either way, because it relies only on BWKEY.
SAP strongly recommends plant level. It is required by several components, such as Production Planning and Product Cost Controlling, which need plant-specific costing. The valuation level also cannot be changed once material master records exist, so this choice must be made at the start.
Assigning a plant in customizing
You work with plants and company codes in the Implementation Guide (IMG), reached through transaction SPRO. The relevant transactions are:
| Transaction | Purpose |
|---|---|
| `OX02` | Define or edit company codes |
| `OX10` | Define, copy, delete, and check plants |
| `OX14` | Define the valuation level |
| `OX18` | Assign a plant to a company code |
The usual order is:
- Define the company code (
OX02). - Define the plant (
OX10). - Assign the plant to the company code (
OX18).
Plants are created in a development or customizing client and transported to the test and production systems, in the same way as other customizing. You do not create them directly in production.
When the assignment can no longer change
The assignment is easy to set and hard to change. Once a plant has any of the following, SAP blocks or strongly discourages reassigning it:
- Material master records with accounting views for that plant.
- Stock quantities or valuation data.
- Material documents and accounting documents posted through the plant.
- Open purchase orders, production orders, or other operational documents.
The reason is that historical documents carry the old company code. Moving the plant would leave stock valued under one legal entity and its history booked under another.
What the assignment drives
Because the company code is derived from the plant, it controls several things for every plant transaction:
- Currency. Valuation and postings use the company code currency from
T001-WAERS. - Chart of accounts. The company code references one chart of accounts, and the automatic account determination for inventory postings uses it.
- Fiscal year variant. Period posting rules come from the company code.
- Automatic postings. A goods receipt posts to inventory and clearing accounts of that company code. The accounts are found through the valuation class of the material and the valuation area, via transaction
OBYC.
Plants in different company codes can therefore have very different accounting behaviour, even though they share a client and a material master.
Cross-company-code movements
A stock transfer between two plants of the same company code is a pure inventory movement. No legal entity changes, so no sale takes place.
A transfer between plants of different company codes is different. Ownership of the goods moves from one legal entity to another. The system must record a payable and receivable between the two, normally through intercompany processes such as a stock transport order with intercompany billing. This extra effort is the practical cost of having several company codes, and it is one reason to avoid splitting company codes without a legal need.
Other units that depend on the assignment
Other organisational units use the plant and company code link to stay consistent.
- A purchasing organisation can be assigned to a company code and to plants. A purchasing organisation can be assigned to several plants, and a plant can be linked to several purchasing organisations. Orders for a plant are checked against these links.
- A controlling area groups company codes for management accounting. All company codes in a controlling area must share the same chart of accounts, which indirectly limits which plants can share a controlling area.
These are covered in a later chapter. For now, note that the plant-to-company-code assignment is the base on which the other links are built.
Common mistakes
- Assigning plants after loading data. Master data created before the assignment is complete causes inconsistencies. Set up the full structure first.
- Creating a plant per warehouse. A physical building does not need its own plant. If a building only holds stock and has no separate planning or costing, a storage location under an existing plant is often enough.
- Confusing company code with plant in reports. Filtering stock reports by company code works only through the valuation area. Selecting from
MARDonBUKRSfails becauseMARDhas no company code field. - Assuming
BWKEYalways equals the plant. The join in this chapter works at either valuation level. A shortcut that comparesWERKStoBWKEYdirectly breaks if the system uses company code level valuation. - Splitting company codes for reporting. Use controlling areas, profit centres, or business areas for management views. Create a new company code only when a separate legal entity or ledger is needed.
Exercise
A new plant 3000 is created in a system that values inventory at plant level. The business asks you to "move plant 3000 to company code 2000" three months after go-live, when stock and documents already exist. Explain why this is a problem, and name the join you would use to confirm the current company code of plant 3000.
Show answer
Plant 3000 is assigned to one company code, and all its existing stock valuations and material and accounting documents carry that company code. Reassigning the plant would leave history booked to the old legal entity and new postings in the new one, so SAP does not allow it in a normal way once data exists. The usual solution is to create a new plant under company code 2000 and transfer the stock with documented movements. To confirm the current assignment, join T001W to T001K on BWKEY and read BUKRS for WERKS = '3000'. For example: SELECT SINGLE k~bukrs FROM t001w AS w INNER JOIN t001k AS k ON k~bwkey = w~bwkey WHERE w~werks = '3000' INTO @DATA(lv_bukrs).
Exercise
Why does the join between T001W and T001K use BWKEY and not WERKS, and what would BWKEY contain if the valuation level were set to company code?
Show answer
The plant is linked to a company code through its valuation area, and T001K is keyed by valuation area (BWKEY), not by plant. With plant-level valuation, BWKEY equals the plant number, so it looks as if WERKS were used. With company-code-level valuation, BWKEY contains the company code, and all plants of that company code share one valuation area. Joining on BWKEY works in both cases.