Skip to content
ERP Upgrade

Handling Custom Code During ERP Upgrades: Refactoring vs. Rewriting Strategies

Learn how to decide between refactoring and rewriting custom ERP code during upgrades. This guide covers risk assessment, technical execution, testing, and cutover planning to ensure business continuity.

12 min readSysGenPro Editorial
Handling Custom Code During ERP Upgrades: Refactoring vs. Rewriting Strategies

Choosing Between Refactoring and Rewriting Custom ERP Code

The decision to refactor or rewrite custom code during an ERP upgrade is a critical strategic choice that directly impacts project cost, timeline, and operational risk. Refactoring involves modifying existing code to work with the new ERP version while preserving its core logic, whereas rewriting entails building new functionality from scratch using the target version's native features or modern APIs. The recommended approach is not one-size-fits-all; it depends on the complexity of the custom code, the extent of changes in the target ERP version, and the business value of the customization. Generally, refactoring is preferred for stable, well-documented modules with minimal changes in the underlying data models, while rewriting is necessary when the target version introduces significant architectural shifts, deprecates core APIs, or when the existing code represents high technical debt that hinders maintainability. The primary risks to control include data loss, broken business processes, integration failures, and extended downtime. A rigorous assessment of source and target version compatibility, combined with a robust testing strategy, is essential to mitigate these risks and ensure a successful migration.

Assessing Custom Code Complexity and Dependencies

Before deciding on a strategy, a comprehensive audit of all custom code is required. This involves identifying every custom module, script, report, and integration point. The audit should map dependencies between custom code and standard ERP objects, such as database tables, views, and APIs. Understanding these dependencies is crucial because changes in the target ERP version may alter the structure or behavior of these standard objects. For example, if a custom module relies on a specific database field that is renamed or removed in the new version, the module will fail. Similarly, if an integration uses an API endpoint that is deprecated, the integration will break. The audit should also assess the quality of the existing code, including documentation, testing coverage, and maintainability. Code with poor documentation and high technical debt is a strong candidate for rewriting, as the cost of refactoring may exceed the cost of rebuilding. Conversely, well-documented and tested code is a better candidate for refactoring. This assessment should be performed by a team with deep knowledge of both the source and target ERP versions, and it should be documented in a detailed dependency map.

Identifying Deprecated APIs and Changed Models

A key part of the assessment is identifying deprecated APIs and changed data models. ERP vendors frequently deprecate older APIs in favor of newer, more efficient ones. Custom code that relies on deprecated APIs must be updated to use the new APIs, which may involve significant changes in logic and data handling. Similarly, changes in data models, such as the addition or removal of fields, can impact custom code that reads from or writes to these models. The assessment should include a review of the vendor's official release notes and migration guides for the specific source and target versions. These documents provide detailed information about changes in the ERP system, including deprecated features, new features, and recommended migration paths. It is important to verify compatibility against the vendor's official documentation for the exact source and target versions, as compatibility claims may vary between different releases. This step ensures that the team has a clear understanding of the technical changes that will impact the custom code.

Refactoring Strategy: Preserving Logic and Reducing Risk

Refactoring is the process of modifying existing code to improve its structure, readability, and maintainability without changing its external behavior. In the context of an ERP upgrade, refactoring involves updating custom code to work with the new ERP version while preserving its core logic. This strategy is suitable for custom modules that are stable, well-documented, and have minimal changes in the underlying data models. The refactoring process typically involves updating API calls, adjusting data mappings, and modifying security rules to align with the new version. It is important to maintain the original business logic to avoid introducing new defects. Refactoring can be done incrementally, allowing the team to test and validate changes in small batches. This approach reduces the risk of breaking the entire system and allows for easier rollback if issues are discovered. However, refactoring requires a deep understanding of the existing code and the changes in the target ERP version. It is not suitable for code with high technical debt or significant architectural changes.

Incremental Refactoring and Testing

Incremental refactoring involves breaking down the custom code into smaller, manageable units and refactoring them one by one. This approach allows the team to test and validate each unit before moving on to the next. It reduces the risk of introducing widespread defects and makes it easier to identify and fix issues. Each refactored unit should be tested in a staging environment that mirrors the production environment. The testing should include unit tests, integration tests, and end-to-end business process tests. Unit tests verify that individual functions and methods work as expected, while integration tests verify that the custom code interacts correctly with the standard ERP modules. End-to-end tests verify that the entire business process works as expected, from start to finish. This comprehensive testing approach ensures that the refactored code is stable and reliable before it is deployed to production.

