SlideShare une entreprise Scribd logo
1  sur  27
COBOL
• Cobol is one of the most robust language in the software field, so far
• Cobol turned 50, in 2009
• Cobol has stood the test of time
• Common Business Oriented Language
• It is very simple, no confusion
• English like language – people think better in natural language than in
programming language
• Number of lines coded in COBOL as on date, exceeds the cumulative total
number of lines coded in all known programming languages
• Data maintained by COBOL program will take 10 to 15 years by a super
computer, to be migrated to another platform or technology
• Hence COBOL is here to stay further
• Demand for COBOL still continues with same or more strength
• COBOL has adapted well to stay fit in new millennium as well
• Unfortunately people have the myth in mind, that COBOL is out dated
• All big time software service companies, invariably work in COBOL and train
people in COBOL, year after year
Program Structure
• Each program has 4 divisions
– Identification division
– Environment division
– Data division
– Procedure division
• Each division has sections within them
• The section names are different for each
division
• Each section has definition or logic
statements
Identification Division
• This is the primary section that gives an identity to the program
• COBOL is not case sensitive – we can write code in uppercase or
lowercase letters
• PROGRAM-ID is the main phrase in this section that gives a unique
name to programs.
• DATE-WRITTEN and DATE-COMPILED are used to denote
documenting part of the program
• AUTHOR is the clause to specify the name of the programmer.
• Identification division.
• Program-id. Myprog.
• Author. Naga.
• Date-written. 12-10-2008.
• Date-compiled. 13-10-2008.
Margins
• Since cobol evolved from punched cards time, the
program lines are restricted to 80 column width
• In this also, there are column boundaries that play major
role
• Columns 1 to 6 are meant for line numbers
• Column 7 is meant for comment. A star mark in this
column, denotes that line is a comment
• Column 8 is called A margin. Columns 8 to 11 is called A
area
• Column 12 is called B margin. Columns 12 to 80 is
called B area
• Some statements must start from A area, and some
other must start from B area.
• If margin rules are not followed, the compiler will issue a
syntax error
Environment Division
• This is used to specify the computer types, special
symbols and files related data.
• This can have CONFIGURATION SECTION and INPUT-
OUTPUT SECTION.
• Configuration section can have the following.
– SOURCE-COMPUTER. TDM180.
– OBJECT-COMPUTER. TDM180.
– SEPCIAL-NAMES.
- DECIMAL POINT IS COMMA, CURRENCY SIGN IS “$”.
• In some countries the decimal points is not a dot and the
currency signs keep varying.
• Input-output section is mainly for file specifications. This
is given at the end of the presentation.
Data Division
• This is used to declare variables, screens,
parameters to other programs and file record
descriptions.
• This can have file section, working-storage
section, linkage section, screen section.
• If sections are not used, they can be omitted as
well. But usually every program will have at least
one variable declaration.
• Unlike other languages, ALL VARIABLES
DECLARED IN A PROGRAM ARE GLOBAL
VARIABLES.
Variables
• Variables are to be declared in working-storage section
• Variables can be scalar, arrays, records, file descriptor records
• The name of variable can have alphanumeric, with first character as alphabet, and can have only dash (hyphen)
in it. Hypen must be embedded
• The type of variable is determined by the picture clause
• 77 level variables are scalar variables; arrays and records are explained later in this presentation
• 77 var-1 picture 999.
– 9 stands for a single digit number. This is a 3 digit number
• 77 var-2 picture xxx.
– X stands for alphanumeric. This is a 3 character alphanumeric
• 77 var-3 picture S99.99
– S sign for numeric variable stands for sign + or -. A dot in picture clause with trailing 9s will indicate the number of decimals. Dot
stands for explicit decimal point
• 77 var-4 picture 9(5) value 100.
– Value specifies what must be the initial value when variable is created
• 77 var-4 picture a(20) value all “a”.
– Picture A stands for alphabetic. All clause in value, will fill the entire variable with that value.
• 9(4) in picture clause is same as 9999, and x(5) is same as xxxxx. The repetition count can be given in brackets.
• 77 var-5 picture 99V99
– V in picture clause with trailing 9s will indicate the number of decimals. V stands for explicit decimal point. In storage, the decimal
point will not be stored as a character. Hence when storing in disk, it will store 99.78 as 9978, without decimal point. But it will know
last 2 digits are for decimal.
• 77 var-6 picture zzz9.99.
• If this variable has a value of 59.28, and picture is set as 9999.99, it will display as 0059.28. If we do not want to
display leading zeroes, we must use z to suppress zeroes.
Procedure Division
• This is the place where the program logic is coded.
• This can have user defined sections. Usually, this is
segmented as multiple paragraphs.
• Each paragraph is a set of statements that can act as a
function or procedure as used in other languages
• Since all variables are global, every variable is
accessible from every paragraph within that program.
• Statement delimiter is dot.
• Procedure division para names must start in A area
• Procedure division statements must start in B area
• The program starts from the very first line of the
procedure division till the statement STOP RUN is
reached.
Initializing Variables
• Move is used to set the value of variables
• Assume v1 is numeric and s1 is alphanumeric
text
– Move zeroes to n1.
– Move spaces to s1
• There is a verb Initialize that can automatically
determine the type of variable and move either
zeroes or spaces
– Initialize n1.
– Initialize s1.
Simple User Input
• Accept is the verb to get values from user
• Accep1 n1. – This will get the values from user,
from the cursor position
• Accept (10, 15) n1. – This will get the value of
the variable at line 10 column 15 on the screen
• Accept (10, 15) n1 with prompt. – This will do
same as above, except it will display dashes so
that you the length of the variable
• Accept n1 from date. – This will give you the
current system date into variable
• Accept n1 from time. – This will give you the
current system time into variable
Simple Output
• Display is the verb to display values of
variables on screen
• Display n1. – This will display the values
on screen, from the cursor position
• Display (10, 15) n1. – This will display the
value of the variable at line 10 column 15
on the screen
• Display Blank screen. – This will erase the
content of screen. This must be defined in
screen section.
Arithmetic Verbs
• Unlike other languages, cobol prefers to
explicitly spell out the operations.
– Add v1 to v2 giving v3.
– Subtract v1 from v2 giving v3.
– Multiply v1 by v2 giving v3.
– Divide v1 by v2 giving v3 remainder v4.
• Formula can be expressed thru compute
verb
– Compute v1 = (v2 + v3) * (v2 – v3).
Conditions
• If and Evaluate are used for conditional branching
• The relational operators as well as spelt out phrases can be used
• If a < b – this can be written as if a is less than b
• >, <, =, >=, <= are the available relational operators
• NOT, AND, OR are the logical operators
• Less than, greater than, equal to are the spelt out phrases
• If a is less than b then
Do some thing
• Else
• Do the other way
• End-if.
• To check an alphanumeric variable for what type of data it holds, we
can use if a is numeric, if a is alphabetic, conditions. Based on the
value this will be true or false. We can then take decisions.
Multiple Conditions
• We can use if-then-else if for multi level conditions
• To make it very simple, we can use evaluate verb
• Evaluate a
• When 1 perform para1
• When 2 perform para2
• When 3 perform para3
• When other perform para4
• End-evaluate
• Each when statement will be treated as a separate if condition. When 3 here
means, if a is equal to 3.
• If no condition is matched, the other clause is executed. This is similar to the
switch statements in other languages.
• Without checking anything, we can transfer the program flow using go to.
GO TO mypara. This will suddenly branch to that para. Go To is not
supposed to be used, as it is not a good programming practice.
Perform Loop
• Perform is the loop in cobol
• There are many variations of this verb
• Perform para1. This will execute only that para only once
• Perform para1 5 times. This will repeat the execution
• Perform para1 thru para5. This will execute any para
from para1 to para5, that appear one after the other on
the source code
• Perform para1 until a < b. This will execute the para until
the condition becomes true.
• Perform para1 varying v1 from 1 by 1 until v1 > 10. This
will use v1 as the loop counter and increment it by 1, till it
reaches 10.
Records
• Records are nothing but collection of related variables
• These are equivalent to structures in other languages
• The record variables do have level numbers
• Level numbers 1 to 76 are used
• 01 employee-record.
• 05 employee-code picture 9(5).
• 05 employee-name picture x(30).
• 05 dob.
• 10 yyyy picture 9999.
• 10 mm picture 99.
• 10 dd picture 99.
• 05 designation picture x(3).
• 05 doj.
• 10 yyyy picture 9999.
• 10 mm picture 99.
• 10 dd picture 99.
• 05 salary picture 9(6).99.
• The record can have any levels. They are grouped by level numbers.
– Yyyy is the sub field of dob. Dob itself is a sub field of employee-record.
• To denote a field in a record, we need to qualify with OF.
– Yyyy of doj of employee-record
– Designation of employee-record
Move Corresponding
• When we have 2 similar records, and we want to move data from one to the other, we
can use this
• We need not write separate move statements for each field of the record
• 01 rec1.
• 05 field1 pic 999.
• 05 field2 pic xx.
• 05 filed3 pic x.
• 01 rec2.
• 05 field2 pic xx.
• 05 filed3 pic x.
• 05 field1 pic 999.
• To move data in a single statements, to respective fields, we can say
– Move corresponding rec1 to rec2.
• This will move field1 of rec1 to field1 of rec2, field2 of rec1 to field2 of rec2, field3 of
rec1 to field3 of rec2.
• Though the fields are in different positions in the 2 records, cobol will match the field
names and then move values.
Condition Names
• Variables hold values, and based on these values we may have to
take decisions in code
• Usual way is to have an if condition to see whether the variable
satisfies a condition
• This can be easily done in a more readable way using condition
names
• 77 mm pic 99.
• 88 jan value 01.
• 88 feb value 02.
• 88 march value 03.
• 88 april value 04.
• We can write if condition to check the month as if mm = 2 then…
• The same can be written in a better way as if jan then. When mm is
set to 1, this name jan is set to true and if condition becomes true.
• People prefer to write English like conditions, such as, if file-is-
closed, if account-is-active, if ticket-is-confirmed etc. This makes
programs simple
Arrays
• Arrays are nothing but a set of variables with same
name, differentiated by an index number
• 01 rec1.
– 05 student-name picture x(30) occurs 100 times.
• Occurs clause determines the number of elements in an
array
• Move spaces to student-name (10) will access the 10th
element of the array
• Arrays start with index as 1
• Any element that is accessed beyond the limit will throw
a runtime error and hence we need to be careful
• We can have multi level arrays also, but they are very
rarely used in business applications
File Handling
• Cobol supports sequential files, relative files and indexed files
• To handle files, we must specify file type and mode in input-output section
• The following is a standard one when we need to access files - SELECT myfile ASSIGN TO DISK
• Myfile is just a logical name that we want to use later in program. It can be EmployeeFile, PayFile
etc
• In data division, we must have a FD (file descriptor) part and record definition of the same
• There are RD and SD definitions (reporting and sorting descriptions). These 2 are not discussed
in this presentation
• We can access disk, tape and printer files. In that case, the assign to clause will change.
• In procedure division, OPEN, READ, WRITE, START, REWRITE, DELETE, CLOSE are the
common verbs that we will use to deal with files.
• Every file operation must be checked for the status of the operation. COBOL gives the status of
last operation in a variable called file-status.
• In working-storage, we must define a variable ws-fs.
– 01 ws-fs.
– 05 s1 pic 9.
– 05 s2 pic 9.
• It contains 2 parts, first digit and second digit. A zero in both digits indicates, success; all other
codes must be handled specially.
• Standard practice is to load record with values before WRITE and initialize record before READ
operations
Defining Sequential Files
• In sequential files, we can add records one after the other and read them one after the other.
• We cannot directly jump to any record we want; we need to go from the beginning
• SELECT myfile assign to disk
• Organization is sequential
• Access mode is sequential
• file status is ws-fs.
• In the FD part of file section, we must use the standard phrases to attach a physical file to the logical name myfile.
• FD FD myfile
• RECORD CONTAINS 62 CHARACTERS
• LABEL RECORD IS STANDARD
• DATA RECORD IS employee-record
• VALUE OF FILE-ID "myfile.DAT".
• 01 employee-record.
• 05 emp-code pic 9(5).
• 05 emp-name pic x(30).
• 05 dob pic 9(8).
• 05 doj pic 9(8).
• 05 designation pic x(3).
• 05 ctc pic 9(6)V99.
• The record character count given in the 01 record, must match with FD description.
• Label record is to tell the file system of the machine that they must be standard. Other clause can be OMITTED
• FILE-ID is the one that actually binds a physical file myfile.dat to the logical file.
Handling Sequential Files
• Open statement must have the mode specified.
• The open modes are input, output, extend
• We cannot delete a record in a sequential file; however we can even rewrite records, only in certain cobol
versions
• In many to most cobol versions, opening sequential file in I-O mode is not allowed
• For input mode, the file must exist; in output mode, the previous file data will be erased; in extend mode, the
previous file data can be appended with new data
• Open Input myfile.
– Open extend myfile.
• To write data to the file, we must first load valid data to the file record, as given in the FD part
• Then we need to issue a WRITE command
– WRITE emp-record
– END-WRITE
• To read a record, we must use READ command. The AT END clause, will tell whether we reached end of file or
not.
• READ myfile
• AT END move 1 to ws-end-of-file
• END-READ
• The read will get the record that is fetched from the disk to the FD record.
• To close the file, use, CLOSE myfile.
• When program ends, all open files will be closed.
Relative Files
• Relative files are used, to directly jump to any
record based on the position of the record
• E.g. If we want to go to the 57th
record in a file,
we can use relative files
• However, relative files are nowadays very rarely
used and they are replaced by indexed files
• For relative file, we must define organization is
relative, access mode is random.
• Since it is not used practically in current day
scenarios, we do not address it in this
presentation
Defining Indexed Files
• Indexed files are one of the most used file types as they establish a good DBMS
• Records in indexed files can be accessed sequentially or randomly as we like
• Using relative files, based on some key values, we can search for a record and the search is binary search and not sequential search;
hence it is faster
• COBOL can handle billions of records in indexed file itself
• SELECT myfile assign to disk
• Organization is indexed
• Access mode is dynamic
• Record key is emp-code of employee-record
• file status is ws-fs.
• In the FD part of file section, we must use the standard phrases to attach a physical file to the logical name myfile.
• FD FD myfile
• RECORD CONTAINS 62 CHARACTERS
• LABEL RECORD IS STANDARD
• DATA RECORD IS employee-record
• VALUE OF FILE-ID "myfile.DAT".
• 01 employee-record.
• 05 emp-code pic 9(5).
• 05 emp-name pic x(30).
• 05 dob pic 9(8).
• 05 doj pic 9(8).
• 05 designation pic x(3).
• 05 ctc pic 9(6)V99.
• In the above file, we can search for any emp-code much faster.
Accessing Indexed Files
• The open mode can be input, i-o, or output.
• Close command is same for all types of files
• If the file is opened with sequential access mode, we can use, this type of command to keep on reading the next records
• READ SupplierFile
• NEXT RECORD
• AT END SET EndOfFile TO TRUE
• END-READ
• If the access mode is set to direct access, we can use this type of read command, to go to the specific record that has the key.
• READ SupplierFile
• INVALID KEY DISPLAY "SUPP STATUS :-", SupplierStatus
• END-READ
• If a record with the key value populated before read, is not found, invalid key statement is executed
• If the access mode is dynamic, we can use start verb to position the reading point based on some key value.
• START Oil-Details-File
• KEY IS GREATER THAN 150
• INVALID KEY DISPLAY "Start Error”
• END-START.
• We can use equal to, less than and other operators in the Key clause of start. If a key is found satisfying the condition, the start is
successful; else invalid key statement is executed
• WRITE command is also used with INVALID KEY clause
• REWRITE can be used to update a record, provided we have executed a START command before rewriting, so that the correct record is
pointed.
• REWRITE is also used along with INVALID KEY option
Program Branching, Termination
• We can use CALL command to call another compiled
cobol program
• CALL “prog2”.
• The “prog2” must be the one appearing in program-id of
the called program
• If we define, linkage section, we can use call “prog2”
using linkage-entries.
• Linkage section is not discussed in this presentation.
• To stop a program from execution, use STOP RUN.
• To exit from a called program, use EXIT PROGRAM.
• To exit from a paragraph, use EXIT.
Example Programs
• Refer to this site.
• You will get a lot of examples.
• Syntax may slightly vary between IBM, HP
and other COBOL versions.
• But, get the concept, right.
• http://www.csis.ul.ie/COBOL/examples/default

