Consultor Eletrônico



Kbase P106138: How to IMPORT a record dynamically.
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   16/10/2008
Status: Unverified

GOAL:

How to IMPORT a record dynamically.

GOAL:

How to IMPORT a record via a buffer-object handle

FACT(s) (Environment):

Progress 9.x
OpenEdge 10.0x

FIX:

The following piece of code emulates a dynamic IMPORT statement, which is currently missing from the 4GL.


PROCEDURE dynImport:
DEFINE INPUT PARAMETER hTable AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER cDelim AS CHARACTER NO-UNDO.
DEFINE VARIABLE cImport AS CHARACTER NO-UNDO EXTENT 512.
DEFINE VARIABLE iImp AS INTEGER NO-UNDO.
DEFINE VARIABLE iCnt AS INTEGER NO-UNDO.
DEFINE VARIABLE iExtnt AS INTEGER NO-UNDO.
DEFINE VARIABLE hFld AS HANDLE NO-UNDO.
IF hTable:TYPE <> "BUFFER" THEN
RETURN.

REPEAT:
ASSIGN cImport = ""
iImp = 0.
IMPORT cImport.
hTable:BUFFER-CREATE().
DO iCnt = 1 TO hTable:NUM-FIELDS:
ASSIGN hFld = hTable:BUFFER-FIELD(iCnt).
IF hFld:EXTENT = 0 THEN DO:
ASSIGN iImp = iImp + 1
hFld:BUFFER-VALUE = cImport[iImp].
END.
ELSE DO:
DO iExtnt = 1 TO hFld:EXTENT:
ASSIGN iImp = iImp + 1
hFld:BUFFER-VALUE(iExtnt) = cImport[iImp].
END.
END.
END.
hTable:BUFFER-VALIDATE().
END.
END PROCEDURE.

The opening and closing of the INPUT stream has been intentionally left out from this function, so that you can specify the options you prefer in the INPUT FROM statement (for example, NO-MAP, BINARY, CONVERT).

The code can be used as follows:

DEF TEMP-TABLE ttCust LIKE customer.

INPUT FROM customer.d CONVERT SOURCE "ibm850".
RUN dynImport (TEMP-TABLE ttCust:DEFAULT-BUFFER-HANDLE, " ").
INPUT CLOSE.