Try OpenEdge Now
skip to main content
Programming Interfaces
Data Management : Database Access : Using the RAW data type
 

Using the RAW data type

ABL supports the RAW data type, which lets you manipulate raw data without converting it in any way.
You can use the RAW data type to:
*Define ABL variables in an ABL procedure
*Define fields in a OpenEdge database
*Retrieve and manipulate raw data from non-OpenEdge databases
You can use the RAW data type to import non–OpenEdge data that has no parallel OpenEdge data type. By using the RAW data type statements and functions, ABL allows you to bring data from any field into your procedure, manipulate it, and write it back to the non-OpenEdge database. The functions and statements let you define RAW data type variables, write data into a raw variable, find the INTEGER value of a byte, change the length of a raw variable, and perform logical operations.
The following procedure demonstrates how to retrieve raw values from the database, how to put bytes into variables, and how to write raw values back to the database:
/*You must run this procedure against a non-OpenEdge sports2000 database.*/

DEFINE VARIABLE r1 AS RAW     NO-UNDO.
DEFINE VARIABLE ix AS INTEGER NO-UNDO.

FIND FIRST customer.
r1 = RAW(Customer.Name).
PUT-BYTE(r1,1) = 115.
RAW(Customer.Name) = r1.
DISPLAY Customer.Name.
This procedure first creates the variable r1 and defines it as a RAW data type. Next, it finds the first Customer in the database ("Lift Line Skiing"), and with the RAW function, takes the raw value of the Name field, and writes it into the variable r1. The PUT–BYTE statement then puts the character code value of "s" (115) into the first byte of r1. The RAW statement takes the raw value of r1 and writes it back to the database. Finally, the procedure displays the Customer name. Thus, "Lift Line Skiing" has become "sift Line Skiing".
The next procedure shows how you can pull bytes from a field:
/*You must run this procedure against a non-OpenEdge sports2000 database.*/

DEFINE VARIABLE ix AS INTEGER NO-UNDO INITIAL 1.
DEFINE VARIABLE ax AS INTEGER NO-UNDO.

FIND Customer WHERE Customer.CustNum = 27.

REPEAT:
  ax = GET-BYTE(RAW(Customer.Name),i).
  DISPLAY ax.
  IF ax = ? THEN LEAVE.
  ix = ix + 1.
END.
This procedure finds the Customer with the Customer number 27, and then finds the character code value of each letter in the Customer name. To do this, it retrieves the bytes from the name one at a time, then places them into the variable a. The GET–BYTE function returns the Unknown value (?) if the byte number you try to retrieve is greater than the length of the expression from which you are retrieving it. The next procedure demonstrates how you find the length of a raw value and how to change length of a raw expression:
/* You must run this procedure against a non-OpenEdge sports2000 database. */
DEFINE VARIABLE r3 AS RAW.

FIND FIRST Customer.
r3 = RAW(Customer.Name).
DISPLAY LENGTH(r3) Customer.Name WITH DOWN. /* length before change */
DOWN.

LENGTH(r3) = 2.
DISPLAY LENGTH(r3) Customer.Name.           /* length after change */
This procedure simply finds the number of bytes in the name of the first Customer in the database then truncates the number of bytes to two. The procedure first displays 16 because the Customer name Lift Line Skiing contains 16 bytes. It then displays 2 because you truncated the raw value to two bytes.
Note: When you use the STRING function to retrieve a raw value as a string, you must supply a format for the string as the second function argument.