Skip to main content

how to declare hexadecimal value in cobol. i declared x(2) value 'X'E2E4' .it shows value literal size is greater than data item size error.how to rectify it

how to declare hexadecimal value in cobol. i declared x(2) value 'X'E2E4' .it shows value literal size is greater than data item size error.how to rectify it

field01       pic x(01).

move x'00' to field1

field02     pic x(02).

move x'0D0A' to field2

this must work fine!!!

on your example move x'0D0A' to yourfield


how to declare hexadecimal value in cobol. i declared x(2) value 'X'E2E4' .it shows value literal size is greater than data item size error.how to rectify it

You can declare hex constants using the X'  '  construct which can be stored as character data and H' ' which can be used to store it as a numeric value.

01 testpicx pic x(2) value x'E2E4'.
01 testnum pic 9(9) value h'E2E4'.

Your example shows a leading single quote in front of the X' ' which shouldn't be there. 


You can declare hex constants using the X'  '  construct which can be stored as character data and H' ' which can be used to store it as a numeric value.

01 testpicx pic x(2) value x'E2E4'.
01 testnum pic 9(9) value h'E2E4'.

Your example shows a leading single quote in front of the X' ' which shouldn't be there. 

Thanks Chris and greiner.will try it. also please let me know how we can declare the below variables in hexadecimal format

test1 pic x(16) value '&éêë;¬'.


Thanks Chris and greiner.will try it. also please let me know how we can declare the below variables in hexadecimal format

test1 pic x(16) value '&éêë;¬'.

I am not really sure what you are asking for here.
The hex value of certain characters would depend on what codeset is being used and whether you are compiling for ASCII or EBCDIC.

You can use a character chart like the one here to determine the numeric value of characters: