Move beyond standard functionality by integrating the steps for product cost planning into a single ABAP program that you can schedule as an automated background process.
Key Concept
Executing the costing run transaction as an automatic batch program without any manual intervention eliminates system issues, makes the process highly scalable, and makes it easily manageable by a central costing team. Implementing this functionality helps large enterprises accurately cost any new materials created on a day-to-day basis and handle the process in a cost-effective manner. It helps avoid situations such as when new material creation by the central master data team is not communicated to the costing team in a timely manner. When a material movement happens before the cost is created for the material, it can lead to wrong financial data. The automatic costing run ensures that all new materials are costed on a day-to-day basis without delay.
Costing of raw materials, finished goods, and semi-finished goods is a key business process in the manufacturing industry. A bill of materials (BOM) for a single finished product may contain 600 to 1,000 sub-assembly parts or component items, and variants of the finished product increase the number of parts that a company needs to cost. Typical product costing is a detailed process requiring a significant amount of manual intervention.
The standard SAP ERP Central Component (or R/3) transaction for cost planning, CK40N, allows for costing of multiple materials together in a single transaction, but the multiple steps associated with it take a long time to execute. Even if you schedule the different steps in a costing run transaction as a background job, the process still requires you to define parameters for each step, including the costing run definition and creation of a material selection list. Further, manual scheduling can lead to locking errors when you schedule costing runs for multiple plants in the same company code together.
By automating the task, you can avoid the potential pitfalls of the manual process and also optimize system performance by scheduling the batch job to run during non-business hours. I’ll show you a quick overview of the costing steps using transaction CK40N and then explain how to automate this process.
Overview of Costing Steps Using Transaction CK40N
Product costing in transaction CK40N follows four steps.
- Step 1. Define the parameters for the costing run
- Step 2. Create the cost estimate
- Step 3. Analyze the cost estimate
- Step 4. Mark and release the cost estimate
I’ll look briefly at the actions involved in the first two of these steps, but because my focus is on the automation process, I won’t go into detail about exactly where and how you enter the data in each step.
Note
When you execute the transaction through this batch job program, you have a lot of flexibility in scheduling the job. You can create multiple batch jobs, one for each company code, and schedule execution of these jobs either in parallel or at different times. Within a single batch job defined for a company code, you can set up each plant costing run as different steps and the system will execute each step sequentially.
Step 1. Define the parameters for the costing run. You define the following parameters for any costing run in the SAP system:
- Costing run name
- Costing run description
- Costing run date
- Costing variant
- Costing version
- Controlling area
- Company code
Entering these parameters automatically defaults the costing validity dates and quantity structure date based on the configuration of the costing variant (Figure 1). After you save the parameters, the system can begin the next step in the process.

Figure 1
Enter parameters for the costing run
Step 2. Create the cost estimate. After you save the parameters in the first step, the system populates the parameters screen for:
- Selection
- Structure explosion
- Costing
I’ll look into these three processes next.
Selection
You generally define materials to be selected in costing, such as production parts, as a material selection list. Transaction CKMATSEL defines the material selection list based on different attributes of the material master, such as valuation class, material type, and valuation area (Figure 2). You can always modify the program’s selection parameters based on business requirements. For example, if your company wants to revise cost every half-year, it can program to cost all materials periodically.

Figure 2
Create the material selection list
As shown in Figure 3, the system retrieves the parameter values for costing selection from the Selection Using Selection List that saved as a variant in transaction CKMATSEL.

