Cobol Tutorial

 
 
 

Basic Programming

Print mark sheet of a student with grades Use of Redefine clause Create marksheet of student Use of leading and trailing Sequential search Class condition Student detail management using indexed file

Search Programs

Enter value is alphabetic,numeric,alphanumeric Find yearly depreciation Unstring word Find smallest quotation for given item Write records reside in i/p file- show on screen Sum of series 1 + 1/4 + 1/9 Using sign test for numeric value Draw polygon Use of EVALUATE clause Count number of char Date manipulation Bubble sort DOS standard o/p device Create the index file

String Programs

Includes external source file in current file Gross salary, deduction, net salary of employee Count character for no of times in input string Display triangle of numbers FILE Read Operation Add two numbers Generate sales report item wise Divides one or more operands by another IF-ELSE Clause Group wise stock summary Attendence Report of Employees SORTING Operation Add 2 or more operands and stores result Relative file - insertion,deletion,updation, print Describe Functionality of table by using File Fahrenheit into temperature - C = (5/9) * (f - 32) Use of Control Break clause Print employee detail Draws an ellipse or a circle Binary search using files Generating date and time

General Programs

Evaluate gender from user and print Display input number is prime or not Display on printer message entered by user Displays message entered by user on printer Merging two files in a single file Generate arithmetic operation - evaluate clause Print account report Use of Sign clause Create attendence sheet Displays on printer - divide operation quotient Binary search on student name, print roll number job appl checking candidate is eligible or not Read data from input file and move to output file

Mathematical Program

Print bill report Purchase and rebate amount payslip Example of string and unstring Describe Functionality of two dimension table Insert, delete, update, view in index file Display the pattern of square School management system Converting integer to its number of words Use of move clause for numeric values Use multiple array Inventory transactions Sort records of file Displays alphanumeric char on screen graphic mode Student details using relative file

Sorting Programs

Store content in file,record of field - other file Calculate Total percentage Classfor each student Edit character Display pattern of numbers in reverse pattern User input data and stores it in to the file Multiplication table Generate sales register Draw a line Use of Tables with INPUT clause Check student is pass or fail i/p result from user Calculate monthly sales amount -sequential access Sescribes how to use Sort technique Declares data to the compiler Input record into file using extend mode

Clause

Describe Functionality of Relative File Print addition of two nos and sum is third or not Use of perform verbs Bank Report depending upon user choice Create result statement for given semester Search name from file display roll no of student Generating julian date Evaluates arithmetic expression - stores result Use of evaluate clause Describe use of IF CONDITION and PRINT Calculate Total percentage Class for each student Displays alphanumeric character in graphics mode Reads in states until end of data Read student details from file - read operation Merge 2 files with students records Print presence report based on provided data Use of Inspect clause Check entered date is valid birth date or not Draws rectangle filled with one color Search perticular record Find age from accepted date from user

File Programs

Check two same condition name is allow or not Arithmetic operations add,sub,div and mul Display on Console a message entered by user Display message entered by user on console Generate student mark sheet using file r/w op Check if a number is a fibonacci or not
 
 
environment division.
 input-output section.
  file-control.
    select student-file assign to \'student.dat\'.
    select subject-file assign to \'subject.mst\'.
    select result-file assign to \'result.rpt\'.
    select sort-file assign to disk.

data division.
 file section.
  fd student-file.
   01 stud-rec.
      05 sem-no     pic 9.
      05 stud-no     pic 999.
      05 name         pic x(40).
      05 result-tbl occurs 6 times.
         10 subj-no     pic 9.
         10 marks     pic 999.
  fd subject-file.
   01 subj-rec.
      05 sem-no     pic 9.
      05 subj-no     pic 9.
         88 valid-subject value 1 thru 6.
      05 subj-name     pic x(40).
  fd result-file.
   01 result-rec    pic x(80).

  sd sort-file.
   01 sort-rec.
      05 s-sem-no     pic 9.
      05 s-stud-no     pic 999.
      05         pic x(64).

 working-storage section.
   01 eof         pic x value \'n\'.
*   01 i            usage index.
   01 i            pic 9.
   01 subj-tbl value spaces.
    05 subject-name occurs 6 times pic x(40).
   01 line-cnt        pic 99 value 80.
   01 max-lines        pic 99 value 55.
**************************************************************************
*         1         2         3         4         5         6         7
*123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789

