Consultor Eletrônico



Kbase P20135: What's the proper way to convert a CHARACTER datatype to a RAW data type ?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   1/27/2011
Status: Verified

GOAL:

What's the proper way to convert CHARACTER datatype to RAW data type ?

GOAL:

How to use PUT-STRING to handle RAW values

FACT(s) (Environment):

All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
OpenEdge Category: Language (4GL/ABL)

FIX:

Use the PUT-STRING function to accomplish this.
Syntax: PUT-STRING { destination, position, [numbytes]} = expression


The following simplified example illustrates the use:

DEFINE VARIABLE wMessageData AS RAW NO-UNDO.
DEFINE VARIABLE cMessageData AS CHARACTER NO-UNDO.
DEFINE VARIABLE gwBackToRaw AS RAW NO-UNDO.
FIND FIRST sports2000.customer NO-LOCK.
MESSAGE customer.NAME
VIEW-AS ALERT-BOX INFO BUTTONS OK.

/* Store the record in wMessageData as RAW */
IF AVAIL sports2000.customer THEN DO:
RAW-TRANSFER sports2000.customer TO wMessageData.
END.
/* Store the RAW data into cMessageData as CHARACTER */
ASSIGN cMessageData = GET-STRING(wMessageData, 1,
LENGTH(wMessageData)).
/* Convert this CHARACTER string back to the RAW datatype */
PUT-STRING(gwBackToRaw, 1, LENGTH(wMessageData)) = cMessageData.
MESSAGE LENGTH(gwBackToRaw) LENGTH(wMessageData)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
FIND CURRENT sports2000.customer EXCLUSIVE-LOCK.
ASSIGN customer.NAME = "Rob".
MESSAGE customer.NAME
VIEW-AS ALERT-BOX INFO BUTTONS OK.

/* Restore the old record using the converted RAW variable */
RAW-TRANSFER gwBackToRaw TO sports2000.customer.
MESSAGE customer.NAME
VIEW-AS ALERT-BOX INFO BUTTONS OK.