Conditional handling in COBOL is quite tricky to replicate in newer languages for a few reasons.
- 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.
-
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-CHARThe above condition requires that WS-SHORT-CHAR to be padded with three EBCDIC space characters.
- 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)
- 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.
- 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
IF WS-X-VAL = ‘AB””CD”EF”’ THEN ← changed the actual literal to hide the real business case
Confuses the LLM as below
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.