SlideShare una empresa de Scribd logo
1 de 19
COBOL簡介
http://www.csis.ul.ie/cobol/Course/C
OBOLIntro.htm#part3
資科系
林偉川

1

COBOL歷史
• COBOL (Common Business Oriented
Language) was one of the earliest high-level
programming languages.
• It was developed in 1959 by a group of
computer professionals called the Conference
on Data Systems Languages (CODASYL).
Since 1959 it has undergone several
modifications and improvements.

2

1
COBOL歷史
• In an attempt to overcome the problem of
incompatibility between different versions of
COBOL, the American National Standards
Institute (ANSI) developed a standard form of
the language in 1968. This version was known
as ANSI COBOL.

• COBOL is self-documenting

3

COBOL歷史
• In 1974, ANSI published a revised version of
ANSI COBOL, containing a number of features
that were not in the 1968 version. In 1985,
ANSI published still another revised version
that had new features not in the 1974 standard.

4

2
COBOL歷史
• The language continues to evolve today.
Object-oriented COBOL is a subset of COBOL
97, which is the fourth edition in the continuing
evolution of ANSI/ISO standard COBOL.
• COBOL 97 includes conventional
improvements as well as object-oriented
features. Like the C++ programming language,
object-oriented COBOL compilers are available
even as the language moves toward
standardization.
5

COBOL語言特性
• The first language that automated business
• Allows names to be truly connotative permits both long names (up to 30 characters)
and word-connector characters (dashes)
• Every variable is defined in detail - this
includes number of decimal digits and the
location of the implied decimal point
• File records are also described with great
detail, as are lines to be output to a printer ideal for printing accounting reports
6

3
COBOL語言特性
• Offers object, visual programming
environments
• Class Libraries
• Rapid Application Capabilities
• Integration with the World Wide Web

7

COBOL語言特性
• The hierarchy consists of Divisions, Sections,
Paragraphs, Sentences and Statements.
• A Division may contain one or more Sections, a
Section one or more Paragraphs, a Paragraph
one or more Sentences and a Sentence one or
more Statements

8

4
COBOL語言特性

9

COBOL語言特性
• The actual program text starts in column 8.
The four positions from 8 to 11 are known as
Area A, and positions from 12 to 72 are Area
B.
• Although many COBOL compilers ignore
some of these formatting restrictions, most
still retain the distinction between Area A
and Area B.

10

5
COBOL語言特性
• When a COBOL compiler recognizes the two
areas, all division names, section names,
paragraph names, FD entries and 01 level
numbers must start in Area A. All other
sentences must start in Area B.
• Divisions
A division is a block of code, usually containing
one or more sections, that starts where the
division name is encountered and ends with the
beginning of the next division or with the end of
the program text.
11

COBOL語言特性
• Sections
A section is a block of code usually containing
one or more paragraphs. A section begins with
the section name and ends where the next
section name is encountered or where the
program text ends.
• Section names are devised by the programmer,
or defined by the language. A section name is
followed by the word SECTION and a period.
SelectUnpaidBills SECTION.
FILE SECTION.
12

6
COBOL語言特性
• Paragraphs
A paragraph is a block of code made up of one
or more sentences. A paragraph begins with the
paragraph name and ends with the next
paragraph or section name or the end of the
program text.
• A paragraph name is devised by the
programmer or defined by the language, and is
followed by a period.
PrintFinalTotals.
PROGRAM-ID.
13

COBOL語言特性
• Sentences and statements
A sentence consists of one or more statements
and is terminated by a period.
For example:
MOVE .21 TO VatRate
MOVE 1235.76 TO ProductCost
COMPUTE VatAmount = ProductCost *
VatRate.
SUBTRACT Tax FROM GrossPay GIVING
NetPay
14

7
COBOL之4大DIVISION
• IDENTIFICATION DIVISION.
Contains program information
• ENVIRONMENT DIVISION.
Contains environment information
• DATA DIVISION.
Contains data descriptions
• PROCEDURE DIVISION.
Contains the program algorithms
15

IDENTIFICATION DIVISION
• Supplies information about the program to the
programmer and the compiler. Most entries in
the IDENTIFICATION DIVISION are
directed at the programmer. The compiler
treats them as comments.

16

