Sub topic 14
Custom Code: Finding and Fixing What Breaks
This chapter assumes you know basic ABAP, understand what a custom Z-object is, and have read the earlier chapters on the Universal Journal, Business Partner, and material documents. Those changes are the main reason custom code breaks during a move to S/4HANA.
Why custom code breaks
Custom code often reads or writes tables that S/4HANA has changed. Three patterns cause most of the findings:
- Code that reads the old finance aggregate and index tables, such as GLT0, instead of ACDOCA.
- Code that reads customer and vendor master tables (KNA1, LFA1) and assumes no Business Partner exists.
- Code that reads the material document tables MKPF and MSEG, or uses a material number field of 18 characters, when the material number can now be longer.
SAP keeps compatibility views for many removed tables, so some reads still work. Writes to those tables usually do not, and the compatibility views may not return the same data in every case.
Finding the problems
SAP's tooling for this has two parts.
- The Simplification Item Catalog lists, for each changed area, what changed and what it means for custom code.
- The ABAP Test Cockpit (ATC) runs static checks on your code against a chosen S/4HANA target release. It reports each finding with the object, the line, and the simplification item behind it.
Before you run the checks, you can reduce the workload by using usage data (the SCMON and UPL tools). They show which custom objects ran in production. Code that never ran is a candidate for deletion instead of adaptation.
Fixing the findings
Most fixes fall into a few types.
| Finding | Typical fix |
|---|---|
| Read from an aggregate table | Select from ACDOCA, or use a CDS view |
| Read from MKPF and MSEG | Select from MATDOC, or use the released view |
| Direct customer or vendor table access | Go through Business Partner APIs |
| Material number length | Declare fields with the data element, not a fixed length |
| Database-specific SQL | Rewrite in Open SQL |
Here is the replacement for a balance read. Instead of reading an aggregate table, sum the line items:
SELECT SUM( hsl ) AS total_amount
FROM acdoca
WHERE rldnr = '0L'
AND rbukrs = '1000'
AND gjahr = '2024'
AND racct = '0000400000'
INTO @DATA(lv_total).Movement history comes from one table:
SELECT mblnr, mjahr, zeile, matnr, werks, menge
FROM matdoc
WHERE matnr = @lv_matnr
AND werks = @lv_werks
INTO TABLE @DATA(lt_movements).Common mistakes
- Analyzing only once. Run ATC again after each round of fixes, and again near go-live, because new code is written during the project.
- Skipping usage data. Teams that adapt every object spend effort on code nobody runs.
- Using the wrong target release. Check against the release you will actually convert to, since the simplification list changes between releases.
- Testing only syntax. A clean check does not prove the results are right. Test the business outcome, such as comparing balances before and after.
Exercise
A custom report selects from MSEG joined to MKPF to list goods movements for a plant. ATC flags it after the check against the S/4HANA target. Name the table that replaces this read, and name one step you should take before fixing it that could remove the need to fix it.
Show answer
Read from MATDOC, which holds the material document items. Before fixing, check usage data (SCMON or UPL) to see whether the report ran in production. If it never ran, you can delete it instead of adapting it.
Exercise
Why is a clean ATC result not enough to approve a custom program for go-live?
Show answer
ATC is a static check. It finds known incompatibilities, but it does not prove the program returns correct results on the new data model. You still need business testing, for example comparing outputs before and after conversion.