An Easytrieve program that access DB2 was run, the following error appeared.
UPDATE ERR EMPLC=02689
** SQLCODE = 311- MSG =(SQL0311N xxxxxxxxxxxxxxxxxx "9"
SQL0311N error occurred. How may this be resolved?
The same program can be run in an AIX system.
EASYTRIEVE REPORT GENERATOR FOR FOR LINUX PC, release 11.6
In a Linux system, the length filed of a VARCHAR column should be specified with type I instead of type B as follows.
WEMPLJN1 W 22 A VARYING
WEMPLJN1-L WEMPLJN1 2 I 0 <===== I type
WEMPLJN1-C WEMPLJN1 +2 20 A
WEMPLJN2 W 22 A VARYING
WEMPLJN2-L WEMPLJN2 2 I 0 <===== I type
WEMPLJN2-C WEMPLJN2 +2 20 A
This should fix the SQL0311N/SQLCODE -311.
This is a big-little-endian issue.
From IBM Linux page
" Endianness refers to the order in which the bytes of a multi-byte word are stored in memory. There are several ways of storing a 32-bit binary value such as 4A3B2C1D, including:
The big-endian scheme stores the most significant byte (MSB) first, yielding 0x4A 0x3B 0x2C 0x1D.
The little-endian scheme stores the least significant byte (LSB) first, yielding 0x1D 0x2C 0x3B 0x4A.
Big endian architectures include Sun SPARC and IBM System z. All processors of the Intel x86 family are little endian.
..."
B (byte) values are "big endian" on all platforms, where as I (integer) values are in platform specific endian representation. Hex 3039 is the binary representation of the numeric value 12345.
A two byte B value of 12345 is stored as the bytes x'30' followed by x'39' on all platforms.
A two byte I value 12345 is stored as the bytes x'30' followed by x'39' on big endian platforms, but x'39' followed by x'30' on little endian platforms.
When running:
...
DEFINE W-I S 2 I 0 VALUE 12345
DEFINE W-B S 2 B 0 VALUE 12345
*
JOB INPUT NULL
DISPLAY 'HEX W-I:'
DISPLAY HEX W-I
DISPLAY W-I
DISPLAY 'HEX W-B:'
DISPLAY HEX W-B
DISPLAY W-B
STOP
...
on z/OS (big endian like AIX), there is no difference between I and B:
...
HEX W-I:
CHAR
ZONE 33
NUMR 09
1.
12,345
HEX W-B:
CHAR
ZONE 33
NUMR 09
1.
12,345
...
On Linux/PC (little endian) there is a difference between I and B:
...
HEX W-I:
CHAR 90
ZONE 33
NUMR 90
1.
12,345
HEX W-B:
CHAR 09
ZONE 33
NUMR 09
1.
12,345
On little endian it's thus always better to use the "I" type when using SQL or the CALL statement.