*MCA Semester 9                Result statement                Date:99/99/9999
*                                                              Page:99
*
*No. Name                               <--Marks in Subjects--> Total    %  Clas
s
*                                        1   2   3   4   5   6  Marks 
*
*999 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 999 999 999 999 999 999  999 999.99 XXXXX
X
*123 123456789012345678901234567890123 123 123 123 123 123 123  123 123456 12345
6
*
* Actually 40 characters in name. But as shown below, it will exceed 80 col.
* So, here it prints only 33 characters.
* In real life, one should print all 40 characters
*999 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 999 999 999 999 999 999 999 99.99 
XXXXXX
****************************************************************************

   01 header-line-1.
      05         pic x(13) value \"MCA Semester\".
      05 h1-sem-no    pic 9.
      05                pic x(17) value spaces.
      05         pic x(31) value \"Result Statement\".
      05         pic x(5)  value \"Date:\".
      05 h1-dd        pic 99.
      05        pic x value \'/\'.
      05 h1-mm        pic 99.
      05        pic x value \'/\'.
      05 h1-yy        pic 99.

   01 header-line-2.
      05        pic x(62) value spaces.
      05        pic x(5) value \"Page:\".
      05 h2-page-no    pic 99.

   01 col-title-1.
      05         pic x(04) value \"No.\".
      05         pic x(34) value \"Name\".
      05         pic x(42) 
                       value \"<--Marks in Subjects--> Total     %  Class\".
* On VAX terminal format, margin B may go beyond 72

   01 col-title-2.
      05         pic x(38) value spaces.
      05         pic x(42) value \"  1   2   3   4   5   6  Marks \".
   01 detail-line.
      05 dtl-no        pic 9(3).
      05         pic x.
      05 dtl-name    pic x(33).
      05 dtl-marks-tbl occurs 6 times.
         10        pic x.
         10 dtl-marks    pic 999.
      05        pic xx.
      05 dtl-tot-marks  pic 999.
      05         pic x.
      05 dtl-prcnt    pic 999.99.
      05         pic x.
      05 dtl-result    pic x(6).

   01 dash-line        pic x(80) value all \"=\".
   01 blnk-line        pic x(80) value all spaces.

   01 stud-tot-marks    pic 999.
   01 t-subj-no        pic 9.
   01 t-marks        pic 999.
   01 tot-student    pic 999   value zero.

   01 prcnt        pic 999v99.
      88 fail   values  0 thru 49.99.
      88 second values 50 thru 59.99.
      88 first1 values 60 thru 69.99.
      88 dist   values 70 thru 100.
   01 t-result        pic x(6).

   01 tot-failed    pic 999.
   01 tot-dist        pic 999.
   01 tot-first    pic 999.
   01 tot-second    pic 999.
   01 tot-pass        pic 999.

   01 avg-tbl value zeros.
      05 avg-marks    occurs 6 times pic 999v99.

   01 smry-avg-header-1    pic x(80)
           value \"Subject  Subject                                    Average\".
   01 smry-avg-header-1    pic x(80)
           value \"    No.  Name                                       Marks\".

*   1     1234567890123456789012345678901234567890   123456
*zzz9     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX   999.99
*Subject  Subject                                    Average
*    No.  Name                                       Marks

   01 smry-line.
      05 smry-subj-no    pic 9.
      05        pic x(3) value spaces.
      05 smry-subj-name pic x(40).
      05        pic x(3) value spaces.
      05 smry-avg-marks   pic 999.99.

   01 smry-line2.
      05                pic x(4).
      05 smry-msg    pic x(40).
      05 smry-tot    pic 999.



**************************

procedure division.
  main.
        perform a10-store-subjects.
        perform b10-init-result-processs.
        perform c10-prepare-result.
        perform d10-prn-summary.
        perform e10-close.
        stop run.

  a10-store-subjects.
        display \"Enter Semester No.\" with no.
    accept h1-sem-no.
        open input subject-file.
        perform a20-init-subj-names.
        perform a30-read-store.

  a20-init-subj-names.
        perform varying i from 1 by 1 until i > 6
            move spaces to subject-name(i)
        end-perform.

  a30-read-store.
************************
* sorted subject file may reduce time, 
*   but here very few records will be there,
*      and initial records may still be required to read and skip (ex.for sem 5)