8
IDENTIFICATION DIVISION
• The PROGRAM-ID clause is an exception to this rule.
Every COBOL program must have a PROGRAM-ID
because the name specified after this clause is used by
the linker when linking a number of subprograms into
one run unit, and by the CALL statement when
transferring control to a subprogram.
• The IDENTIFICATION DIVISION has the
following structure:
IDENTIFICATION DIVISION
PROGRAM-ID. NameOfProgram.
[AUTHOR. YourName.]
other entries here
17

ENVIRONMENT DIVISION
• Describe the environment in which the program will
run. The purpose of the ENVIRONMENT DIVISION
is to isolate in one place all aspects of the program
that are dependant upon a specific computer, device
or encoding sequence.
• The idea behind this is to make it easy to change the
program when it has to run on a different computer or
one with different peripheral devices.
• In the ENVIRONMENT DIVISION, aliases are
assigned to external devices, files or command
sequences. Other environment details, such as the
collating sequence, the currency symbol and the
decimal point symbol may also be defined here.

18

9
DATA DIVISION
• Provides descriptions of the data-items
processed by the program.
• The DATA DIVISION has two main sections:
the FILE SECTION and the WORKINGSTORAGE SECTION. Additional sections,
such as the LINKAGE SECTION (used in
subprograms) and the REPORT SECTION
(used in Report Writer based programs) may
also be required.
19

DATA DIVISION
• The FILE SECTION is used to describe most
of the data that is sent to, or comes from, the
computer's peripherals.
• The WORKING-STORAGE SECTION is
used to describe the general variables used in
the program.

20

10
DATA DIVISION

21

COBOL變數宣告
• All user-defined names, such as data names,
paragraph names, section names condition
names and mnemonic names, must adhere to the
following rules:
• They must contain at least one character, but not
more than 30 characters.
• They must contain at least one alphabetic
character.
22

11
COBOL變數宣告
• They must not begin or end with a hyphen.
• They must be constructed from the characters A
to Z, the numbers 0 to 9, and the hyphen.
• They must not contain spaces.
• Names are not case-sensitive: TotalPay is the
same as totalpay, Totalpay or TOTALPAY.

23

DATA DIVISION - Sample
• IDENTIFICATION DIVISION.
PROGRAM-ID. SequenceProgram.
AUTHOR. Michael Coughlan.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num1 PIC 9 VALUE ZEROS.
01 Num2 PIC 9 VALUE ZEROS.
01 Result PIC 99 VALUE ZEROS.

24

12
PROCEDURE DIVISION
• Contains the code used to manipulate the data
described in the DATA DIVISION. It is here that the
programmer describes his algorithm.
• The PROCEDURE DIVISION is hierarchical in
structure and consists of sections, paragraphs,
sentences and statements.
• Only the section is optional. There must be at least
one paragraph, sentence and statement in the
PROCEDURE DIVISION.
• Paragraph and section names in the PROCEDURE
DIVISION are chosen by the programmer and must
conform to the rules for user-defined names.
25

PROCEDURE DIVISION - Sample
IDENTIFICATION DIVISION.
PROGRAM-ID. SequenceProgram.
AUTHOR. Michael Coughlan.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num1 PIC 9 VALUE ZEROS.
01 Num2 PIC 9 VALUE ZEROS.
01 Result PIC 99 VALUE ZEROS.
PROCEDURE DIVISION.
CalculateResult.
ACCEPT Num1.
ACCEPT Num2.
MULTIPLY Num1 BY Num2 GIVING Result.
DISPLAY "Result is = ", Result.
STOP RUN.
26

13
執行COBOL
• RMCOBOL XXX.cbl
• RUNCOBOL XXX

27

Program Statements
• 由螢幕輸入 Num1
ACCEPT Num1.
• 由螢幕輸入 Num2
ACCEPT Num2.

28

14
Program Statements
• Num1乘以 Num2 結果放於 Result
MULTIPLY Num1 BY Num2 GIVING Result.
• 顯示Result於螢幕
DISPLAY "Result is = ", Result.

29

COBOL syntax
• Words in uppercase are reserved words. When
underlined they are mandatory. When not
underlined they are "noise" words, used for
readability only, and are optional. Because
COBOL statements are supposed to read like
English sentences there are a lot of these
"noise" words.
• Words in mixed case represent names that
must be devised by the programmer (like data
item names).
30