Rewriting Strategy: Modernizing and Improving Maintainability

Rewriting is the process of building new functionality from scratch using the target ERP version's native features or modern APIs. This strategy is suitable for custom modules that have high technical debt, rely on deprecated APIs, or are affected by significant architectural changes in the target ERP version. Rewriting allows the team to take advantage of the new version's features, such as improved performance, better security, and enhanced usability. It also provides an opportunity to improve the maintainability of the code by using modern coding standards and best practices. However, rewriting is a more time-consuming and costly process than refactoring. It requires a detailed understanding of the business requirements and the target ERP version's capabilities. The team must ensure that the new code meets all the business requirements and that it is thoroughly tested before deployment. Rewriting is a good opportunity to eliminate technical debt and improve the long-term maintainability of the ERP system.

Leveraging Native Features and Modern APIs

When rewriting custom code, the team should leverage the target ERP version's native features and modern APIs wherever possible. This reduces the amount of custom code that needs to be maintained and improves the system's performance and reliability. For example, if the new version provides a built-in reporting feature that can replace a custom report, the team should use the built-in feature instead of rewriting the custom report. Similarly, if the new version provides a modern API for data integration, the team should use the modern API instead of the deprecated one. This approach reduces the complexity of the custom code and makes it easier to maintain. It also ensures that the custom code is aligned with the vendor's recommended best practices, which can improve the system's compatibility with future upgrades.

Decision Criteria for Refactoring vs. Rewriting

CriteriaRefactoringRewriting
Code ComplexityLow to MediumHigh
Technical DebtLowHigh
API ChangesMinimalSignificant
Business ValueHighHigh
TimelineShorterLonger
CostLowerHigher

The decision to refactor or rewrite should be based on a careful evaluation of the criteria listed in the table. Code complexity and technical debt are key factors. If the code is complex and has high technical debt, rewriting may be the better option. If the code is simple and has low technical debt, refactoring may be sufficient. API changes are also a critical factor. If the target ERP version introduces significant API changes, rewriting may be necessary. Business value is another important consideration. If the custom module provides high business value, it is worth investing in either refactoring or rewriting to ensure its continued functionality. Timeline and cost are also important factors. Refactoring is generally faster and cheaper than rewriting, but it may not be suitable for all situations. The team should weigh these factors carefully and make a decision that aligns with the project's goals and constraints.

Testing and Validation of Custom Code

Testing and validation are critical steps in the ERP upgrade process. They ensure that the custom code works correctly in the new ERP version and that it meets the business requirements. The testing strategy should include unit tests, integration tests, end-to-end business process tests, and user acceptance testing. Unit tests verify that individual functions and methods work as expected, while integration tests verify that the custom code interacts correctly with the standard ERP modules. End-to-end tests verify that the entire business process works as expected, from start to finish. User acceptance testing involves end-users testing the system to ensure that it meets their needs and expectations. The testing should be performed in a staging environment that mirrors the production environment. This ensures that the testing is realistic and that any issues are identified before deployment. The testing results should be documented and reviewed by the project team to ensure that all defects are resolved before cutover.

Regression Testing and Performance Benchmarking

Regression testing is a critical part of the testing strategy. It involves re-running existing tests to ensure that the custom code still works correctly after the upgrade. This is important because changes in the target ERP version can introduce new defects that were not present in the source version. Performance benchmarking is also important. It involves measuring the performance of the custom code in the new ERP version and comparing it to the performance in the source version. This ensures that the upgrade does not introduce performance regressions that could impact the business. The performance benchmarking should include metrics such as response time, throughput, and resource utilization. The results should be analyzed to identify any performance issues and to ensure that the system meets the performance requirements.

Cutover Planning and Rollback Strategies

Cutover planning is a critical step in the ERP upgrade process. It involves defining the steps that will be taken to switch from the source ERP version to the target ERP version. The cutover plan should include a detailed timeline, a list of tasks, and a list of responsible parties. It should also include a rollback plan, which defines the steps that will be taken to revert to the source ERP version if the upgrade fails. The rollback plan is essential for mitigating the risk of data loss and downtime. It should include verified backups, restore tests, and documented go/no-go criteria. The go/no-go criteria should be based on the results of the testing and validation process. If the criteria are not met, the upgrade should be postponed, and the rollback plan should be executed. The cutover plan should be reviewed and approved by the project team and the business stakeholders before the upgrade is executed.