*      so no need to spend time in sorting
************************
        perform until eof=\'y\'
          move spaces to subj-rec
      read subject-file 
          at end move \'y\' to eof
             not at end perform a40-store-subj-name
          end-read  
        end-perform.
        close subject-file.

  a40-store-subj-name.
        if sem-no of subj-rec is equal to h1-sem-no
           if valid-subject
              move subj-name to subject-name(subj-no of subj-rec)
           else
              display \"Invalid subject code, out of range (1,6)\"
           end-if
        end-if.

  b10-init-result-processs.
      perform b20-sort-student.
    perform b30-open-files.
    perform b40-get-first-student.

  b20-sort-student.
    sort sort-file 
       on ascending key s-sem-no s-stud-no
       using student-file giving student-file.

  b30-open-files.
      open input  student-file
             output result-file. 

  b40-get-first-student.
*  read student file till getting first student record of given sem.
    move \'n\' to eof.
        move zero to sem-no of stud-rec.
    perform until eof = \'y\' or sem-no of stud-rec = h1-sem-no
       read student-file
              at end move \'y\' to eof
       end-read
    end-perform.

  c10-prepare-result.
    if eof=\'y\'
       display \"No student records to process\"
        else
       perform c20-process-students
        end-if.

  c20-process-students.
    perform until eof = \'y\' or sem-no of stud-rec not = h1-sem-no
       add 1 to tot-student
       perform c30-get-result
       perform c40-prn-detail-line
       read student-file 
              at end move \'y\' to eof
* if c30-c04 are used with: not at end, will process one more rec.
           end-read
        end-perform. 

  c30-get-result.
        move spaces to detail-line.
        move zeros to stud-tot-marks.
        move spaces to t-result

    perform varying i from 1 by 1 until i > 6
*       move subj-no(i) of stud-rec to t-subj-no   *** invalid
       move subj-no of stud-rec(i) to t-subj-no
       move marks(i) to t-marks, dtl-marks(t-subj-no)
* marks may be \'A00\'
           if t-marks is numeric
                add t-marks to stud-tot-marks
        add t-marks to avg-marks(t-subj-no)
        if t-marks < 40
            move \"fail\" to t-result
        end-if
           else 
         move \"fail\" to t-result
           end-if
    end-perform.

        divide stud-tot-marks by 6 giving prcnt.

*       fail may be due to < 40 or A00, In evaluate, may change if % > 50
        if t-result not = \"fail\"
*        evaluate prcnt   -- invalid, with condition name
          evaluate true
          when  fail
          move \"fail\" to t-result
        when  second
          move \"second\" to t-result
          add 1 to tot-second
        when  first1
          move \"first\" to t-result
          add 1 to tot-first
        when  dist
          move \"dist\" to t-result
          add 1 to tot-dist
          end-evaluate
        end-if.
        if t-result = \"fail\" add 1 to tot-failed.        

  c40-prn-detail-line.
    perform c50-move-detail-line.
    add 1 to line-cnt.
    if line-cnt > max-lines
       perform c60-prn-header.
    write result-rec from detail-line.
    move spaces to detail-line.

  c50-move-detail-line.
    move stud-no of stud-rec to dtl-no.
    move name to dtl-name.
*    marks already moved during get-result
    move stud-tot-marks to dtl-tot-marks.
    move prcnt to dtl-prcnt.
    move t-result to dtl-result.

  c60-prn-header.
    write result-rec from header-line-1 after advancing page.
    add 1 to h2-page-no.
    write result-rec from header-line-2.
    write result-rec from col-title-1 after 2 lines.
    write result-rec from col-title-2.
    write result-rec from dash-line.
    move 7 to line-cnt.

  d10-prn-summary.
        write result-rec from dash-line.
        move \"Summary...\" to result-rec.
    write result-rec after 2.
        move \"Average marks in different Subjects...\" to result-rec.
    write result-rec after 2.
    write result-rec from blnk-line.

    move spaces to smry-line.
    perform varying i from 1 by 1 until i > 6
      divide avg-marks(i) by tot-student giving smry-avg-marks
      move i to smry-subj-no
          move subject-name(i) to smry-subj-name
          write result-rec from smry-line
    end-perform.
        write result-rec from dash-line.

    move spaces to smry-line2.
        move \"No. of students failed\" to smry-msg.
     move tot-failed to smry-tot.
     write result-rec from smry-line2 after 2.
        move \"No. of students having second class\" to smry-msg.
     move tot-second to smry-tot.
     write result-rec from smry-line2.
        move \"No. of students having first class\" to smry-msg.
     move tot-first to smry-tot.
     write result-rec from smry-line2.
        move \"No. of students having distinction\" to smry-msg.
     move tot-dist to smry-tot.
     write result-rec from smry-line2.

  e10-close.
      close student-file
            result-file.     

 
 
Didn't find what you were looking for? Find more on Program to Create result statement for a given semester