Contenu connexe

Tendances

Oracle Unified Method (OUM)
Oracle Unified Method (OUM) Oracle Unified Method (OUM)
Oracle Unified Method (OUM) UBC Corporation
 
c# usage,applications and advantages
c# usage,applications and advantages c# usage,applications and advantages
c# usage,applications and advantages mohamed drahem
 
Oracle Fusion & Cloud Applications Overview
Oracle Fusion & Cloud Applications OverviewOracle Fusion & Cloud Applications Overview
Oracle Fusion & Cloud Applications OverviewAhmed El-Demasy
 
UNIFIED MODELING LANGUAGE
UNIFIED MODELING LANGUAGEUNIFIED MODELING LANGUAGE
UNIFIED MODELING LANGUAGERaval Chirag
 
Object Oriented Approach for Software Development
Object Oriented Approach for Software DevelopmentObject Oriented Approach for Software Development
Object Oriented Approach for Software DevelopmentRishabh Soni
 
Oracle Planning and Budgeting Cloud Service
Oracle Planning and Budgeting Cloud ServiceOracle Planning and Budgeting Cloud Service
Oracle Planning and Budgeting Cloud ServiceDatavail
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loadersTech_MX
 
Oracle ERP Cloud implementation tips
Oracle ERP Cloud implementation tipsOracle ERP Cloud implementation tips
Oracle ERP Cloud implementation tipsPrabal Saha
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design IntroductionRicha Sharma
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compileradilmehmood93
 
