This is the continuation to my previous blog post on Legacy application modernization using AI & ML.
From my previous blog post – “Legacy RPG and CLP applications can be modernized using AI-powered tools that analyze and refactor code into optimized, modular structures. For example, AI can scan RPG III or old cycle-based programs and suggest converting fixed-format code into modern free-format RPG for better readability and maintainability.”
Let us explore how AI tools can help us in this process.
- AI powered code analysis uses machine learning and natural language processing techniques to scan source code and help us detect issues like:
· Bad coding practices (like hardcoding)
· Performance bottlenecks
· Unused or duplicate code
For example, consider this old RPG code with hardcoded values:
C READ FILE1
C IF FIELD1 = 'X'
C CALL 'OLDPROC'
C ENDIF
Which can be refactored using Free RPG as:
Dcl-S fieldValue Char(1);
READ FILE1;
fieldValue = FIELD1;
Select;
When fieldValue = 'X';
Exsr NewProcedure;
EndSl;
- AI powered refactoring automatically improves code efficiency without changing the logic. Consider the below RPG III fixed format code:
C Z-ADD 0 TOTAL 10 0
C DO 100 I
C Z-ADD I VALUE 10 0
C ADD VALUE TOTAL
C ENDDO
C SETON LR
which can be refactored using Free RPG as:
ctl-opt dftactgrp(*no) actgrp(*caller);
//Variable declaration using dcl-s
for i = 1 to 100;
total += i;
endfor;
*inlr = *on;
The AI tool identified redundant Z-ADD operations and an unnecessary temporary variable VALUE in the previous code. It optimized these elements using a concise code snippet, replacing the legacy style code with modern RPG. This enhancement improves both readability and maintainability.
- AI powered code transformation - One of the main challenges is modernizing legacy RPG code int any new programming languages (like Python). AI-powered tools can automatically translate RPG into Python. For example, lets take the same RPG III code:
C Z-ADD 0 TOTAL 10 0
C DO 100 I
C Z-ADD I VALUE 10 0
C ADD VALUE TOTAL
C ENDDO
C SETON LR
which can be converted into optimized Python code:
# Efficient Python version
total = range (1, 101))
print(f"Total: {total}")
In the next post, we will discuss examples on AI-driven data migration and cleansing processes.