Sub topic 9
Custom code analysis and adaptation
This chapter assumes you can read ABAP, know the difference between a development system and a production system, and have met simplification items in an earlier chapter. It covers how to find custom code that breaks on S/4HANA, how to decide what to fix, and how the work differs across the three transition paths.
Why custom code decides schedules
Most ECC systems hold years of custom reports, enhancements, interfaces, and forms in the Z and Y namespaces. S/4HANA changes the data model underneath that code. Code that runs on ECC can therefore fail in three ways after a move:
- It does not compile or activate, because an object or field no longer exists.
- It runs but returns wrong results, because the data now lives somewhere else or behaves differently.
- It runs but is slow or unstable, because it was written for a different database.
Custom code analysis finds these problems before cutover. The result is a worklist, and the size of that worklist is a major input to the choice of path.
What typically breaks
| Category | Example | Typical fix |
|---|---|---|
| Removed or replaced tables | Direct access to former aggregate or index tables, or to tables merged into others | Read the replacement table or the compatibility view |
| Write access to compatibility views | Inserting into MKPF or MSEG, which now sit on top of MATDOC | Use the standard API (BAPI or function module) |
| Changed field lengths | Material number extended to 40 characters | Use data elements, not hard-coded lengths |
| Business partner | Custom code that reads or writes customer (KNA1) or vendor (LFA1) master data directly | Go through Customer/Vendor Integration (CVI) and the business partner APIs |
| Database ordering | A SELECT that relied on results coming back in primary key order | Add ORDER BY, or SORT the internal table |
| Removed transactions and function modules | Calls to obsolete BAPIs or screens | Call the successor listed in the simplification item |
Treat this table as a sample. The authoritative list comes from the simplification database for your target release, and the tools below read from it.
The tooling
Three SAP tools do most of the work.
- ABAP Test Cockpit (ATC) runs static checks. The check variant
S4HANA_READINESScompares your code against the simplification database and reports findings by object. Quality checks for performance and security can run alongside it. - Custom Code Migration app is a Fiori app that runs on top of ATC. It imports the findings, lets you assign them to developers, and tracks progress. It is normally set up in a central check system, not in each development system.
- ABAP Call Monitor (transaction SCMON) records which custom objects are actually called in production. The Usage and Procedure Logging (UPL) feature offers similar data. Both feed the analysis with real usage.
Static analysis alone produces a very long list. Usage data cuts it down.
Step 1: Reduce the scope with usage data
Collect usage in production for a long period. Twelve months is a common recommendation, because quarter-end, year-end, and annual jobs run rarely and would otherwise look unused. Then sort objects into groups:
- Not used: candidates for decommissioning. Confirm with the business owner before deleting, then remove the code from the transport path.
- Used but replaceable: standard S/4HANA functionality now covers the requirement. Retire the custom object and use the standard function.
- Used and needed: the code you must adapt.
It is common to find that a large share of custom objects are unused. The exact figure varies by company, so measure it in your own system.
Step 2: Run the readiness checks
Run ATC with S4HANA_READINESS against the objects that remain. Each finding names the affected object, the line, and the related simplification item. Findings fall into two practical groups:
- Automatic or guided fixes. ATC offers quick fixes for some patterns, such as replacing a removed table with its successor view.
- Manual changes. Anything that touches business logic needs a developer and a functional consultant to agree on the new behavior.
Step 3: Adapt the code
Beyond the findings, a few edits come up in nearly every project. The following report shows the ordering fix. Old code often read a table and then used READ TABLE ... BINARY SEARCH. On the previous database that usually happened to work. On HANA, row order is not guaranteed without an explicit instruction.
REPORT zdemo_sorted_orders.
PARAMETERS p_kunnr TYPE vbak-kunnr OBLIGATORY.
START-OF-SELECTION.
" ORDER BY makes the sequence explicit, so a later
" BINARY SEARCH on VBELN stays correct on HANA.
SELECT vbeln, erdat, netwr
FROM vbak
WHERE kunnr = @p_kunnr
ORDER BY vbeln
INTO TABLE @DATA(lt_orders).
IF lt_orders IS INITIAL.
WRITE / 'No orders found.'.
RETURN.
ENDIF.
READ TABLE lt_orders WITH KEY vbeln = lt_orders[ 1 ]-vbeln
TRANSPORTING NO FIELDS BINARY SEARCH.
IF sy-subrc = 0.
WRITE: / 'First order:', lt_orders[ 1 ]-vbeln.
ENDIF.Other recurring adaptations:
- Replace direct reads of master data tables with released APIs, and route customer and vendor changes through the business partner.
- Replace selects inside loops with a single set-based statement or a CDS view, so HANA does the work in the database.
- Use data elements for material numbers and similar fields, and remove hard-coded lengths and offsets.
- Check for
SELECT ... FOR ALL ENTRIES, which silently selects all rows if the driver table is empty.
Adaptation across the three paths
The path changes how much of this work you do and where.
| Path | What happens to custom code |
|---|---|
| Greenfield | You do not convert old code. You decide object by object whether to rebuild it in the new system, replace it with standard, or drop it. Rebuilt code is written against the S/4HANA data model from the start. |
| Brownfield | The existing code moves with the system. Analysis and adaptation are mandatory, and they happen in the development system before the conversion reaches production. Code that is not adapted either fails or must be deactivated. |
| Selective data transition | Depends on the variant. If the target is a conversion of a copy, the brownfield effort applies. If the target is a new system receiving selected data, custom code is rebuilt as in greenfield. |
This is why code analysis belongs in the early assessment. A large amount of needed, tightly coupled custom code pushes toward brownfield effort whichever path you pick. A large amount of obsolete code makes greenfield or a cleanup before conversion cheaper.
Link to clean core
Adapting code is also a chance to stop repeating old habits. Modifications of SAP objects and direct database access to SAP tables create the findings you are fixing now. Where you rewrite, prefer released APIs, released CDS views, and extension points, so the next upgrade produces fewer findings. The clean core chapter covers this in detail.
Practical checklist
- Switch on SCMON in production early, at least a year before the planned conversion if you can.
- Set up the central ATC check system on the target release, so the simplification database matches your target.
- Rerun the analysis whenever the transition scope or target release changes, and after major development changes.
- Freeze or restrict new custom development during the conversion, so the worklist stops growing.
- Track findings by owner and status, and regression-test every adapted object.
Exercise
Your ECC system has 12,000 custom objects. SCMON data from production covers three months only. A manager wants to delete every object that shows no calls in that period before running ATC. What is the risk, and what would you do instead?
Show answer
Three months misses code that runs only at year-end, in annual closing, or in other rare processes, so deleting by that data could remove needed objects. Extend the collection to about twelve months. For objects without recorded calls, ask the business owner to confirm they are obsolete. Mark them for decommissioning rather than deleting them immediately. Run ATC with S4HANA_READINESS only on the objects that remain.
Exercise
A custom report reads rows from a database table into an internal table and then uses READ TABLE ... BINARY SEARCH, with no ORDER BY and no SORT. ATC reports no error. Why should you still change it for HANA, and what is the fix?
Show answer
Without ORDER BY, the database does not promise any row order. The earlier system often returned rows in primary key order, and the binary search relied on that by accident. On HANA the order can differ, so the search can silently miss rows. Add ORDER BY on the search key in the SELECT, or SORT the internal table before the READ TABLE.