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 Part-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.
Below is the logic to read the indexed file. Here, Part_1 is the key value for the indexed file. The key point is before reading, you need to move Key value.
Move T-partno to Part-1 Read filename-1 At end Move 'No' to Are-there-no-records Not at end Move T-partno to Part-1 Read filename-1 Invalid key Perform 600-err-rtn Not Invalid Key Perform 500-ok-rtn End-Read