Kbase 33459: 4GL. How to read an unformatted file character by character.
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
Solution ID: P3459
GOAL:
4GL. How to read an unformatted file character by character.
FIX:
The example below show a way to read an unformatted file with variable length.
It read from a file that has information structured in this way:
@1234008$abcdefg@1234001$a@1234002$ab....
Where the record delimiter is the "@" symbol and the 4 next digits correspond to a product code the next 3 digit a description length a "$" which is the start of the description.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE a AS CHARACTER NO-UNDO.
DEFINE VARIABLE b AS CHARACTER NO-UNDO.
DEFINE VARIABLE c AS CHARACTER NO-UNDO.
DEFINE VARIABLE FirstVal AS CHARACTER NO-UNDO.
DEFINE VARIABLE SecondVal AS INTEGER NO-UNDO.
DEFINE VARIABLE ThirdVal AS CHARACTER NO-UNDO.
INPUT FROM SomeDataFile.
REPEAT:
READKEY.
IF CHR(LASTKEY) = "@" THEN
DO:
DO i = 2 TO 5:
READKEY.
IF i NE 1 THEN
ASSIGN a = a + STRING(CHR(LASTKEY)).
END.
ASSIGN FirstVal = a
a = "".
END.
DO i = 1 TO 3:
READKEY.
IF CHR(LASTKEY) NE "@" THEN
ASSIGN b = b + (CHR(LASTKEY)).
END.
ASSIGN SecondVal = INTEGER(b)
b = "".
DO i = 1 TO SecondVal + 1:
READKEY.
IF CHR(LASTKEY) NE "$" THEN
ASSIGN c = c + CHR(LASTKEY).
END.
ASSIGN ThirdVal = c
c = "".
MESSAGE FirstVal STRING(SecondVal) ThirdVal VIEW-AS ALERT-BOX.
END.