Search code examples
filecobolsequential

How to treat the first line of a file differently in COBOL?


In COBOL i want to read a line sequential file. The first line occurs one time. The second and the thirth line can be repeated multiple (unknown) times. I really don't know how to do it.

I think the file description is something like this:

01 DBGEGEVENS            PIC X(200).
01 PROJECT. (occurs unknown times)
   03 PROJECTCODE        PIC X(10).
   03 CSVPAD             PIC X(200).

Solution

  • It depends on the file format

    Do you want a VB file format ???? then

       FILE-CONTROL.
           SELECT In-File ASSIGN .....
       DATA             DIVISION.
       FILE             SECTION.
       FD  Comp-File.
        01  DBGEGEVENS            PIC X(200).
        01  PROJECT. 
            03 PROJECTCODE        PIC X(10).
            03 CSVPAD             PIC X(200).
    

    with

        Read In-File
        Read In-File
        Read In-File
    

    You would use DBGEGEVENS for the first record and project for secon or subsquent records

    For Fixed width file format

       FILE-CONTROL.
           SELECT Comp-File ASSIGN .....
       DATA             DIVISION.
       FILE             SECTION.
       FD  Comp-File.
       01  input-record.
    
       WORKING-STORAGE  SECTION.
        01  DBGEGEVENS            PIC X(200).
        01  PROJECT. 
            03 PROJECTCODE        PIC X(10).
            03 CSVPAD             PIC X(200).
    

    with

        Read In-File into DBGEGEVENS
        Read In-File into PROJECT.
        Read In-File into PROJECT.
    

    Either should work, depending on which file format you use