COBOL - Ateneo

Download Report

Transcript COBOL - Ateneo

Cobol 101
Anne Michelle Santos
Roumel Mendoza
COBOL 101

COBOL



Common Business Oriented Language
A third-generation programming language,
Was one of the earliest high-level programming
languages; still wide used today.




Business Computing Domain.
First proposed in 1959 by the Conference on Data
Systems Languages (CODASYL).
Three ANSI standards for COBOL have been produced in
1968, 1974 and 1985.
Object-oriented COBOL is the fourth edition in the
continuing evolution of ANSI/ISO standard COBOL.
Underlining Philosophy

Like the name suggests, COBOL was meant to be
‘common’ or compatible among a significant group
of manufacturers

COBOL is designed for developing business,
typically file-oriented, applications, and is not
designed for writing systems programs.

Primary domain in business, finance, and
administrative systems for companies and
governments.
Pro’s and Con’s
-
Advantages
-
Simple
Portable
Maintainable
-
Disadvantages
-
-
-very wordy
- has a very rigid
format
-not designed to
handle scientific
applications
Distinct features







The language is simple
No pointers
No user defined types
No user defined functions
‘Structure like’ data types
File records are also described with great
detail, as are lines to be output to a printer
COBOL is self documenting
Structure of COBOL

COBOL programs are hierarchical in structure.

Each element of the hierarchy consists of one or more
subordinate elements.

The levels of hierarchy are Divisions, Sections,
Paragraphs, Sentences and Statements

There are 4 main divisions and each division
provides an essential part of the information
required by the complier
Structure of COBOL (continued)



At the top of the COBOL hierarchy are the four divisions.
The sequence in which they are specified is fixed, and must follow
the order:

IDENTIFICATION DIVISION supplies information about the program
to the programmer and the compiler.

ENVIRONMENT DIVISION is used to describe the environment in
which the program will run.

DATA DIVISION provides descriptions of the data-items processed by
the program.

PROCEDURE DIVISION contains the code used to manipulate the data
described in the DATA DIVISION. It is here that the programmer
describes his algorithm.
Some COBOL compilers require that all the divisions be present in
a program while others only require the IDENTIFICATION
DIVISION and the PROCEDURE DIVISION
HelloWorld Example
000100
000200
000300
000400
000500
000600
000700
000800
000900
001000
001100
101200
101300
101400
101500
101600
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLOWORLD.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. RM-COBOL.
OBJECT-COMPUTER. RM-COBOL.
DATA DIVISION.
FILE SECTION.
PROCEDURE DIVISION.
MAIN-LOGIC SECTION.
DISPLAY "Hello world!"
STOP RUN.
Writing, Compiling and
Executing
Creating .cbl programs
1.

Notepad/Text Editors and save as .cbl
Compiling and Running
2.


Open RM/Cobol Directory
Compile



Type in prompt: rmcobol <filename.extn>
filename.extn is the source code
Execute

If no errors:


Type in prompt: runcobol <filename>
Filename is the object code
Data Types in COBOL

COBOL is not a strongly typed language

In COBOL, there are only three data types


Numeric, lphanumeric (text/string), alphabetic
Data types are declared using:



A level number
A data-name or identifier
A Picture clause.


For detailed field specification
e.g. 01 GrossPay PIC 9(5)V99 VALUE ZEROS.
Group Items





Group items are the COBOL equivalent of structures.
The items with a group item must be elementary items or
other group items.
Ultimately every group item should be defined in terms of
elementary items.
The hierarchy in a group item is represented by different
level numbers
e.g. 01 DateOfBirth.
02 DayOfBirth PIC 99.
02 MonthOfBirth PIC 99.
02 YearOfBirth PIC 9(2).
Basic Commands







ADD a TO b GIVING c.
SUBTRACT a FROM b GIVING c.
MULTIPLY a BY b GIVING c.
DIVIDE a INTO b GIVING c.
COMPUTE x = a + b * c.
MOVE a TO b c
SORT sort-file
ON ASCENDING KEY k
USING inventory-file
GIVING sorted-inventory-file .
Basic Commands (Contd.)


MERGE merge-work-file
ON ASCENDING KEY K
USING input-file1 input-file2
GIVING output-file .
DISPLAY
Accept
total-cost.
identifier.
PERFORM paragraphname1 THROUGH paragraphname2
VARYING index FROM value1 BY value2
UNTIL condition.
Advanced Cobol
(somehow)
Two Types
Job Control Language (JCL)
 CICS® (Customer Information
Control System)

Job Control Language (JCL)

A scripting language used on IBM
mainframe operating systems


to instruct the Job Entry Subsystem (that
is, JES2 or JES3) on how to run a batch
program or start a subsystem.
Acts as the driver and scheduler for
batch COBOL programs
DB2

IBM's line of RDBMS


As IBM now calls it, data server
Software products within IBM's broader Information
Management software line

Acts as the backend database for COBOL
programs

IBM's flagship relational database management
system DB2 Enterprise Server Edition or the top of
the line DB2 Data Warehouse Edition (DB2 DWE)
which runs on Unix, Windows or Linux servers.
Sample Program
EXEC SQL
SELECT TKT_NUM
,TKT_ISS_DTE
,MEMO_NUM
,MEMO_CRTN_DTE
,WVR_CDE
,WVR_CRTN_DTE
INTO :WVU0140A-TKT-NUM
,:WVU0140A-TKT-ISS-DTE
,:WVU0140A-MEMO-NUM
,:WVU0140A-MEMO-CRTN-DTE :WSW-NULL-INDICATOR
,:WVU0140A-WVR-CDE
,:WVU0140A-WVR-CRTN-DTE
FROM T_WVR
WHERE TKT_NUM = :W400-PRMY-TKT-NUM
WITH UR
END-EXEC.
CICS® / Customer Information Control
System

A transaction server that runs primarily on IBM mainframe systems

Acts as the driver and GUI for online COBOL programs

A transaction processing system designed for both online and
batch activity


Can be written in numerous programming languages


easily supports thousands of transactions per second, making it a
mainstay of enterprise computing
COBOL, PL/I, C, C++, Assembler, REXX, and Java
Over 90 percent of Fortune 500 companies are reported to rely on
CICS (running on z/OS) for their core business functions; most
state and national governments do as well
CICS® / Customer Information Control
System

Each CICS program is initiated using a transaction id.


CICS screens are sent as maps using a programming
language such as COBOL.

The end user inputs data which is made accessible to the
program by receiving a map.

CICS screens may contain text that is highlighted, having
different colors or blinking.

An example of how a map can be sent through COBOL is
given below.

EXEC CICS
SEND MAPSET(MPS1) MAP(MP1)
END-EXEC.
Key References



Wikipedia.org
http://www.cs.wayne.edu/~jcc/CSC114/lec.html
http://www.csis.ul.ie/COBOL/examples/default.ht
m#SimplePrograms