Why modernization is hard? – Series 2
Conditional handling in COBOL is quite tricky to replicate in newer languages for a few reasons.
1. The character comparisons use EBCDIC codepage which has different collating sequence than ASCII/UTF-8. The non-equal comparison operators viz. >, >=, <, <= can result in different results when compared with EBCDIC collating sequence as against ASCII/UTF-8. e.g. String compare of literals viz.‘123ABC’ > ‘ABC123’ on mainframe will be flagged as True while it will be exact opposite in ASCII/UTF-8.
2. Comparing two different variables (PIC X(nn)) of different sizes are padded with SPACES (hexadecimal 40) and then compared. This can cause a difference in results if not handled correctly. Business rules depend on this kind of conditional handling.
77 WS-LONG-CHAR PIC X(10).
77 WS-SHORT-CHAR PIC X(7).
IF WS-LONG-CHAR IS EQUAL WS-SHORT-CHAR
The above condition requires that WS-SHORT-CHAR to be padded with three EBCDIC space characters.
3. A variable with DISPLAY Numeric can behave either as a number or as a character field and this causes extra complex conditional handling. Especially if one side of the condition is DISPLAY Numeric and other side is a Character or a Literal.
The following example will not work if WS-NUM PIC 9(2) has value 9.
IF WS-NUM IS EQUAL ‘9’ ←or equivalent character variable – PIC X(nn)
4. I have also seen many Multi level Nested IF / ELSE scope abruptly ends with a period or dot in COBOL. This could cause LLM to completely misunderstand the business rule.
Example below abruptly ends all levels of nested IF/ELSE with a period.
![](https://cloudframe.com/wp-content/uploads/2024/07/Screenshot-2024-07-08-at-3.02.01-PM.png)
5. I have also seen some strange behavior from AI such as (real business cases):
IF WS-STR( I, J, K)( A -B – C : D -E) = FUNCTION LOWER-CASE ( WS-X-VAL ( A -B -C: D -E) THEN
Confuses the LLM as below
![](https://cloudframe.com/wp-content/uploads/2024/07/image-1-1.jpg)
IF WS-X-VAL = ‘AB””CD”EF”’ THEN ← changed the actual literal to hide the real business case
Confuses the LLM as below
![](https://cloudframe.com/wp-content/uploads/2024/07/image-2.jpg)
Summary
What I have highlighted above represents just a small subset of the real issues encountered during legacy modernization. Understanding the actual business intent behind COBOL conditional logic can be a lengthy process unless you have a robust toolset like CloudFrame.
Recent Comments