15
COBOL syntax
• When material is enclosed in curly braces { },
a choice must be made from the options within
the braces. If there is only one option then that
item in mandatory.
• Material enclosed in square brackets [ ],
indicates that the material is optional, and may
be included or omitted as required.

31

COBOL syntax
• In COBOL, evaluating an arithmetic
expression and assigning the result to a data
item is achieved by means of the COMPUTE
statement. The syntax diagram for the
COMPUTE is shown below.

32

16
COBOL開關檔
• 開檔
OPEN INPUT IN-FILE OUTPUT OUT-FILE.
• 讀檔
READ IN-FILE AT END MOVE "Y" TO EOF.
• 關檔
CLOSE IN-FILE OUT-FILE.

33

資料檔輸入螢幕輸出SIN.dat
0104A018550
0104A018580
0104A018595
0104A026580
0104A026545
0105A018555
0105A018580
0105A026590
0105A028590
0201A018580
0202A026576
0203A026569
0203A026540
0204A026590
0204A036890
0205A036790
0205A045690
0205A056710
0205A057820

34

17
資料檔輸入螢幕輸出
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE ASSIGN TO INPUT "SIN.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT OUT-FILE ASSIGN TO OUTPUT "SOUT.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
FILE SECTION.
FD IN-FILE.
01 IN-REC.
05 MON-I PIC 99.
05 DAY-I PIC 99.
05 GNO-I PIC X(3).
05 UP-I PIC 99.
05 QY-I PIC 99.
35

資料檔輸入資料檔輸出
FD OUT-FILE.
01 OUT-REC
PIC X(80).
WORKING-STORAGE SECTION.
01 DL.
05 MON-O PIC Z9.
05 FILLER PIC X(4).
05 DAY-O PIC Z9.
05 FILLER PIC X(4).
05 GNO-O PIC X(4).
05 FILLER PIC X(4).
05 AMOUNT-O PIC 99,999.
05 FILLER PIC X(4).
05 DISCOUNT-O PIC 9,999.
05 FILLER PIC X(4).
05 NET-O PIC 9,999.

36

18
COBOL讀檔不只一筆資料
• PERFORM 200-MAIN-RTN UNTIL EOF = "Y".
• 語法:
PERFORM 段名 ?? TIMES
PERFORM 段名1 THROUGH 段名2 ?? TIMES
PERFORM 段名1 VARING 變數 FROM ??
BY ?? UNTIL 變數 > ??

37

19

Más contenido relacionado

La actualidad más candente

Cobol programming language
Cobol programming languageCobol programming language
Cobol programming languageBurhan Ahmed
 
Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1Anil Polsani
 
Introduction to COBOL Programming Language
Introduction to COBOL Programming LanguageIntroduction to COBOL Programming Language
Introduction to COBOL Programming LanguageJessieBenson1
 
Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture NotesFellowBuddy.com
 
Reasons to migrate from Delphi 7 to Delphi 2009
Reasons to migrate from Delphi 7 to Delphi 2009Reasons to migrate from Delphi 7 to Delphi 2009
Reasons to migrate from Delphi 7 to Delphi 2009Michael Findling
 
Compiler designs presentation final
Compiler designs presentation  finalCompiler designs presentation  final
Compiler designs presentation finalilias ahmed
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilersVairavel C
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)guest251d9a
 

La actualidad más candente (16)

Cobol programming language
Cobol programming languageCobol programming language
Cobol programming language
 
Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1
 
Introduction to COBOL Programming Language
Introduction to COBOL Programming LanguageIntroduction to COBOL Programming Language
Introduction to COBOL Programming Language
 
COBOL Foundation 1
COBOL Foundation 1COBOL Foundation 1
COBOL Foundation 1
 
COBOL Foundation 2
COBOL Foundation 2COBOL Foundation 2
COBOL Foundation 2
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
 
Reasons to migrate from Delphi 7 to Delphi 2009
Reasons to migrate from Delphi 7 to Delphi 2009Reasons to migrate from Delphi 7 to Delphi 2009
Reasons to migrate from Delphi 7 to Delphi 2009
 
Compiler designs presentation final
Compiler designs presentation  finalCompiler designs presentation  final
Compiler designs presentation final
 
