Consultor Eletrônico



Kbase P17074: How do you get the value of a field without knowing the fiel
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   11/25/2003
Status: Unverified

GOAL:

How do you get the value of a field without knowing the field name?

FIX:

Use the buffer handle of the record, traverse through the number of fields in the record or just use the index for the field in the record buffer in order to get the buffer value of the field.
Below is a sample on how to do this. Note the code in the IF statements also handles the case when there are fields with extents.

/* Run this code against the sports database */

FUNCTION dynDysplay RETURNS CHARACTER

(INPUT hRecord AS HANDLE,
INPUT cDelim AS CHARACTER):

DEF VAR hFld AS HANDLE.
DEF VAR iCnt AS INTEGER.
DEF VAR iExtnt AS INTEGER.
DEF VAR cTmp AS CHARACTER.
DEF VAR cArray AS CHARACTER.
DEF VAR cResult AS CHARACTER.

IF hRecord:TYPE <> "BUFFER" THEN
RETURN ?.
DO iCnt = 1 TO hRecord:NUM-FIELDS:
ASSIGN hFld = hRecord:BUFFER-FIELD(iCnt).
IF hFld:EXTENT = 0 THEN DO:
ASSIGN cTmp = (IF hFld:BUFFER-VALUE = ? THEN "?"
ELSE
STRING(hFld:BUFFER-VALUE))
cResult = (IF iCnt = 1 THEN cTmp
ELSE cResult + cDelim + cTmp).
END.
ELSE DO:
DO iExtnt = 1 TO hFld:EXTENT:
ASSIGN cTmp = (IF hFld:BUFFER-VALUE(iExtnt) = ? THEN "?"
ELSE
STRING(hFld:BUFFER-VALUE(iExtnt)))
cArray = (IF iExtnt = 1 THEN cTmp
ELSE cArray + cDelim + cTmp).
END.
ASSIGN cResult = (IF iCnt = 1 THEN cArray
ELSE cResult + cDelim + cArray).
END.
END.
RETURN cResult.
END.


DEF VAR myVar AS CHARACTER.
FIND FIRST customer.
ASSIGN myVar = dynDysplay(INPUT BUFFER customer:HANDLE, " ").
MESSAGE myVar VIEW-AS ALERT-BOX.