Académique Documents
Professionnel Documents
Culture Documents
In a day !!!
2008-09-15
Copyright 2008 TietoEnator Corporation
Veena Katiyar
QA Engineer
TietoEnator Corporation
B&I
veena.katiyar@tietoenator.com
Table of contents.
• Structure of COBOL file .
• Cobol areas .
• Variable declaration .
• Structures .
• Level 77 & level 88 .
• Sentence .
• Paragraph .
• Arrays .
• Simple cobol program .
• RUN STOP .
• Decision making .
• Arithmetic operators .
• Comparision operators .
• PERFORM .
• Complex cobol program .
Copyright 2008 TietoEnator Corporation
• Questions ?
2
Structure of COBOL file .
IDENTIFICATION DIVISION.
* Specify PROGRAM-ID here .
PROGRAM-ID. COBSHL04.
ENVIRONMENT DIVISION.
Define environment here.
DATA DIVISION.
WORKING-STORAGE SECTION.
Define variables here .
PROCEDURE DIVISION.
* Write program here.
Copyright 2008 TietoEnator Corporation
Cobol areas
Position 7 :- Place an asterisk here then compiler will treat this row as
comment and will not process it .
4
Variable declaration & Structures
• The WORKING-STORAGE SECTION of the DATA DIVISION is used to create space for
the variables of a program.
• 01 STUDENT-REC .
05 FILLER PIC X(5) VALUE “Age” .
05 STUDENT-AGE PIC 9(2) VALUE ZERO.
05 FILLER PIC X(5) VALUE “Marks”.
05 MAX-MARKS PIC 999 VALUE 100 .
05 FILLER PIC x(5) VALUE “Name” .
05 STUDENT-NAME PIC X(10) VALUE SPACES .
Copyright 2008 TietoEnator Corporation
ACCEPT STUDENT-AGE .
DISPLAY STUDENT-REC .
5
Level 77 & Level 88
• Level 77 :- A variable that is not a structure can be given a level number of 77
instead of 01 .
77 YES-NO PIC X.
• A level number of 77 indicates to the compiler that the variable named after the
77 is a simple elementary variable and not a structure.
01 YES-NO PIC X.
88 ANSWER-IS-YES VALUE "Y".
* if YES-NO = “Y”
DISPLAY “Value of YES-NO is Y” .
6
Sentence & Paragraph
MAIN-PROG .
PERFORM GET-NAME .
PERFORM GET-AGE .
STOP RUN .
GET-NAME .
DISPLAY “Good Morning !!!”.
DISPLAY “Enter your name”.
ACCEPT USER-NAME .
GET-AGE .
DISPLAY “Enter your age” .
Copyright 2008 TietoEnator Corporation
ACCEPT USER-AGE .
7
Arrays
PROCEDURE DIVISION .
DISPLAY "Enter Student name [1] : ".
ACCEPT ST-NAME(1) .
DISPLAY "Enter Student age [1] : " .
ACCEPT ST-AGE(1) .
Copyright 2008 TietoEnator Corporation
DISPLAY MYTABLE(1)
8
Simple COBOL Program
IDENTIFICATION DIVISION
PROGRAM-ID. MYFIRST .
ENVIRONMENT DIVISION
DATA DIVISION
WORKING-STORAGE SECTION.
01 USER-NAME PIC X(5).
PROCEDURE SECTION .
MAIN-PROG .
PERFORM GET-NAME .
STOP RUN .
GET-NAME .
DISPLAY “Enter your name”.
ACCEPT USER-NAME .
Copyright 2008 TietoEnator Corporation
9
RUN STOP
01 MYNO PIC 9.
88 MYNO-ODD VALUES 1 3 5 7 9.
88 MYNO-EVEN VALUES 2 4 6 8 .
88 MYNO-ZERO VALUE 0.
PROCEDURE DIVISION.
IF MYNO-ODD
DISPLAY "It's a odd no."
STOP RUN .
IF MYNO-EVEN
DISPLAY "It's a even no.“
STOP RUN .
Copyright 2008 TietoEnator Corporation
IF MYNO-ZERO
DISPLAY "It's zero“
STOP RUN .
STOP RUN ends the execution at the end of the paragraph .
10
Decision making
• IF :-
DISPLAY “Enter Y or N”.
ACCEPT YES-NO .
IF YES-NO = “Y”
DISPLAY ”You have entered Y”.
IF YES-NO = “N”
DISPLAY ”You have entered N”.
• IF-ELSE :-
IF YES-NO = “Y”
DISPLAY “You have entered Y”
Copyright 2008 TietoEnator Corporation
ELSE
DISPLAY “You have not entered Y” .
11
Arithmetic operations
• Addition :-
COMPUTE SALARY = SALARY + 1000 .
ADD 1000 TO SALARY .
ADD 1000 TO 5000 GIVING SALARY .
* SALARY = 1000 + 5000
• Subtraction :-
COMPUTE SALARY = SALARY – 1000.
SUBTRACT 1000 FROM SALARY .
SUBTRACT 1000 FROM 5000 GIVING SALARY .
* SALARY = 5000 – 1000 .
• Multiplication :-
COMPUTE SALARY = SALARY * 1000 .
MULTIPLY 1000 BY SALARY .
* SALARY = SALARY * 1000 .
MULTIPLY 1000 BY 10 GIVING SALARY .
* Salary = 1000 * 10 .
Copyright 2008 TietoEnator Corporation
• Division :-
COMPUTE SALARY = SALARY / 1000 .
DIVIDE 10 INTO SALARY.
DIVIDE 17 INTO 1000 GIVING SALARY REMAINDER MY-REMAINDER .
*SALARY = 1000 / 17 .
* Remainder in MY-REMAINDER variable .
12
13
Copyright 2008 TietoEnator Corporation
Comparision Operators
PERFORM
• Paragraphs are similar to functions .
• PERFORM execute paragraphs .
PROCEDURE DIVISION .
MOVE 10 TO A B .
MOVE 10 TO A B .
PERFORM ADD-IT UNTIL B >100 .
STOP RUN .
ADD-IT .
Copyright 2008 TietoEnator Corporation
COMPUTE B = A + B .
DISPLAY B.
14
Complex COBOL Program
IDENTIFICATION DIVISION .
PROGRAM-ID . compprog .
ENVIRONMENT DIVISION .
DATA DIVISION .
WORKING-STORAGE SECTION .
77 UCASE PIC X(26) VALUE "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
77 LCASE PIC X(26) VALUE "abcdefghijklmnopqrstuvwxyz".
01 UTEXT PIC X(20) VALUE SPACES .
01 A-SPACE PIC X(5) VALUE SPACES .
01 CHOICE PIC 9 VALUE ZERO .
01 YESNO PIC X VALUE "Y".
PROCEDURE DIVISION .
PERFORM MAIN-PROC UNTIL YESNO = "N".
STOP RUN .
Copyright 2008 TietoEnator Corporation
MAIN-PROC .
PERFORM GET-DATA .
PERFORM GET-CASE.
15
PERFORM CHANGE-CASE.
PERFORM DISPLAY-DATA .
PERFORM ASK-ANOTHER .
GET-DATA .
DISPLAY A-SPACE .
DISPLAY "Enter text string > ".
ACCEPT UTEXT .
DISPLAY A-SPACE .
GET-CASE .
DISPLAY A-SPACE .
DISPLAY "Enter 1 to change to uppercase ." .
DISPLAY "Enter 2 to change to lowercase ." .
ACCEPT CHOICE .
CHANGE-CASE .
Copyright 2008 TietoEnator Corporation
IF CHOICE = 1
INSPECT UTEXT CONVERTING LCASE TO UCASE
ELSE
INSPECT UTEXT CONVERTING UCASE TO LCASE .
16
DISPLAY-DATA .
DISPLAY A-SPACE .
DISPLAY "Result :-".
DISPLAY A-SPACE .
DISPLAY UTEXT
ASK-ANOTHER .
DISPLAY A-SPACE .
17
18
Copyright 2008 TietoEnator Corporation
QUESTIONS ???
Thank you.
Copyright 2008 TietoEnator Corporation
Veena Katiyar
QA Engineer
TietoEnator Corporation
B&I
veena.katiyar@tietoenator.com