In COBOL a file that is defined in Organization is called indexed file. The access mode can be Sequential/Random/Dynamic.
In the below example the first step I have mentioned “Organization is Indexed”.
Select filename-1 Assign to Imp-1 Organization is indexed Access Mode is Random Record Key is data-1
Like any other files you can open indexed files by using INPUT, OUTPUT, IO and EXTEND modes. If you want to read and write into the same file then you need to open as I/O mode.
Tip: Access mode is Random. That means you cannot access the record sequentially.
In the below example, I am reading an indexed file. The speciality is before reading I am just moving key value.
Move T-partno to Part-no Read filename-1 At end Move 'No' to Are-there-no-records Not at end Move T-partno to Part-no Read filename-1 Invalid key Perform 600-err-rtn Not Invalid Key Perform 500-ok-rtn End-Read