Oracle Financials R12 - GL STEP 1 - Chart Of Accounts
Oracle Financials R12 - GL STEP 1 - Chart Of AccountsOracle Financials R12 - GL STEP 1 - Chart Of Accounts
Oracle Financials R12 - GL STEP 1 - Chart Of AccountsMohammed Raouf
 
Oracle Fusion Payments
Oracle Fusion Payments Oracle Fusion Payments
Oracle Fusion Payments Berry Clemens
 

Tendances (20)

Abap reports
Abap reportsAbap reports
Abap reports
 
Oracle Unified Method (OUM)
Oracle Unified Method (OUM) Oracle Unified Method (OUM)
Oracle Unified Method (OUM)
 
c# usage,applications and advantages
c# usage,applications and advantages c# usage,applications and advantages
c# usage,applications and advantages
 
Assembler
AssemblerAssembler
Assembler
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
 
Oracle Fusion & Cloud Applications Overview
Oracle Fusion & Cloud Applications OverviewOracle Fusion & Cloud Applications Overview
Oracle Fusion & Cloud Applications Overview
 
UNIFIED MODELING LANGUAGE
UNIFIED MODELING LANGUAGEUNIFIED MODELING LANGUAGE
UNIFIED MODELING LANGUAGE
 
Object Oriented Approach for Software Development
Object Oriented Approach for Software DevelopmentObject Oriented Approach for Software Development
Object Oriented Approach for Software Development
 
