Highlighted
Absent Member.
Absent Member.
3479 views

Read file in sequential mode

Jump to solution

Hi 🙂
IT's possible to read and write a sequential file in Visual Cobol .net ?

Like in that sample ?

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT StudentFile ASSIGN TO "STUDENTS.DAT"
		ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD StudentFile.
01 StudentDetails.
   02  StudentId       PIC 9(7).
   02  StudentName.
       03 Surname      PIC X(8).
       03 Initials     PIC XX.
   02  DateOfBirth.
       03 YOBirth      PIC 9(4).
       03 MOBirth      PIC 9(2).
       03 DOBirth      PIC 9(2).
   02  CourseCode      PIC X(4).
   02  Gender          PIC X

I get that sample in that link:
http://www.csis.ul.ie/cobol/examples/SeqWrite/SEQWRITE.htm

http://www.csis.ul.ie/cobol/examples/SeqRead/SEQREADno88.htm

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Are you referring to where in a class program do you place the file definitions?

Here is an example of what this could look like:

       class-id managedfiles.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT StudentFile ASSIGN TO "STUDENTS.DAT"
		                      ORGANIZATION IS LINE SEQUENTIAL.

       FILE SECTION.
       FD StudentFile.
       01 StudentDetails.
          02  StudentId       PIC 9(7).
          02  StudentName.
              03 Surname      PIC X(8).
              03 Initials     PIC XX.
          02  DateOfBirth.
              03 YOBirth      PIC 9(4).
              03 MOBirth      PIC 9(2).
              03 DOBirth      PIC 9(2).
          02  CourseCode      PIC X(4).
          02  Gender          PIC X.
       working-storage section.
       method-id ReadFile.
       procedure division.
          open input studentfile
          read studentfile
             at end
                display "no more"
          end-read
          close studentfile
          goback.
       end method.
          
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           goback.
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
       end method.
      
       end class.

View solution in original post

0 Likes
3 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Yes, Visual COBOL supports all of the standard COBOL file types like sequential, line sequential, relative

and indexed files.

These are supported in .NET managed code as well as in native code programs.

Please see the documentation under Programming-->Data Access-->File Handling for more information.

0 Likes
Highlighted
Absent Member.
Absent Member.

good, but,  have an specific location in source, to put the file division ???

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Are you referring to where in a class program do you place the file definitions?

Here is an example of what this could look like:

       class-id managedfiles.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT StudentFile ASSIGN TO "STUDENTS.DAT"
		                      ORGANIZATION IS LINE SEQUENTIAL.

       FILE SECTION.
       FD StudentFile.
       01 StudentDetails.
          02  StudentId       PIC 9(7).
          02  StudentName.
              03 Surname      PIC X(8).
              03 Initials     PIC XX.
          02  DateOfBirth.
              03 YOBirth      PIC 9(4).
              03 MOBirth      PIC 9(2).
              03 DOBirth      PIC 9(2).
          02  CourseCode      PIC X(4).
          02  Gender          PIC X.
       working-storage section.
       method-id ReadFile.
       procedure division.
          open input studentfile
          read studentfile
             at end
                display "no more"
          end-read
          close studentfile
          goback.
       end method.
          
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           goback.
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
       end method.
      
       end class.

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.