Defining Go/No-Go Criteria and Rollback Triggers

Defining clear go/no-go criteria and rollback triggers is essential for a successful cutover. The go/no-go criteria should be based on the results of the testing and validation process. They should include metrics such as the number of defects, the performance of the system, and the user acceptance. The rollback triggers should be based on specific events that indicate that the upgrade has failed. For example, if a critical defect is discovered during the cutover, the rollback trigger should be activated. The rollback plan should be tested in a staging environment to ensure that it works correctly. This ensures that the team is prepared to execute the rollback plan if necessary. The cutover plan should be communicated to all stakeholders, including the business users, the IT team, and the vendor. This ensures that everyone is aware of the plan and is prepared to support the upgrade.

Post-Migration Stabilization and Monitoring

Post-migration stabilization is a critical phase in the ERP upgrade process. It involves monitoring the system to ensure that it is stable and that it meets the business requirements. The monitoring should include metrics such as system performance, error rates, and user feedback. The team should be prepared to address any issues that arise during the stabilization phase. This may involve fixing defects, tuning the system, or providing additional training to the users. The stabilization phase should continue until the system is stable and the users are satisfied with the new ERP version. The team should document any issues that arise during the stabilization phase and the actions that were taken to resolve them. This documentation can be used to improve future upgrades and to identify areas for improvement in the ERP system.

Conclusion: Balancing Risk and Value in ERP Upgrades

Handling custom code during ERP upgrades requires a careful balance between risk and value. The decision to refactor or rewrite should be based on a thorough assessment of the code's complexity, technical debt, and business value. A robust testing and validation strategy is essential to ensure that the custom code works correctly in the new ERP version. A well-defined cutover plan and rollback strategy are critical for mitigating the risk of data loss and downtime. Post-migration stabilization and monitoring are essential for ensuring that the system is stable and that it meets the business requirements. By following these best practices, organizations can successfully upgrade their ERP systems while minimizing risk and maximizing value. The key is to take a structured and disciplined approach to the upgrade process, and to involve all stakeholders in the decision-making process. This ensures that the upgrade is aligned with the business goals and that it delivers the expected benefits.

Written by
SysGenPro Editorial

SysGenPro Editorial

Platform & solutions team

Practical guidance on ERP, AI automation, cloud deployment and enterprise transformation from the SysGenPro team.

Share this article

Frequently asked questions

Common questions on this topic. Talk to our team for anything specific to your business.

01When should I rewrite custom ERP code instead of refactoring?

You should rewrite custom ERP code when it has high technical debt, relies on deprecated APIs, or is affected by significant architectural changes in the target ERP version. Rewriting allows you to take advantage of the new version's features and improve the maintainability of the code.

02How do I assess the compatibility of custom modules with a new ERP version?

You should assess the compatibility of custom modules by performing a detailed audit of the code, mapping dependencies, and reviewing the vendor's official release notes and migration guides for the specific source and target versions. This helps you identify any changes in the ERP system that may impact the custom code.

03What is the role of automated testing in ERP code migration?

Automated testing plays a critical role in ERP code migration by ensuring that the custom code works correctly in the new ERP version. It includes unit tests, integration tests, and end-to-end business process tests, which help identify and fix defects before deployment.

04How does technical debt affect ERP upgrade costs?

Technical debt can significantly increase ERP upgrade costs because it requires more time and effort to refactor or rewrite the code. It can also increase the risk of defects and downtime, which can further increase the costs of the upgrade.

05What are the key risks of migrating custom code without a rollback plan?

The key risks of migrating custom code without a rollback plan include data loss, extended downtime, and broken business processes. A rollback plan is essential for mitigating these risks and ensuring that the system can be reverted to the source version if the upgrade fails.

06How do I document custom code dependencies for an ERP upgrade?

You should document custom code dependencies by creating a detailed dependency map that shows how the custom code interacts with the standard ERP objects, such as database tables, views, and APIs. This map should be updated regularly to reflect any changes in the code or the ERP system.

Continue learning
View all articles
Explore the platform

Where to go next

Browse the knowledge hub

See how SysGenPro fits your business

Discuss your workflows, modules and deployment options with our team.

Back to resources