Linker and Loader
Linker and Loader Linker and Loader
Linker and Loader
 
Oracle Planning and Budgeting Cloud Service
Oracle Planning and Budgeting Cloud ServiceOracle Planning and Budgeting Cloud Service
Oracle Planning and Budgeting Cloud Service
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
Oracle ERP Cloud implementation tips
Oracle ERP Cloud implementation tipsOracle ERP Cloud implementation tips
Oracle ERP Cloud implementation tips
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
Opm costing
Opm costingOpm costing
Opm costing
 
CORBA.ppt
CORBA.pptCORBA.ppt
CORBA.ppt
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
 
Oracle Financials R12 - GL STEP 1 - Chart Of Accounts
Oracle Financials R12 - GL STEP 1 - Chart Of AccountsOracle Financials R12 - GL STEP 1 - Chart Of Accounts
Oracle Financials R12 - GL STEP 1 - Chart Of Accounts
 
C Programming Language
C Programming LanguageC Programming Language
C Programming Language
 
Oracle Fusion Payments
Oracle Fusion Payments Oracle Fusion Payments
Oracle Fusion Payments
 

En vedette

COBOL FOR FRESHER
COBOL FOR FRESHERCOBOL FOR FRESHER
COBOL FOR FRESHERNirmal Pati
 
Jcl interview questions
Jcl interview questionsJcl interview questions
Jcl interview questionsganjigirish
 
Top jcl interview questions and answers job interview tips
Top jcl interview questions and answers job interview tipsTop jcl interview questions and answers job interview tips
Top jcl interview questions and answers job interview tipsjcltutorial
 
Top 9 mainframe testing interview questions answers
Top 9 mainframe testing interview questions answersTop 9 mainframe testing interview questions answers
Top 9 mainframe testing interview questions answersjonhmart036
 
Problem Determination Tools
Problem Determination ToolsProblem Determination Tools
Problem Determination ToolsCICS ROADSHOW
 
Cobol performance tuning paper lessons learned - s8833 tr
Cobol performance tuning paper   lessons learned - s8833 trCobol performance tuning paper   lessons learned - s8833 tr
Cobol performance tuning paper lessons learned - s8833 trPedro Barros
 
1004 z2 env_positioned
1004 z2 env_positioned1004 z2 env_positioned
1004 z2 env_positionedHenning Blohm
 
IBM Cobol Programming
IBM Cobol ProgrammingIBM Cobol Programming
IBM Cobol ProgrammingRui Andrade
 
O novo IBM COBOL ENTERPRISE V5/V6 para zOS e o IBM ABO
O novo IBM COBOL ENTERPRISE V5/V6 para zOS e o IBM ABOO novo IBM COBOL ENTERPRISE V5/V6 para zOS e o IBM ABO
O novo IBM COBOL ENTERPRISE V5/V6 para zOS e o IBM ABOPaulo Batuta
 
Presentation on Logical Operators
Presentation on Logical OperatorsPresentation on Logical Operators
Presentation on Logical OperatorsSanjeev Budha
 