Presentation compiler design
Presentation compiler designPresentation compiler design
Presentation compiler design
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
 
Compilers
CompilersCompilers
Compilers
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)
 

Similar a Cobol簡介

Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1Anil Polsani
 
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
 
A Checklist for Migrating Big Iron Cobol Applications
A Checklist for Migrating Big Iron Cobol ApplicationsA Checklist for Migrating Big Iron Cobol Applications
A Checklist for Migrating Big Iron Cobol ApplicationsCognizant
 
The security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric VanderburgThe security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric VanderburgEric Vanderburg
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingManoj Tyagi
 
presentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C languagepresentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C languageGautamGupta136
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of cHarish Kumawat
 
03 the c language
03 the c language03 the c language
03 the c languagearafatmirza
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptxMark82418
 
Elevating Application Performance with the latest IBM COBOL offerings
Elevating Application Performance with the latest IBM COBOL offeringsElevating Application Performance with the latest IBM COBOL offerings
Elevating Application Performance with the latest IBM COBOL offeringsDevOps for Enterprise Systems
 

Similar a Cobol簡介 (20)

Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1
 
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
 
C session 1.pptx
C session 1.pptxC session 1.pptx
C session 1.pptx
 
A Checklist for Migrating Big Iron Cobol Applications
A Checklist for Migrating Big Iron Cobol ApplicationsA Checklist for Migrating Big Iron Cobol Applications
A Checklist for Migrating Big Iron Cobol Applications
 
The security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric VanderburgThe security professional's guide to programming - Eric Vanderburg
The security professional's guide to programming - Eric Vanderburg
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C programming
C programmingC programming
C programming
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
 
Mcs lec2
Mcs lec2Mcs lec2
Mcs lec2
 
presentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C languagepresentation on the topic: Introduction to the C language
presentation on the topic: Introduction to the C language
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of c
 
03 the c language
03 the c language03 the c language
03 the c language
 
Overview of c
Overview of cOverview of c
Overview of c
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Elevating Application Performance with the latest IBM COBOL offerings
Elevating Application Performance with the latest IBM COBOL offeringsElevating Application Performance with the latest IBM COBOL offerings
Elevating Application Performance with the latest IBM COBOL offerings
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
WEBSITE DEVELOPMENT
WEBSITE DEVELOPMENTWEBSITE DEVELOPMENT
WEBSITE DEVELOPMENT
 

Último

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 

