Cobol Tutorial

 
 
 

Basic Programming

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 Check if a number is a fibonacci or not

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 Student detail management using indexed file 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 Sum of series 1 + 1/4 + 1/9 Using sign test for numeric value

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 Create the index file Draw polygon Use of EVALUATE clause Count number of char Date manipulation Bubble sort DOS standard o/p device Add two numbers Generate sales report item wise

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 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 Generate arithmetic operation - evaluate clause

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 Read data from input file and move to output file 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 Display the pattern of square School management system

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 Student details using relative file 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 Multiplication table Generate sales register

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 Input record into file using extend mode 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

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
 
 
        IDENTIFICATION DIVISION.
        PROGRAM-ID. SALARY.
        ENVIRONMENT DIVISION.
        INPUT-OUTPUT SECTION.
        FILE-CONTROL.

                SELECT PAY-IN-FILE ASSIGN TO DISK
                ORGANIZATION IS LINE SEQUENTIAL.

                SELECT REG-OUT-FILE ASSIGN TO DISK
                ORGANIZATION IS LINE SEQUENTIAL.

        DATA DIVISION.
        FILE SECTION.

      *   Structure of the input file.  
        FD PAY-IN-FILE VALUE OF FILE-ID IS FILE-NAME
                    LABEL RECORDS ARE STANDARD.
        01 PAY-REC.
                05 MMYY         PIC 9999.
                05 ENO          PIC 9999.  
                05 ENAME        PIC X(22).
                05 DESIG        PIC X(10).
                05 DNO          PIC 99.
                05 CATOGRY      PIC X.
                05 GROSS        PIC 9(5)V99.
                05 PF-AMT       PIC 9(5)V99.
                05 PROF-TAX     PIC 9(5)V99.
                05 LIC-DED      PIC 9(5)V99.
                05 OTHER-DED    PIC 9(5)V99.

      *   Output file which has a variable name.  
        FD REG-OUT-FILE VALUE OF FILE-ID IS \'PRAC12.RPT\'
                     LABEL RECORDS ARE STANDARD.
        01 SLIP-REC  PIC X(130).

        WORKING-STORAGE SECTION.

      *    Structure of the Heading of the output file.
        01 HEAD1.
                05 FILLER       PIC X(25) VALUE SPACES.
                05 TITLE1       PIC X(30)
                        VALUE \'FOLLWALA INFO TECH LTD.\'.

      *    Structure of the column heads.
        01 HEAD2.
                05 FILLER       PIC X(3)          VALUE SPACES.       
                05 COL1         PIC X(5)          VALUE \'EMP.\'.
                05 FILLER       PIC X(2)          VALUE SPACES.
                05 COL2         PIC X(22)         VALUE \'EMP.\'.
                05 FILLER       PIC X(2)          VALUE SPACES.
                05 COL3         PIC X(5)          VALUE \'DEPT.\'.
                05 FILLER       PIC X(2)          VALUE SPACES.
                05 COL4         PIC X(5)          VALUE \'EMPL\'.
                05 FILLER       PIC X(2)          VALUE SPACES.
                05 COL5         PIC X(10)         VALUE \'GROSS\'.
                05 FILLER       PIC X(2)          VALUE SPACES.
                05 COL6         PIC X(10)         VALUE \'PF\'.
                05 FILLER       PIC X(2)          VALUE SPACES.
                05 COL7         PIC X(10)         VALUE \'PROF\'.
                05 FILLER       PIC X(2)          VALUE SPACES.
                05 COL8         PIC X(10)         VALUE \'LIC\'.
                05 FILLER       PIC X(2)          VALUE SPACES.
                05 COL9         PIC X(10)         VALUE \'OTHER\'.
                05 FILLER       PIC X(2)          VALUE SPACES.
                05 COL10        PIC X(10)         VALUE \'TOTAL\'.
                05 FILLER       PIC X(2)          VALUE SPACES.
                05 COL11        PIC X(10)         VALUE \'NET\'.


      *    Output record Structure.
        01 REG-REC.
                05 FILLER       PIC X(2) VALUE SPACES.
                05 ENO          PIC ZZ99.
                05 FILLER       PIC X(2) VALUE SPACES.
                05 ENAME        PIC X(22).
                05 FILLER       PIC X(4) VALUE SPACES.
                05 DNO          PIC Z9.
                05 FILLER       PIC X(6) VALUE SPACES.
                05 CATOGRY      PIC X.
                05 FILLER       PIC X(2) VALUE SPACES.
                05 GROSS        PIC ZZ,ZZ9.99.
                05 FILLER       PIC X(2) VALUE SPACES.
                05 PF-AMT       PIC ZZ,ZZ9.99.
                05 FILLER       PIC X(2) VALUE SPACES.
                05 PROF-TAX     PIC ZZ,ZZ9.99.
                05 FILLER       PIC X(2) VALUE SPACES.
                05 LIC-DED      PIC ZZ,ZZ9.99.
                05 FILLER       PIC X(3) VALUE SPACES.
                05 OTHER-DED    PIC ZZ,ZZ9.99.
                05 FILLER       PIC X(1) VALUE SPACES.
                05 NET-DED      PIC ZZ,ZZ,ZZ9.99.
                05 FILLER       PIC X(2) VALUE SPACES.
                05 NET-SAL      PIC ZZ,ZZ,ZZ9.99.

      *   Unedited totals to calculate total salaries.
        01 TOTALS.
                05 TOTAL-GROSS          PIC 9(9)V99 VALUE ZERO.
                05 TOTAL-DED            PIC 9(9)V99 VALUE ZERO.
                05 TOTAL-NET            PIC 9(9)V99 VALUE ZERO.

        77 FILE-NAME    PIC X(12) VALUE SPACES.
        77 EOF          PIC X VALUE \'N\'.
        01 USER-MMYY.
                05 U-MM PIC 99.
                05 U-YY PIC 99.
        77 TEMP-TOTAL   PIC 9(9)V99.
        77 D-LINE       PIC X(130) VALUE ALL \'-\'.

        PROCEDURE DIVISION.

      *    Main para to open the input file and process it.
        MAIN-PARA.
                DISPLAY \"ENTER THE MONTH AND YEAR :- \".
                ACCEPT USER-MMYY.
                PERFORM FIND-FILE.

                OPEN INPUT PAY-IN-FILE
                     OUTPUT REG-OUT-FILE.

                PERFORM HEAD-PARA.

                READ PAY-IN-FILE.
                PERFORM WRITE-PARA UNTIL EOF = \'Y\'.

                PERFORM FOOTER-PARA.
                CLOSE PAY-IN-FILE REG-OUT-FILE.
                STOP RUN.

      *    Depending upon input record generate the file-name.  
        FIND-FILE.
                STRING \"SLIP\" DELIMITED BY \' \'
                       USER-MMYY DELIMITED BY \' \'
                       \".DAT\" DELIMITED BY \' \' 
                       INTO FILE-NAME.

      *    Para to write the headings and col. titles in output file.
        HEAD-PARA.
                WRITE SLIP-REC FROM HEAD1.

                STRING \'SALARY REGISTER FOR :- \'
                DELIMITED BY \'/\'
                U-MM DELIMITED BY \' \'
                \'/20\' DELIMITED BY \' \'
                U-YY DELIMITED BY \' \'
                INTO TITLE1.

                WRITE SLIP-REC FROM HEAD1.

                WRITE SLIP-REC FROM D-LINE.
                WRITE SLIP-REC FROM HEAD2.

                MOVE \' NO.\'   TO COL1.
                MOVE \'NAME\'   TO COL2.
                MOVE \'NO\'     TO COL3.
                MOVE \'CATG\'   TO COL4.
                MOVE \'SALARY\' TO COL5.
                MOVE \'AMT.\'   TO COL6.
                MOVE \'TAX\'    TO COL7.
                MOVE \'DEDN\'   TO COL8, COL9, COL10.
                MOVE \'SALARY\' TO COL11.

                WRITE SLIP-REC FROM HEAD2.
                WRITE SLIP-REC FROM D-LINE.

      *    Output the record to appropriate file depending upon mmyy.
        WRITE-PARA.
                MOVE CORR PAY-REC TO REG-REC.
                PERFORM CALC-PARA.
                WRITE SLIP-REC FROM REG-REC.
                READ PAY-IN-FILE AT END MOVE \'Y\' TO EOF.


      *    Add current record to the totals.
        CALC-PARA.
                MOVE ZERO TO TEMP-TOTAL.
                ADD GROSS OF PAY-REC      TO TOTAL-GROSS.
                ADD PF-AMT OF PAY-REC     TO TEMP-TOTAL.
                ADD PROF-TAX OF PAY-REC   TO TEMP-TOTAL.
                ADD LIC-DED OF PAY-REC    TO TEMP-TOTAL.
                ADD OTHER-DED OF PAY-REC  TO TEMP-TOTAL.

                MOVE TEMP-TOTAL TO NET-DED.
                ADD TEMP-TOTAL TO TOTAL-DED.
                COMPUTE TOTAL-NET = TOTAL-NET +
                        ( GROSS OF PAY-REC - TEMP-TOTAL).

                COMPUTE NET-SAL = GROSS OF PAY-REC - TEMP-TOTAL.

      *    Para to print the footer report.  
        FOOTER-PARA.
                WRITE SLIP-REC FROM D-LINE.
                MOVE SPACES TO REG-REC.
                MOVE \'TOTAL  : \' TO ENAME OF REG-REC.
                MOVE TOTAL-GROSS TO GROSS OF REG-REC.
                MOVE TOTAL-DED TO NET-DED OF REG-REC.
                MOVE TOTAL-NET TO NET-SAL OF REG-REC.
                WRITE SLIP-REC FROM REG-REC.
                WRITE SLIP-REC FROM D-LINE.



