Progress
Programming
Handbook


Using the RAW Data Type

Progress 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:

You can use the RAW data type to import non–Progress data that has no parallel Progress data type. By using the RAW data type statements and functions, Progress allows you to bring data from any field into your procedure, manipulate it, and write it back to the non-Progress 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-Progress sports database. */ 
DEFINE VAR r1 AS RAW. 
DEFINE VAR i AS INT. 
FIND FIRST cust. 
r1 = RAW(name). 
PUTBYTE(r1,1) = 115. 
RAW(name) = r1.  
DISPLAY 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 field name, 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-Progress sports database. */ 
DEFINE VAR i AS INT. 
DEFINE VAR a AS INT. 
FIND cust WHERE cust-num = 27. 
i = 1. 
REPEAT: 
  a = GETBYTE(RAW(name),i). 
  DISPLAY a. 
  IF a = ? THEN LEAVE. 
  i = i + 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-Progress sports database. */ 
DEFINE VAR r3 AS RAW. 
FIND FIRST cust. 
r3 = RAW(name). 
DISPLAY LENGTH(r3) name WITH DOWN. /* length before change */ 
DOWN. 
LENGTH(r3) = 2. 
DISPLAY LENGTH(r3) 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. (If you are using a C-ISAM dataserver the procedure displays a larger value because C-ISAM uses fixed-length strings.) 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.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095