Try OpenEdge Now
skip to main content
Programming Interfaces
External Program Interfaces : Introduction to External Program Interfaces : Using MEMPTR to reference external data : Setting byte order
 
Setting byte order
When passing MEMPTR data between system environments (such as can happen using sockets), you must help ensure that the communicating applications agree on the byte order for any data types that are transferred using the MEMPTR variable. Most machines follow one of two schemes for ordering bytes:
*Little-endian — Low-order bytes are stored starting at the lowest address location reserved for a data type, with progressively higher-order bytes stored at the higher byte positions. For example, 7 is stored in a four-byte (hex) integer as follows, where addresses increase from left to right:
07 00 00 00
*Big-endian — High-order bytes are stored in the lowest address location reserved for a data type with progressively lower-order bytes stored at the higher byte positions. For example, 7 is stored in a four-byte (hex) integer as follows, where addresses increase from left to right:
00 00 00 07
ABL ensures that MEMPTR data is interpreted correctly using MEMPTR write/read statements and functions as long as you indicate what byte order the MEMPTR data that you write uses. To do this use the SET-BYTE-ORDER statement:

Syntax

SET-BYTE-ORDER( memptr-name ) = integer-expression
Given the name of the MEMPTR variable (memptr-name), you can set one of these keyword values for integer-expression:
*HOST-BYTE-ORDER — A value of one (1) that indicates the byte ordering of the machine where the statement executes
*BIG-ENDIAN — A value of two (2) that indicates big-endian byte ordering
Note: Internet protocols use big-endian byte ordering.
*LITTLE-ENDIAN — A value of three (3) that indicates little-endian byte ordering
By default, all MEMPTR variables use the byte ordering of the machine where they are defined.
Note that the SET-BYTE-ORDER statement does not change the existing order of bytes in the MEMPTR data. It only indicates how subsequent MEMPTR write/read statements and functions interpret the data. You can also return the current byte order setting using the GET-BYTE-ORDER function. For more information, see OpenEdge Development: ABL Reference.