Último (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

Cobol簡介

  • 1. COBOL簡介 http://www.csis.ul.ie/cobol/Course/C OBOLIntro.htm#part3 資科系 林偉川 1 COBOL歷史 • COBOL (Common Business Oriented Language) was one of the earliest high-level programming languages. • It was developed in 1959 by a group of computer professionals called the Conference on Data Systems Languages (CODASYL). Since 1959 it has undergone several modifications and improvements. 2 1
  • 2. COBOL歷史 • In an attempt to overcome the problem of incompatibility between different versions of COBOL, the American National Standards Institute (ANSI) developed a standard form of the language in 1968. This version was known as ANSI COBOL. • COBOL is self-documenting 3 COBOL歷史 • In 1974, ANSI published a revised version of ANSI COBOL, containing a number of features that were not in the 1968 version. In 1985, ANSI published still another revised version that had new features not in the 1974 standard. 4 2
  • 3. COBOL歷史 • The language continues to evolve today. Object-oriented COBOL is a subset of COBOL 97, which is the fourth edition in the continuing evolution of ANSI/ISO standard COBOL. • COBOL 97 includes conventional improvements as well as object-oriented features. Like the C++ programming language, object-oriented COBOL compilers are available even as the language moves toward standardization. 5 COBOL語言特性 • The first language that automated business • Allows names to be truly connotative permits both long names (up to 30 characters) and word-connector characters (dashes) • Every variable is defined in detail - this includes number of decimal digits and the location of the implied decimal point • File records are also described with great detail, as are lines to be output to a printer ideal for printing accounting reports 6 3
  • 4. COBOL語言特性 • Offers object, visual programming environments • Class Libraries • Rapid Application Capabilities • Integration with the World Wide Web 7 COBOL語言特性 • The hierarchy consists of Divisions, Sections, Paragraphs, Sentences and Statements. • A Division may contain one or more Sections, a Section one or more Paragraphs, a Paragraph one or more Sentences and a Sentence one or more Statements 8 4
  • 5. COBOL語言特性 9 COBOL語言特性 • The actual program text starts in column 8. The four positions from 8 to 11 are known as Area A, and positions from 12 to 72 are Area B. • Although many COBOL compilers ignore some of these formatting restrictions, most still retain the distinction between Area A and Area B. 10 5
  • 6. COBOL語言特性 • When a COBOL compiler recognizes the two areas, all division names, section names, paragraph names, FD entries and 01 level numbers must start in Area A. All other sentences must start in Area B. • Divisions A division is a block of code, usually containing one or more sections, that starts where the division name is encountered and ends with the beginning of the next division or with the end of the program text. 11 COBOL語言特性 • Sections A section is a block of code usually containing one or more paragraphs. A section begins with the section name and ends where the next section name is encountered or where the program text ends. • Section names are devised by the programmer, or defined by the language. A section name is followed by the word SECTION and a period. SelectUnpaidBills SECTION. FILE SECTION. 12 6
  • 7. COBOL語言特性 • Paragraphs A paragraph is a block of code made up of one or more sentences. A paragraph begins with the paragraph name and ends with the next paragraph or section name or the end of the program text. • A paragraph name is devised by the programmer or defined by the language, and is followed by a period. PrintFinalTotals. PROGRAM-ID. 13 COBOL語言特性 • Sentences and statements A sentence consists of one or more statements and is terminated by a period. For example: MOVE .21 TO VatRate MOVE 1235.76 TO ProductCost COMPUTE VatAmount = ProductCost * VatRate. SUBTRACT Tax FROM GrossPay GIVING NetPay 14 7
  • 8. COBOL之4大DIVISION • IDENTIFICATION DIVISION. Contains program information • ENVIRONMENT DIVISION. Contains environment information • DATA DIVISION. Contains data descriptions • PROCEDURE DIVISION. Contains the program algorithms 15 IDENTIFICATION DIVISION • Supplies information about the program to the programmer and the compiler. Most entries in the IDENTIFICATION DIVISION are directed at the programmer. The compiler treats them as comments. 16 8
  • 9. IDENTIFICATION DIVISION • The PROGRAM-ID clause is an exception to this rule. Every COBOL program must have a PROGRAM-ID because the name specified after this clause is used by the linker when linking a number of subprograms into one run unit, and by the CALL statement when transferring control to a subprogram. • The IDENTIFICATION DIVISION has the following structure: IDENTIFICATION DIVISION PROGRAM-ID. NameOfProgram. [AUTHOR. YourName.] other entries here 17 ENVIRONMENT DIVISION • Describe the environment in which the program will run. The purpose of the ENVIRONMENT DIVISION is to isolate in one place all aspects of the program that are dependant upon a specific computer, device or encoding sequence. • The idea behind this is to make it easy to change the program when it has to run on a different computer or one with different peripheral devices. • In the ENVIRONMENT DIVISION, aliases are assigned to external devices, files or command sequences. Other environment details, such as the collating sequence, the currency symbol and the decimal point symbol may also be defined here. 18 9
  • 10. DATA DIVISION • Provides descriptions of the data-items processed by the program. • The DATA DIVISION has two main sections: the FILE SECTION and the WORKINGSTORAGE SECTION. Additional sections, such as the LINKAGE SECTION (used in subprograms) and the REPORT SECTION (used in Report Writer based programs) may also be required. 19 DATA DIVISION • The FILE SECTION is used to describe most of the data that is sent to, or comes from, the computer's peripherals. • The WORKING-STORAGE SECTION is used to describe the general variables used in the program. 20 10
  • 11. DATA DIVISION 21 COBOL變數宣告 • All user-defined names, such as data names, paragraph names, section names condition names and mnemonic names, must adhere to the following rules: • They must contain at least one character, but not more than 30 characters. • They must contain at least one alphabetic character. 22 11
  • 12. COBOL變數宣告 • They must not begin or end with a hyphen. • They must be constructed from the characters A to Z, the numbers 0 to 9, and the hyphen. • They must not contain spaces. • Names are not case-sensitive: TotalPay is the same as totalpay, Totalpay or TOTALPAY. 23 DATA DIVISION - Sample • IDENTIFICATION DIVISION. PROGRAM-ID. SequenceProgram. AUTHOR. Michael Coughlan. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 24 12
  • 13. PROCEDURE DIVISION • Contains the code used to manipulate the data described in the DATA DIVISION. It is here that the programmer describes his algorithm. • The PROCEDURE DIVISION is hierarchical in structure and consists of sections, paragraphs, sentences and statements. • Only the section is optional. There must be at least one paragraph, sentence and statement in the PROCEDURE DIVISION. • Paragraph and section names in the PROCEDURE DIVISION are chosen by the programmer and must conform to the rules for user-defined names. 25 PROCEDURE DIVISION - Sample IDENTIFICATION DIVISION. PROGRAM-ID. SequenceProgram. AUTHOR. Michael Coughlan. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. CalculateResult. ACCEPT Num1. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN. 26 13
  • 14. 執行COBOL • RMCOBOL XXX.cbl • RUNCOBOL XXX 27 Program Statements • 由螢幕輸入 Num1 ACCEPT Num1. • 由螢幕輸入 Num2 ACCEPT Num2. 28 14
  • 15. Program Statements • Num1乘以 Num2 結果放於 Result MULTIPLY Num1 BY Num2 GIVING Result. • 顯示Result於螢幕 DISPLAY "Result is = ", Result. 29 COBOL syntax • Words in uppercase are reserved words. When underlined they are mandatory. When not underlined they are "noise" words, used for readability only, and are optional. Because COBOL statements are supposed to read like English sentences there are a lot of these "noise" words. • Words in mixed case represent names that must be devised by the programmer (like data item names). 30 15
  • 16. COBOL syntax • When material is enclosed in curly braces { }, a choice must be made from the options within the braces. If there is only one option then that item in mandatory. • Material enclosed in square brackets [ ], indicates that the material is optional, and may be included or omitted as required. 31 COBOL syntax • In COBOL, evaluating an arithmetic expression and assigning the result to a data item is achieved by means of the COMPUTE statement. The syntax diagram for the COMPUTE is shown below. 32 16
  • 17. COBOL開關檔 • 開檔 OPEN INPUT IN-FILE OUTPUT OUT-FILE. • 讀檔 READ IN-FILE AT END MOVE "Y" TO EOF. • 關檔 CLOSE IN-FILE OUT-FILE. 33 資料檔輸入螢幕輸出SIN.dat 0104A018550 0104A018580 0104A018595 0104A026580 0104A026545 0105A018555 0105A018580 0105A026590 0105A028590 0201A018580 0202A026576 0203A026569 0203A026540 0204A026590 0204A036890 0205A036790 0205A045690 0205A056710 0205A057820 34 17
  • 18. 資料檔輸入螢幕輸出 INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IN-FILE ASSIGN TO INPUT "SIN.DAT" ORGANIZATION IS LINE SEQUENTIAL. SELECT OUT-FILE ASSIGN TO OUTPUT "SOUT.DAT" ORGANIZATION IS LINE SEQUENTIAL. FILE SECTION. FD IN-FILE. 01 IN-REC. 05 MON-I PIC 99. 05 DAY-I PIC 99. 05 GNO-I PIC X(3). 05 UP-I PIC 99. 05 QY-I PIC 99. 35 資料檔輸入資料檔輸出 FD OUT-FILE. 01 OUT-REC PIC X(80). WORKING-STORAGE SECTION. 01 DL. 05 MON-O PIC Z9. 05 FILLER PIC X(4). 05 DAY-O PIC Z9. 05 FILLER PIC X(4). 05 GNO-O PIC X(4). 05 FILLER PIC X(4). 05 AMOUNT-O PIC 99,999. 05 FILLER PIC X(4). 05 DISCOUNT-O PIC 9,999. 05 FILLER PIC X(4). 05 NET-O PIC 9,999. 36 18
  • 19. COBOL讀檔不只一筆資料 • PERFORM 200-MAIN-RTN UNTIL EOF = "Y". • 語法: PERFORM 段名 ?? TIMES PERFORM 段名1 THROUGH 段名2 ?? TIMES PERFORM 段名1 VARING 變數 FROM ?? BY ?? UNTIL 變數 > ?? 37 19