Progress Programming Tips
By Rod Gaither (rdg@worldinfo.com)
PPT-31 Saving a snapshot of a record using a RAW field
Tip:
Several features were added in version 8.1 to help support the
creation of replication utilities. Among these features was
expanded support for the RAW datatype, including the RAW-TRANSFER
statement. This statement allows data to be transfered to a field
from a buffer and back, as well as between buffers. The RAW datatype
is now supported as a field in a Progress database table as well as a
variable and parameter. The language reference entry for RAW-TRANSFER
gives a short example of creating a log entry for replication purposes
as well as detailing some of the specifics of how the data is written
and checked.
Here is a short sample, done in 8.2 just to test the basic features.
---- Code insert begins ----
/** rawtest.p **/
DEFINE VARIABLE t-raw AS RAW NO-UNDO.
DEFINE TEMP-TABLE tt-customer NO-UNDO LIKE Customer.
FIND FIRST Customer NO-LOCK.
IF AVAILABLE(Customer)
THEN DO:
RAW-TRANSFER Customer TO t-raw NO-ERROR.
RUN ip-showcust IN THIS-PROCEDURE (INPUT t-raw).
END.
PROCEDURE ip-showcust :
DEFINE INPUT PARAMETER p-raw AS RAW NO-UNDO.
CREATE tt-customer.
RAW-TRANSFER p-raw TO tt-customer NO-ERROR.
MESSAGE "Transfer completed"
customer.cust-num
tt-customer.cust-num
VIEW-AS ALERT-BOX.
END PROCEDURE.
---- Code insert ends ----
This procedure tests several things -
1. Moving data from a record into a RAW variable.
2. Passing a RAW variable as a parameter.
3. Moving data from a RAW variable into a Temp-Table.
The ability to put a whole record into a single variable opens up some
interesting possibilities but should be approached with caution. The
replication purpose has some built in assumptions, namely that the
length of time data is stored in single field format will probably be
limited. It is not the most effecient storage technique, or the most
flexible, but it does simplify the programming necessary to automate a
process such as replication.
Some additional areas I think can benefit safely from this new
capabiltiy are -
1. Storing a variable number of "Template" records to use for initial
create of records.
2. Storing selection criteria for filters and searches.
3. Passing any table to a procedure.
I hesitate to mention this last one as it has some downsides that can
lead to bad programming practices. We have temp-table parameters now
as well as buffer parameters so the need for this any table feature is
limited. However, in certain circumstances this can be quite a boon.
You can have a single point of entry for the same processing on
multiple tables, or just simplify the starting point for other more
table specific operations.
Don't forget that other new commands were introduced to help manage
buffer level assignments and comparisons which are more appropriate
for those operations.
Also keep in mind that anything you store in the database is a
potential conversion issue when the database changes. This is
especially true for a RAW field holding data related to a specific
schema format.
** Surprising Note **
I was not surprised when I couldn't display the contents of the raw
variable itself in my message statement, it displays an error about
not being usable in input/output operations. What I was surprised by
was a quick test of export and import works just fine!
Wisdom:
At the highest level of abstraction nothing gets accomplished.
Rod Gaither | rdg@worldinfo.com
World Information Systems | (910) 333-2580 Voice
Greensboro, NC | (910) 333-2584 Fax