Figure 3
Define selection parameters using the material selection list
After you save the selection parameters, you execute the costing selection step. You can execute it either in the foreground or background, depending on the number of items to be selected. When you save the parameters for each step, execution does not happen automatically. Users need to execute the step manually and they have options to execute them in the foreground or as a background process.
Define Structure Explosion
Next you need to define and execute the parameters for explosion. The SAP system then explodes the BOM of the parent item that you defined earlier. For example, the parent item entered in material selection is a part number associated with an assembled car. When you execute the BOM explosion step, the system selects all component parts or sub-assembly items that constitute the BOM of finished assembly for costing. The system then identifies and selects a list of child materials that also needs costing. For example, to cost the finished good (FG) item, you need to successfully cost the child materials for the FG item as well.
Define Parameters for Costing and Execute Costing
After you have completed the structure explosion, the system costs all materials that you selected in earlier steps based on valuation strategies defined in the configuration for the specific costing variant.
In the parameters for costing, you define foreground or background processing and execute accordingly. After you cost the materials, the system gives a detail log of error and warning messages it encountered during the process. You can review the error log and take any necessary action. If no error log exists, then you can proceed to the analysis of cost and mark/release phases.
As I mentioned earlier, following these three steps you analyze and then mark and release the cost estimate. You then may need to perform a price update, depending on business rules. For cost variants (such as current or planned), you perform a price update in the material master in specific fields that you choose in the selection screen. This again depends on business rules within your organization. Then you need to mark updates for future cost estimates in the material master and release them. Now that you know what is involved in each of the costing steps, I’ll show you how to automate them.
Automate Costing Steps
Automation of transaction CK40N execution refers to integrating the steps of costing — namely defining parameters and executing the steps such as selection, structure explosion, and costing — to create a cost estimate. You can integrate all these steps of costing in a single custom ABAP program.
For the automated process, you use these substitutes for transaction CK40N:
- Transaction CK41: Define costing parameters
- Transaction CK60: Define costing selection (preselection for material or plant)
- Transaction CK62: BOM explosion
- Transaction CK64: Run cost estimate of objects that you can further execute as a batch processing by transaction CK65
The program that you create needs to include the following mandatory and optional user selections that you can use to fulfill all selection requirements needed to define the costing run and execute the later steps (selection, structure explosion, and costing).
Mandatory:
(a) Plant
(b) Costing run date
(c) Costing variant
(d) Costing version
(e) Controlling area
(f) Company code
(g) Costing date from
(h) Costing date to
(i) Quantity structure date
(j) Valuation date
Optional:
(k) Material type
(l) Valuation area
(m) Valuation class
(n) Current cost estimate
Based on these selection parameters, the program executes the following transactions. In each case I’ll provide examples of how to set up the code and program, but specifications will vary based on your organization.
1. Transaction CKMATSEL. The program creates a material selection list to retrieve the list of items that need costing. The system automatically populates selection parameters for this transaction from the user selection to the ABAP program. Transaction execution from entering parameters to saving material selection list is recorded as a Batch Data Communication (BDC) session.
Use transaction CKMATSEL in the BDC with the following information:
- Plant, material type, valuation area, valuation class, current cost estimate, from (a), (c), (d), (e), and (f) above
- Selection list named plant_yyyyddmm (plant from [a] above and yyyyddmm from costing run date [b] above)
- Execute (F8)
- Select all (F5)
- Save
2. Transaction CK41. After you define the material selection list, you need to use transaction CK41 and record the BDC session again from the point of defining costing run name, description, costing date, and so on to saving the parameters of costing run.
Use transaction CK41 in the BDC with the following information:
- Costing run named plant_dd (plant from [a] above and dd from costing run date [b] above, yyyymmdd)
- Costing run date from (b) above
- Press Enter
- Description as plant_yyyyddmm_costing_run (plant from [a] above and yyyyddmm from costing run date [b] above)
- Costing variant, costing version, controlling area, and company code from (g), (h), (i), and (j) above
- Press Enter
- In the resulting window, enter costing date from, costing date to, quantity structure date, and valuation date from (k), (l), (m), and (n) above
- Save
3. Transaction CK60. After defining the costing run, the first step to derive cost estimate is selection. Selection is based on the material selection list defined earlier. Then you record the parameters for selection and the subsequent execution as a BDC and call them in the program.
Use transaction CK60 using a submit statement with the following:
- Costing run and costing run date as in transaction CK41
- Selection list as in transaction CKMATSEL
4. Transaction CK62. The execution of structure explosion step is quite similar to transaction CK60 as explained above.
5. Transaction CK64. Use transaction CK64 using BDC with the following:
- Costing run and costing run date as in transaction CK41
- Execute
- Save
Note
Because the steps in a costing run are sequential, it is necessary for each step to be successful before the next step is executed. If any step fails, the program is terminated. Users can find the explanation in the spool associated with the program execution.
After executing transaction CK64, the system calls SAP program SAPCRK10 (transaction CK65) and the program executes and generates a costing log of all materials. Every time you execute the ABAP program, the system triggers SAPCRK10 internally. Transaction CK40N recognizes the completion of the costing step when you’ve executed SAPCRK10.
The program must recognize the completion of one step in costing before proceeding to the next step. You cannot perform the BDC recording in transaction CK40N because it is an SAP Easy Access transaction and records the status completion with green, red, and yellow signals, which you cannot capture in a BDC session. As a result, you need to record the completion of each of the steps and use different transactions to call each of the steps. You can track the status of step completion in the program.
You can see typical selection parameters for a wrapper program used to cost materials in a plant that does not have a current standard cost estimate in Figure 4. When you execute a program with these selection parameters, then it automatically executes all the steps. The program internally tracks the status of completion of each step, and, when it finishes one step, moves onto the subsequent step.

Figure 4
Automation of costing run program — defining selection parameters
The system logs each step in costing in a job spool. Users can find the details of the material selection list and the costing run name in the spool. Based on this, they can invoke transaction CK40N to find details in the error log, analyze cost estimates created, and then move on to other actions such as marking and releasing.
Muralidharan Sethuraman
Muralidharan Sethuraman is director enterprise ERP IT finance at Johnson Controls. He has more than 16 years of industry experience leading and managing multiple SAP implementation and business transformation programs across geographies. Muralidharan is currently leading the SAP S/4HANA program at Johnson Controls. He specializes in SAP Financials and has done design lead, solution architect roles in global SAP implementation programs. Muralidharan is a subject matter expert in the areas of product cost analysis and management, inventory and working capital management, management reporting and profitability analysis, financial analytics and reporting, and business planning. He has published multiple articles in Financials Expert in these areas.
If you have comments about this article or publication, or would like to submit an article idea, please contact the editor.