Purpose
You create a Sales order and in profitability segment of the order you expect to derive the Cost Element. This WIKI explains why this requirement is not possible and what is the standard system behaviour.
Overview
It is not possible to derive the cost element because the source field COPA-KSTAR is not available during billing. Problem is that cost element is not filled in CO-PA (Profitability Analysis) when transferring values from SD (Sales and Distribution). The reason is that we transfer several conditions (each condition can be assigned to a different cost element) with one line item to CO-PA. So it would not make sense to choose any of the affected cost elements by chance to the line item as the line item stands for several cost elements.
Explanation of system behavior
This is the correct system behaviour. The technical field "KSTAR" will only be filled in case of postings from FI to CO-PA and of assessments or activity allocations of cost centers and processes into Profitability Analysis. When you transfer billing documents to CO-PA "KSTAR" will never be filled, because you have one CO-PA posting for every SD-position, but every position can contain more than one cost element.
The conception of the interface SD and CO-PA is not established via cost elements, but in the way of conditions. If you look into transaction KE4I or in the Customizing CO-PA flows of actual values -> transfer of billing documents you will find that there is a link between conditions and value fields/quantity fields. So, whenever there is a condition on a billing document in SD which is linked to a value fields within transaction KE4I these values will be taken onto CO-PA.
This way, the interface SD > CO-PA is developed in a different way in comparison to the interface MM(Material Management) /FI (Financials)/CO (Controlling) CO-PA (eg. for settlement, assessment, direct postings from MM/FI) and which is most important the SD -> CO-PA interface does NOT work with cost elements.
Conclusion
CO-PA derivation always depends on the interface with the sender application. In case of SD the interface is always through Conditions which are mapped in transaction KE4I. Hence it is not possible to derive cost element in the Profitability Analysis segment of the sales document.