Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I import a variable length sequential file?

Status
Not open for further replies.

Natalie

Programmer
Jun 6, 2000
29
US
Hello. I'm fairly new to PROGRESS and have been given the task of importing a variable-length record sequential file. Essentially, it's a file of customers and their kids. The first part of the record is fixed width (Name, address, etc). The variable length part comes in when they start listing their kids. Each kid will get his/her own field, with a variable number of fields depending on how many kids the person has.

The input will be:

Name
Address
Kid 1
Kid 2
Kid 3 (etc)

The output will be a unique record for each kid, with the parent's info at the beginning:
Name
Address
Kid
Kid-ordinal (1,2,3, etc)

Any ideas? Is there a magic Progress command to read this data?

Thanks in advance!

Natalie
 
Try this...

Input File:
Code:
John Doe
123 Maple Street
Kid 1
Kid 2
Kid 3

Code:
Code:
DEF TEMP-TABLE tt-kids
    FIELD NAME AS CHAR
    FIELD addr AS CHAR
    FIELD kid  AS CHAR
    FIELD kid-ord AS INT
  INDEX bykid IS PRIMARY
        NAME
        addr
        kid
        kid-ord.

DEF VAR in-file AS CHAR NO-UNDO INIT "c:\kids-1.txt".
DEF VAR in-text AS CHAR NO-UNDO.
DEF VAR v-name  AS CHAR NO-UNDO.
DEF VAR v-addr  AS CHAR NO-UNDO.
DEF VAR i       AS INT  NO-UNDO.
DEF VAR j       AS INT  NO-UNDO.
DEF VAR v-kids  AS CHAR NO-UNDO.

INPUT FROM VALUE(in-file).

REPEAT:
  IMPORT UNFORMATTED in-text.
  IF in-text <> &quot;&quot; THEN
  DO:
    ASSIGN i = i + 1.
    CASE i:
        WHEN 1 THEN
          ASSIGN v-name = in-text.
        WHEN 2 THEN
          ASSIGN v-addr = in-text.
        OTHERWISE
          ASSIGN v-kids = v-kids
                        + (IF v-kids <> &quot;&quot; THEN &quot;|&quot; ELSE &quot;&quot;)
                        + in-text.
    END CASE.
  END.
END.

    DO j = 1 TO NUM-ENTRIES(v-kids,&quot;|&quot;):
      CREATE tt-kids.
      ASSIGN tt-kids.NAME = v-name
             tt-kids.addr = v-addr
             tt-kids.kid  = ENTRY(j,v-kids,&quot;|&quot;)
             tt-kids.kid-ord = j.
    END.

INPUT CLOSE.
FOR EACH tt-kids NO-LOCK:
    DISP tt-kids.
END.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top