Searching linear &amp; binary search
Searching linear &amp; binary searchSearching linear &amp; binary search
Searching linear &amp; binary searchnikunjandy
 

En vedette (18)

COBOL
COBOLCOBOL
COBOL
 
COBOL FOR FRESHER
COBOL FOR FRESHERCOBOL FOR FRESHER
COBOL FOR FRESHER
 
Operators
OperatorsOperators
Operators
 
Jcl interview questions
Jcl interview questionsJcl interview questions
Jcl interview questions
 
Cobol interview-questions
Cobol interview-questionsCobol interview-questions
Cobol interview-questions
 
JCL DFSORT
JCL DFSORTJCL DFSORT
JCL DFSORT
 
Top jcl interview questions and answers job interview tips
Top jcl interview questions and answers job interview tipsTop jcl interview questions and answers job interview tips
Top jcl interview questions and answers job interview tips
 
Top 9 mainframe testing interview questions answers
Top 9 mainframe testing interview questions answersTop 9 mainframe testing interview questions answers
Top 9 mainframe testing interview questions answers
 
Problem Determination Tools
Problem Determination ToolsProblem Determination Tools
Problem Determination Tools
 
Automatic Performance Improvement for Legacy COBOL
Automatic Performance Improvement for Legacy COBOLAutomatic Performance Improvement for Legacy COBOL
Automatic Performance Improvement for Legacy COBOL
 
Cobol performance tuning paper lessons learned - s8833 tr
Cobol performance tuning paper   lessons learned - s8833 trCobol performance tuning paper   lessons learned - s8833 tr
Cobol performance tuning paper lessons learned - s8833 tr
 
myslide1
myslide1myslide1
myslide1
 
1004 z2 env_positioned
1004 z2 env_positioned1004 z2 env_positioned
1004 z2 env_positioned
 
IBM Cobol Programming
IBM Cobol ProgrammingIBM Cobol Programming
IBM Cobol Programming
 
Mainframe interview
Mainframe interviewMainframe interview
Mainframe interview
 
O novo IBM COBOL ENTERPRISE V5/V6 para zOS e o IBM ABO
O novo IBM COBOL ENTERPRISE V5/V6 para zOS e o IBM ABOO novo IBM COBOL ENTERPRISE V5/V6 para zOS e o IBM ABO
O novo IBM COBOL ENTERPRISE V5/V6 para zOS e o IBM ABO
 
Presentation on Logical Operators
Presentation on Logical OperatorsPresentation on Logical Operators
Presentation on Logical Operators
 
Searching linear &amp; binary search
Searching linear &amp; binary searchSearching linear &amp; binary search
Searching linear &amp; binary search
 

Similaire à Cobol basics 19-6-2010

Cobol programming language
Cobol programming languageCobol programming language
Cobol programming languageBurhan Ahmed
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxssusere336f4
 
Basic syntax : Algorithm,Flow chart
Basic syntax : Algorithm,Flow chartBasic syntax : Algorithm,Flow chart
Basic syntax : Algorithm,Flow chartPrasanna R Kovath
 
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Blue Elephant Consulting
 
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Blue Elephant Consulting
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and importiamluqman0403
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variablesTony Apreku
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structureSelf-Employed
 
Mediump support in Mesa (XDC 2019)
Mediump support in Mesa (XDC 2019)Mediump support in Mesa (XDC 2019)
Mediump support in Mesa (XDC 2019)Igalia
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageCSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageZubayer Farazi
 
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxssusere336f4
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGEINTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGERathnaM16
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt8759000398
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Rasan Samarasinghe
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageDr.Florence Dayana
 

Similaire à Cobol basics 19-6-2010 (20)

Cobol programming language
Cobol programming languageCobol programming language
Cobol programming language
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptx
 
C Language Part 1
C Language Part 1C Language Part 1
C Language Part 1
 
Basic syntax : Algorithm,Flow chart
Basic syntax : Algorithm,Flow chartBasic syntax : Algorithm,Flow chart
Basic syntax : Algorithm,Flow chart
 
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
 
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
 
CPP07 - Scope
CPP07 - ScopeCPP07 - Scope
CPP07 - Scope
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variables
 
C programming language
C programming languageC programming language
C programming language
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
 
Mediump support in Mesa (XDC 2019)
Mediump support in Mesa (XDC 2019)Mediump support in Mesa (XDC 2019)
Mediump support in Mesa (XDC 2019)
 
CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageCSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
 
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptx
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGEINTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
Qbasic notes
Qbasic notesQbasic notes
Qbasic notes
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 

Plus de SivaprasanthRentala1975 (20)

Testing using load runner performance testing
Testing using load runner  performance testingTesting using load runner  performance testing
Testing using load runner performance testing
 
Why contract savings are missing
Why contract savings are missingWhy contract savings are missing
Why contract savings are missing
 
Voyager scm
Voyager scmVoyager scm
Voyager scm
 
Volumes
VolumesVolumes
Volumes
 
The new mainframe
The new mainframeThe new mainframe
The new mainframe
 
Test execution may_04_2006
Test execution may_04_2006Test execution may_04_2006
Test execution may_04_2006
 
Telecom testing
Telecom testingTelecom testing
Telecom testing
 
Six sigma
Six sigmaSix sigma
Six sigma
 
Sdlc models
Sdlc modelsSdlc models
Sdlc models
 
Sdlc
SdlcSdlc
Sdlc
 
Scm
ScmScm
Scm
 
Pt presentation1
Pt presentation1Pt presentation1
Pt presentation1
 
Pp employee learnnig initiative-iss-220-g tle 2007
Pp employee learnnig initiative-iss-220-g tle 2007Pp employee learnnig initiative-iss-220-g tle 2007
Pp employee learnnig initiative-iss-220-g tle 2007
 
