Sample Program

From Glow, 1 Year ago, written in COBOL, viewed 109 times.
URL https://anna.fyi/view/49cb801b Embed
Download Paste or View Raw
  1. $ SET SOURCEFORMAT"FREE"
  2. IDENTIFICATION DIVISION.
  3. PROGRAM-ID.  SeqWrite.
  4. AUTHOR.  Michael Coughlan.
  5. * Example program showing how to create a sequential file
  6. * using the ACCEPT and the WRITE verbs.
  7. * Note: In this version of COBOL pressing the Carriage Return (CR)
  8. * without entering any data results in StudentDetails being filled
  9. * with spaces.
  10.  
  11.  
  12. ENVIRONMENT DIVISION.
  13. INPUT-OUTPUT SECTION.
  14. FILE-CONTROL.
  15.     SELECT StudentFile ASSIGN TO "STUDENTS.DAT"
  16.                 ORGANIZATION IS LINE SEQUENTIAL.
  17.  
  18. DATA DIVISION.
  19. FILE SECTION.
  20. FD StudentFile.
  21. 01 StudentDetails.
  22.    02  StudentId       PIC 9(7).
  23.    02  StudentName.
  24.        03 Surname      PIC X(8).
  25.        03 Initials     PIC XX.
  26.    02  DateOfBirth.
  27.        03 YOBirth      PIC 9(4).
  28.        03 MOBirth      PIC 9(2).
  29.        03 DOBirth      PIC 9(2).
  30.    02  CourseCode      PIC X(4).
  31.    02  Gender          PIC X.
  32.  
  33. PROCEDURE DIVISION.
  34. Begin.
  35.     OPEN OUTPUT StudentFile
  36.     DISPLAY "Enter student details using template below.  Enter no data to end."
  37.  
  38.     PERFORM GetStudentDetails
  39.     PERFORM UNTIL StudentDetails = SPACES
  40.        WRITE StudentDetails
  41.        PERFORM GetStudentDetails
  42.     END-PERFORM
  43.     CLOSE StudentFile
  44.     STOP RUN.
  45.  
  46. GetStudentDetails.
  47.     DISPLAY "Enter - StudId, Surname, Initials, YOB, MOB, DOB, Course, Gender"
  48.     DISPLAY "NNNNNNNSSSSSSSSIIYYYYMMDDCCCCG"
  49.     ACCEPT  StudentDetails.  

Reply to "Sample Program"

Here you can reply to the paste above