/***********************************************************************************************    
                                     OUTPUT        
***********************************************************************************************/

                         FOLLWALA INFO TECH LTD.                                                                                  
                         SALARY REGISTER FOR :- 02/2003                                                                           
----------------------------------------------------------------------------------------------------------------------------------
   EMP.   EMP.                    DEPT.  EMPL   GROSS       PF          PROF        LIC         OTHER       TOTAL       NET       
    NO.   NAME                    NO     CATG   SALARY      AMT.        TAX         DEDN        DEDN        DEDN        SALARY    
----------------------------------------------------------------------------------------------------------------------------------
    01  VD                         1      M   1,000.00     110.00      20.00      10.00       10.00       150.00        850.00    
    02  KHALAS KAPIL               1      S   5,000.00      10.00      30.00      10.00       10.00        60.00      4,940.00    
    03  MODI VISHAL                1      D   2,000.00     100.00      50.00      10.00       10.00       170.00      1,830.00    
    04  HARSH CHAUHAN              2      O     100.00       5.00      40.00      10.00       10.00        65.00         35.00    
    05  ANISHA CHAUHAN             2      C     500.00       8.00      30.00      10.00       10.00        58.00        442.00    
    06  PATEL TAPAN                2      W   2,000.00       7.00      20.00      10.00       10.00        47.00      1,953.00    
----------------------------------------------------------------------------------------------------------------------------------
        TOTAL  :                             10,600.00                                                    550.00     10,050.00    
----------------------------------------------------------------------------------------------------------------------------------

 
 
Didn't find what you were looking for? Find more on Program to generate a sales register