截至目前,已經(jīng)對(duì)文件組織方案進(jìn)行了討論。對(duì)于每一個(gè)文件組織方案,可以使用不同的訪問(wèn)模式。以下是文件訪問(wèn)模式的類型:
本章節(jié)中提到的語(yǔ)法及其各自的術(shù)語(yǔ),僅涉及它們?cè)诔绦蛑械挠梅āJ褂眠@些語(yǔ)法的完整程序?qū)⒃谙乱徽掠懻摗?
當(dāng)訪問(wèn)模式是按順序的,記錄檢索的方法根據(jù)所選的文件組織而變化。
對(duì)于順序文件 ,被插入的記錄仍按相同的順序進(jìn)行訪問(wèn)。
對(duì)于索引文件 ,用于獲取記錄的參數(shù)是記錄的鍵值。
對(duì)于相對(duì)文件 ,記錄相對(duì)鍵用于檢索記錄。
語(yǔ)法
以下是順序訪問(wèn)模式的語(yǔ)法:
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO dd-name ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO dd-name ORGANIZATION IS INDEXED ACCESS MODE IS SEQUENTIAL RECORD KEY IS rec-key1 ALTERNATE RECORD KEY IS rec-key2 ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO dd-name ORGANIZATION IS RELATIVE ACCESS MODE IS SEQUENTIAL RELATIVE KEY IS rec-key1
當(dāng)訪問(wèn)模式為隨機(jī)(RANMOM)時(shí),記錄檢索方法根據(jù)所選文件組織而變化。
對(duì)于索引文件,記錄可以通過(guò)主鍵或備用鍵的鍵字段中的值來(lái)訪問(wèn)??梢杂幸粋€(gè)或多個(gè)備用索引。
對(duì)于相對(duì)文件,記錄通過(guò)記錄相對(duì)鍵進(jìn)行檢索。
語(yǔ)法
以下是隨機(jī)訪問(wèn)模式的語(yǔ)法:
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO dd-name ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS rec-key1 ALTERNATE RECORD KEY IS rec-key2 ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO dd-name ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS rec-key1
動(dòng)態(tài)訪問(wèn)支持在同一程序中的順序和隨機(jī)訪問(wèn)。通過(guò)動(dòng)態(tài)訪問(wèn),一個(gè)文件定義可用于執(zhí)行順序和隨機(jī)進(jìn)程,例如按順序訪問(wèn)一些記錄和通過(guò)鍵訪問(wèn)其他記錄。
使用相對(duì)和索引文件,動(dòng)態(tài)訪問(wèn)模式允許你在順序訪問(wèn)模式和隨機(jī)訪問(wèn)模式之間來(lái)回切換,同時(shí)使用READ語(yǔ)句上的NEXT短語(yǔ)讀取文件。NEXT和READ的功能將在下一章中進(jìn)行討論。
語(yǔ)法
以下是動(dòng)態(tài)訪問(wèn)模式的語(yǔ)法:
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO dd-name ORGANIZATION IS SEQUENTIAL ACCESS MODE IS DYNAMIC RECORD KEY IS rec-key1 ALTERNATE RECORD KEY IS rec-key2 ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO dd-name ORGANIZATION IS RELATIVE ACCESS MODE IS DYNAMIC RELATIVE KEY IS rec-key1
更多建議: