Monday, September 26, 2011

COBOL : blank padding


The below example explains how the blank padding works in COBOL.

WORKING-STORAGE SECTION.
01 A PIC X(04) VALUE '12'
PROCEDURE DIVISION.
PARA.
IF A = '12'
DISPLAY ' MATCH FOUND'

Output
Match found

Explanation
The variable "A" is defined as X(04). But the program is assigning only digits (i.,e '12') to it. So during the compile time, COBOL compiler automatically pads the blank for the remaining positions. So, the vlaue of A becomes '12  '

The IF condition compares "A" with value of '12'. "A" is defined as 4 characters, but the program is trying to compare it against two characters. In alphanumeric comparison, when the operands are of unequal size like the example shown above, the comparison is made as thought the shorter operand were extended to the right with enough spaces to make the operands equal in size.  

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.