Performance testing and rpt
Performance testing and rptPerformance testing and rpt
Performance testing and rpt
 
Patents
PatentsPatents
Patents
 
Xpediter kanbay
Xpediter kanbayXpediter kanbay
Xpediter kanbay
 
Copy of good quotes.ppt
Copy of good quotes.pptCopy of good quotes.ppt
Copy of good quotes.ppt
 
Contract savings new
Contract savings newContract savings new
Contract savings new
 
Contract savings schema
Contract savings schemaContract savings schema
Contract savings schema
 
Contract savings may 10th 2004 by gm euro
Contract savings may 10th 2004 by gm euroContract savings may 10th 2004 by gm euro
Contract savings may 10th 2004 by gm euro
 

Dernier

Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 

Dernier (20)

Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 

Cobol basics 19-6-2010

  • 1. COBOL • Cobol is one of the most robust language in the software field, so far • Cobol turned 50, in 2009 • Cobol has stood the test of time • Common Business Oriented Language • It is very simple, no confusion • English like language – people think better in natural language than in programming language • Number of lines coded in COBOL as on date, exceeds the cumulative total number of lines coded in all known programming languages • Data maintained by COBOL program will take 10 to 15 years by a super computer, to be migrated to another platform or technology • Hence COBOL is here to stay further • Demand for COBOL still continues with same or more strength • COBOL has adapted well to stay fit in new millennium as well • Unfortunately people have the myth in mind, that COBOL is out dated • All big time software service companies, invariably work in COBOL and train people in COBOL, year after year
  • 2. Program Structure • Each program has 4 divisions – Identification division – Environment division – Data division – Procedure division • Each division has sections within them • The section names are different for each division • Each section has definition or logic statements
  • 3. Identification Division • This is the primary section that gives an identity to the program • COBOL is not case sensitive – we can write code in uppercase or lowercase letters • PROGRAM-ID is the main phrase in this section that gives a unique name to programs. • DATE-WRITTEN and DATE-COMPILED are used to denote documenting part of the program • AUTHOR is the clause to specify the name of the programmer. • Identification division. • Program-id. Myprog. • Author. Naga. • Date-written. 12-10-2008. • Date-compiled. 13-10-2008.
  • 4. Margins • Since cobol evolved from punched cards time, the program lines are restricted to 80 column width • In this also, there are column boundaries that play major role • Columns 1 to 6 are meant for line numbers • Column 7 is meant for comment. A star mark in this column, denotes that line is a comment • Column 8 is called A margin. Columns 8 to 11 is called A area • Column 12 is called B margin. Columns 12 to 80 is called B area • Some statements must start from A area, and some other must start from B area. • If margin rules are not followed, the compiler will issue a syntax error
  • 5. Environment Division • This is used to specify the computer types, special symbols and files related data. • This can have CONFIGURATION SECTION and INPUT- OUTPUT SECTION. • Configuration section can have the following. – SOURCE-COMPUTER. TDM180. – OBJECT-COMPUTER. TDM180. – SEPCIAL-NAMES. - DECIMAL POINT IS COMMA, CURRENCY SIGN IS “$”. • In some countries the decimal points is not a dot and the currency signs keep varying. • Input-output section is mainly for file specifications. This is given at the end of the presentation.
  • 6. Data Division • This is used to declare variables, screens, parameters to other programs and file record descriptions. • This can have file section, working-storage section, linkage section, screen section. • If sections are not used, they can be omitted as well. But usually every program will have at least one variable declaration. • Unlike other languages, ALL VARIABLES DECLARED IN A PROGRAM ARE GLOBAL VARIABLES.
  • 7. Variables • Variables are to be declared in working-storage section • Variables can be scalar, arrays, records, file descriptor records • The name of variable can have alphanumeric, with first character as alphabet, and can have only dash (hyphen) in it. Hypen must be embedded • The type of variable is determined by the picture clause • 77 level variables are scalar variables; arrays and records are explained later in this presentation • 77 var-1 picture 999. – 9 stands for a single digit number. This is a 3 digit number • 77 var-2 picture xxx. – X stands for alphanumeric. This is a 3 character alphanumeric • 77 var-3 picture S99.99 – S sign for numeric variable stands for sign + or -. A dot in picture clause with trailing 9s will indicate the number of decimals. Dot stands for explicit decimal point • 77 var-4 picture 9(5) value 100. – Value specifies what must be the initial value when variable is created • 77 var-4 picture a(20) value all “a”. – Picture A stands for alphabetic. All clause in value, will fill the entire variable with that value. • 9(4) in picture clause is same as 9999, and x(5) is same as xxxxx. The repetition count can be given in brackets. • 77 var-5 picture 99V99 – V in picture clause with trailing 9s will indicate the number of decimals. V stands for explicit decimal point. In storage, the decimal point will not be stored as a character. Hence when storing in disk, it will store 99.78 as 9978, without decimal point. But it will know last 2 digits are for decimal. • 77 var-6 picture zzz9.99. • If this variable has a value of 59.28, and picture is set as 9999.99, it will display as 0059.28. If we do not want to display leading zeroes, we must use z to suppress zeroes.
  • 8. Procedure Division • This is the place where the program logic is coded. • This can have user defined sections. Usually, this is segmented as multiple paragraphs. • Each paragraph is a set of statements that can act as a function or procedure as used in other languages • Since all variables are global, every variable is accessible from every paragraph within that program. • Statement delimiter is dot. • Procedure division para names must start in A area • Procedure division statements must start in B area • The program starts from the very first line of the procedure division till the statement STOP RUN is reached.
  • 9. Initializing Variables • Move is used to set the value of variables • Assume v1 is numeric and s1 is alphanumeric text – Move zeroes to n1. – Move spaces to s1 • There is a verb Initialize that can automatically determine the type of variable and move either zeroes or spaces – Initialize n1. – Initialize s1.
  • 10. Simple User Input • Accept is the verb to get values from user • Accep1 n1. – This will get the values from user, from the cursor position • Accept (10, 15) n1. – This will get the value of the variable at line 10 column 15 on the screen • Accept (10, 15) n1 with prompt. – This will do same as above, except it will display dashes so that you the length of the variable • Accept n1 from date. – This will give you the current system date into variable • Accept n1 from time. – This will give you the current system time into variable
  • 11. Simple Output • Display is the verb to display values of variables on screen • Display n1. – This will display the values on screen, from the cursor position • Display (10, 15) n1. – This will display the value of the variable at line 10 column 15 on the screen • Display Blank screen. – This will erase the content of screen. This must be defined in screen section.
  • 12. Arithmetic Verbs • Unlike other languages, cobol prefers to explicitly spell out the operations. – Add v1 to v2 giving v3. – Subtract v1 from v2 giving v3. – Multiply v1 by v2 giving v3. – Divide v1 by v2 giving v3 remainder v4. • Formula can be expressed thru compute verb – Compute v1 = (v2 + v3) * (v2 – v3).
  • 13. Conditions • If and Evaluate are used for conditional branching • The relational operators as well as spelt out phrases can be used • If a < b – this can be written as if a is less than b • >, <, =, >=, <= are the available relational operators • NOT, AND, OR are the logical operators • Less than, greater than, equal to are the spelt out phrases • If a is less than b then Do some thing • Else • Do the other way • End-if. • To check an alphanumeric variable for what type of data it holds, we can use if a is numeric, if a is alphabetic, conditions. Based on the value this will be true or false. We can then take decisions.
  • 14. Multiple Conditions • We can use if-then-else if for multi level conditions • To make it very simple, we can use evaluate verb • Evaluate a • When 1 perform para1 • When 2 perform para2 • When 3 perform para3 • When other perform para4 • End-evaluate • Each when statement will be treated as a separate if condition. When 3 here means, if a is equal to 3. • If no condition is matched, the other clause is executed. This is similar to the switch statements in other languages. • Without checking anything, we can transfer the program flow using go to. GO TO mypara. This will suddenly branch to that para. Go To is not supposed to be used, as it is not a good programming practice.
  • 15. Perform Loop • Perform is the loop in cobol • There are many variations of this verb • Perform para1. This will execute only that para only once • Perform para1 5 times. This will repeat the execution • Perform para1 thru para5. This will execute any para from para1 to para5, that appear one after the other on the source code • Perform para1 until a < b. This will execute the para until the condition becomes true. • Perform para1 varying v1 from 1 by 1 until v1 > 10. This will use v1 as the loop counter and increment it by 1, till it reaches 10.
  • 16. Records • Records are nothing but collection of related variables • These are equivalent to structures in other languages • The record variables do have level numbers • Level numbers 1 to 76 are used • 01 employee-record. • 05 employee-code picture 9(5). • 05 employee-name picture x(30). • 05 dob. • 10 yyyy picture 9999. • 10 mm picture 99. • 10 dd picture 99. • 05 designation picture x(3). • 05 doj. • 10 yyyy picture 9999. • 10 mm picture 99. • 10 dd picture 99. • 05 salary picture 9(6).99. • The record can have any levels. They are grouped by level numbers. – Yyyy is the sub field of dob. Dob itself is a sub field of employee-record. • To denote a field in a record, we need to qualify with OF. – Yyyy of doj of employee-record – Designation of employee-record
  • 17. Move Corresponding • When we have 2 similar records, and we want to move data from one to the other, we can use this • We need not write separate move statements for each field of the record • 01 rec1. • 05 field1 pic 999. • 05 field2 pic xx. • 05 filed3 pic x. • 01 rec2. • 05 field2 pic xx. • 05 filed3 pic x. • 05 field1 pic 999. • To move data in a single statements, to respective fields, we can say – Move corresponding rec1 to rec2. • This will move field1 of rec1 to field1 of rec2, field2 of rec1 to field2 of rec2, field3 of rec1 to field3 of rec2. • Though the fields are in different positions in the 2 records, cobol will match the field names and then move values.
  • 18. Condition Names • Variables hold values, and based on these values we may have to take decisions in code • Usual way is to have an if condition to see whether the variable satisfies a condition • This can be easily done in a more readable way using condition names • 77 mm pic 99. • 88 jan value 01. • 88 feb value 02. • 88 march value 03. • 88 april value 04. • We can write if condition to check the month as if mm = 2 then… • The same can be written in a better way as if jan then. When mm is set to 1, this name jan is set to true and if condition becomes true. • People prefer to write English like conditions, such as, if file-is- closed, if account-is-active, if ticket-is-confirmed etc. This makes programs simple
  • 19. Arrays • Arrays are nothing but a set of variables with same name, differentiated by an index number • 01 rec1. – 05 student-name picture x(30) occurs 100 times. • Occurs clause determines the number of elements in an array • Move spaces to student-name (10) will access the 10th element of the array • Arrays start with index as 1 • Any element that is accessed beyond the limit will throw a runtime error and hence we need to be careful • We can have multi level arrays also, but they are very rarely used in business applications
  • 20. File Handling • Cobol supports sequential files, relative files and indexed files • To handle files, we must specify file type and mode in input-output section • The following is a standard one when we need to access files - SELECT myfile ASSIGN TO DISK • Myfile is just a logical name that we want to use later in program. It can be EmployeeFile, PayFile etc • In data division, we must have a FD (file descriptor) part and record definition of the same • There are RD and SD definitions (reporting and sorting descriptions). These 2 are not discussed in this presentation • We can access disk, tape and printer files. In that case, the assign to clause will change. • In procedure division, OPEN, READ, WRITE, START, REWRITE, DELETE, CLOSE are the common verbs that we will use to deal with files. • Every file operation must be checked for the status of the operation. COBOL gives the status of last operation in a variable called file-status. • In working-storage, we must define a variable ws-fs. – 01 ws-fs. – 05 s1 pic 9. – 05 s2 pic 9. • It contains 2 parts, first digit and second digit. A zero in both digits indicates, success; all other codes must be handled specially. • Standard practice is to load record with values before WRITE and initialize record before READ operations
  • 21. Defining Sequential Files • In sequential files, we can add records one after the other and read them one after the other. • We cannot directly jump to any record we want; we need to go from the beginning • SELECT myfile assign to disk • Organization is sequential • Access mode is sequential • file status is ws-fs. • In the FD part of file section, we must use the standard phrases to attach a physical file to the logical name myfile. • FD FD myfile • RECORD CONTAINS 62 CHARACTERS • LABEL RECORD IS STANDARD • DATA RECORD IS employee-record • VALUE OF FILE-ID "myfile.DAT". • 01 employee-record. • 05 emp-code pic 9(5). • 05 emp-name pic x(30). • 05 dob pic 9(8). • 05 doj pic 9(8). • 05 designation pic x(3). • 05 ctc pic 9(6)V99. • The record character count given in the 01 record, must match with FD description. • Label record is to tell the file system of the machine that they must be standard. Other clause can be OMITTED • FILE-ID is the one that actually binds a physical file myfile.dat to the logical file.
  • 22. Handling Sequential Files • Open statement must have the mode specified. • The open modes are input, output, extend • We cannot delete a record in a sequential file; however we can even rewrite records, only in certain cobol versions • In many to most cobol versions, opening sequential file in I-O mode is not allowed • For input mode, the file must exist; in output mode, the previous file data will be erased; in extend mode, the previous file data can be appended with new data • Open Input myfile. – Open extend myfile. • To write data to the file, we must first load valid data to the file record, as given in the FD part • Then we need to issue a WRITE command – WRITE emp-record – END-WRITE • To read a record, we must use READ command. The AT END clause, will tell whether we reached end of file or not. • READ myfile • AT END move 1 to ws-end-of-file • END-READ • The read will get the record that is fetched from the disk to the FD record. • To close the file, use, CLOSE myfile. • When program ends, all open files will be closed.
  • 23. Relative Files • Relative files are used, to directly jump to any record based on the position of the record • E.g. If we want to go to the 57th record in a file, we can use relative files • However, relative files are nowadays very rarely used and they are replaced by indexed files • For relative file, we must define organization is relative, access mode is random. • Since it is not used practically in current day scenarios, we do not address it in this presentation
  • 24. Defining Indexed Files • Indexed files are one of the most used file types as they establish a good DBMS • Records in indexed files can be accessed sequentially or randomly as we like • Using relative files, based on some key values, we can search for a record and the search is binary search and not sequential search; hence it is faster • COBOL can handle billions of records in indexed file itself • SELECT myfile assign to disk • Organization is indexed • Access mode is dynamic • Record key is emp-code of employee-record • file status is ws-fs. • In the FD part of file section, we must use the standard phrases to attach a physical file to the logical name myfile. • FD FD myfile • RECORD CONTAINS 62 CHARACTERS • LABEL RECORD IS STANDARD • DATA RECORD IS employee-record • VALUE OF FILE-ID "myfile.DAT". • 01 employee-record. • 05 emp-code pic 9(5). • 05 emp-name pic x(30). • 05 dob pic 9(8). • 05 doj pic 9(8). • 05 designation pic x(3). • 05 ctc pic 9(6)V99. • In the above file, we can search for any emp-code much faster.
  • 25. Accessing Indexed Files • The open mode can be input, i-o, or output. • Close command is same for all types of files • If the file is opened with sequential access mode, we can use, this type of command to keep on reading the next records • READ SupplierFile • NEXT RECORD • AT END SET EndOfFile TO TRUE • END-READ • If the access mode is set to direct access, we can use this type of read command, to go to the specific record that has the key. • READ SupplierFile • INVALID KEY DISPLAY "SUPP STATUS :-", SupplierStatus • END-READ • If a record with the key value populated before read, is not found, invalid key statement is executed • If the access mode is dynamic, we can use start verb to position the reading point based on some key value. • START Oil-Details-File • KEY IS GREATER THAN 150 • INVALID KEY DISPLAY "Start Error” • END-START. • We can use equal to, less than and other operators in the Key clause of start. If a key is found satisfying the condition, the start is successful; else invalid key statement is executed • WRITE command is also used with INVALID KEY clause • REWRITE can be used to update a record, provided we have executed a START command before rewriting, so that the correct record is pointed. • REWRITE is also used along with INVALID KEY option
  • 26. Program Branching, Termination • We can use CALL command to call another compiled cobol program • CALL “prog2”. • The “prog2” must be the one appearing in program-id of the called program • If we define, linkage section, we can use call “prog2” using linkage-entries. • Linkage section is not discussed in this presentation. • To stop a program from execution, use STOP RUN. • To exit from a called program, use EXIT PROGRAM. • To exit from a paragraph, use EXIT.
  • 27. Example Programs • Refer to this site. • You will get a lot of examples. • Syntax may slightly vary between IBM, HP and other COBOL versions. • But, get the concept, right. • http://www.csis.ul.ie/COBOL/examples/default