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, and that you can read a basic Open SQL SELECT with a join. It covers the rule that links plants to company codes, how the link is stored, and the errors it causes.
The rule
Every plant belongs to exactly one company code. A company code can have many plants. The assignment is many-to-one, from plant to company code.
The reason is accounting. Stock in a plant has a value, and that value has to be posted to the books of one legal entity. If a plant could belong to two company codes, the system could not decide which ledger receives a goods receipt.
Because the assignment is fixed per plant, a plant cannot be shared between legal entities. If two entities both use a physical site, you set up two plants, one under each company code.
The path goes through the valuation area
The assignment is not stored directly between the plant and the company code. It goes through the valuation area, which is the level at which inventory is valued.
- The plant (table
T001W) carries a valuation area key in the fieldBWKEY. - The valuation area (table
T001K) carries the company code in the fieldBUKRS.
In almost all systems the valuation level is the plant, so BWKEY has the same value as the plant key WERKS. The two-step path is still how the data is stored, and queries should follow it.
Reading the assignment in a query
This query joins T001W to T001K on the valuation area. It shows which company code each plant belongs to.
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.The join condition is k~bwkey = w~bwkey, not a comparison on WERKS. This works whether the valuation area equals the plant or covers several plants. A plant with no matching row in T001K is missing from the result because of the inner join. That is useful when you check for incomplete setup.
Maintaining the assignment
You make the assignment in customizing, in the implementation guide (transaction SPRO). The path is Enterprise Structure, Assignment, Logistics - General, Assign Plant to Company Code. The direct transaction is OX18. You define the plant first, with OX10, and the company code must already exist.
Assign only after the organisational units exist. Changes then go through your normal transport requests, so the same assignment reaches the test and production systems.
Common errors
| Symptom | Likely cause |
|---|---|
| A plant does not appear in a join with `T001K` | The plant has no valuation area, or the valuation area has no company code |
| A material cannot be created for a plant | The plant is not assigned to a company code, so accounting data cannot be created |
| A plant shows an unexpected company code | The query joined on `WERKS` instead of `BWKEY` |
| Intercompany postings appear where none were expected | Two plants of one site were assigned to different company codes |
Check your understanding
Exercise
A company has two legal entities, each with its own books. Both use one physical warehouse building. How do you model this, and why can't one plant serve both?
Show answer
Create two plants, one assigned to each company code. A plant belongs to exactly one company code, because its stock value must be posted to one legal entity's ledger. A single plant assigned to both would leave the system unable to decide which ledger receives a goods receipt.
Exercise
Why does the query above join T001W and T001K on BWKEY and not on WERKS?
Show answer
The company code is stored on the valuation area in T001K. A plant reaches it through its BWKEY field. BWKEY usually equals the plant key, but the join on BWKEY stays correct when the valuation area is something other than the plant.