C13 COBOL 檔案訪問模式

2021-10-09 16:40:11 字數 2638 閱讀 2574

截至目前,已經對檔案組織方案進行了討論。對於每乙個檔案組織方案,可以使用不同的訪問模式。以下是檔案訪問模式的型別:

本章節中提到的語法及其各自的術語,僅涉及它們在程式中的用法。使用這些語法的完整程式將在下一章討論。

當訪問模式是按順序的,記錄檢索的方法根據所選的檔案組織而變化。

語法

以下是順序訪問模式的語法:

environment

division

.input

-output

section

.file

-control

.select file-name assign

to dd-name

organization

issequential

access

mode

issequential

environment

division

.input

-output

section

.file

-control

.select file-name assign

to dd-name

organization

isindexed

access

mode

issequential

record

keyis rec-key1

alternate

record

keyis rec-key2

environment

division

.input

-output

section

.file

-control

.select file-name assign

to dd-name

organization

isrelative

access

mode

issequential

relative

keyis rec-key1

當訪問模式為隨機(ranmom)時,記錄檢索方法根據所選檔案組織而變化。

語法

以下是隨機訪問模式的語法:

environment

division

.input

-output

section

.file

-control

.select file-name assign

to dd-name

organization

isindexed

access

mode

israndom

record

keyis rec-key1

alternate

record

keyis rec-key2

environment

division

.input

-output

section

.file

-control

.select file-name assign

to dd-name

organization

isrelative

access

mode

israndom

relative

keyis rec-key1

動態訪問支援在同一程式中的順序和隨機訪問。通過動態訪問,乙個檔案定義可用於執行順序和隨機程序,例如按順序訪問一些記錄和通過鍵訪問其他記錄。

使用相對和索引檔案,動態訪問模式允許你在順序訪問模式和隨機訪問模式之間來回切換,同時使用read語句上的next短語讀取檔案。next和read的功能將在下一章中進行討論。

語法

以下是動態訪問模式的語法:

environment

division

.input

-output

section

.file

-control

.select file-name assign

to dd-name

organization

issequential

access

mode

isdynamic

record

keyis rec-key1

alternate

record

keyis rec-key2

environment

division

.input

-output

section

.file

-control

.select file-name assign

to dd-name

organization

isrelative

access

mode

isdynamic

relative

keyis rec-key1

設計模式13 訪問者模式

訪問者模式中,有乙個資料體,新增了各個訪問物件。這些訪問物件在不同的狀態時,會有不同的反應。這種模式中,物件與狀態相分離,互不干擾。visitor.h內容 1 ifndef visitor h h 2 define visitor h h34 5 include 6 include 7 using ...

Python檔案訪問模式

一 檔案 1.檔案訪問模式 1 r,唯讀。2 w,只寫。若檔案存在,則清空檔案內容再寫 如檔案不存在,則建立檔案。3 a,追加。若檔案存在,則在檔案末尾追加文字,並且只能在文末追加 如檔案不存在,則建立檔案。4 r 讀寫。5 w 讀寫。w 和r 不同的是,它會清空檔案。6 a 讀寫。a 和r 不同的...

設計模式學習(C 實現)13 策略模式

與橋接模式類似,只不過橋接模式是將乙個類的部分屬性抽離為乙個繼承體系,再通過組合的方式加入該類中,而策略模式是將乙個類的部分方法抽離為乙個繼承體系,再通過組合的方式加入該類中,例如暑期出行為乙個類,出行的方式可能有很多,坐火車或者坐飛機,那麼可以將交通方式抽離為乙個繼承體系,通過介面傳入,以適配更靈...