Those are ways of emulating reading files backward using other language features, not explicit language features for reverse-reading of files.
Actually now I realise z/OS stdio has support for backwards-reading of VSAM files: you can fopen with mode “r,type=record,acc=bwd” and “acc=bwd” sets file read direction to reverse. And you can put an open type=record file in reverse reading mode by calling flocate() with __KEY_LAST, __KEY_EQ_BWD, etc
But going just by the docs, that only works for VSAM not BSAM. Whereas COBOL’s OPEN INPUT REVERSED definitely works for BSAM, but not sure if it works for VSAM
Fair, but reading files backwards doesn't make much sense on random access media. I wonder if anyone still uses it.
I don’t know who uses the COBOL feature or the z/OS stdio feature
But relational databases do it all the time… it is very common for certain queries (especially those involving ORDER BY DESC) to be compiled into query plans which do reverse table/index scans… stdio VSAM acc=bwd is just the same thing at a much lower level - VSAM is pretty close to the storage engine layer of a standard relational database, to the point that relational databases for z/OS sometimes end up using VSAM instead of the custom storage engines they use on other platforms
> Fair, but reading files backwards doesn't make much sense on random access media.
On the contrary, it actually makes more sense. A tape drive has a standard direction, and reverse reading is rarely supported (especially nowadays) and requires special circuitry if it is supported. Floppy disks, hard disks and optical disks also have an inherent direction of rotation, but they are really random-sequential not pure random access devices. But true random access devices-DRAM, flash, SSD, etc-don’t have any inherent direction, so reading backwards (decreasing sequential block addresses) is just as valid as reading forwards (increasing sequential block addresses)
> compiled into query plans which do reverse table/index scans…
But are they implemented as reading files backwards? Reading datasets in any direction is very normal because all our media is, for all practical purposes, random-access. Stepping through data backwards is just a special case of random access.
> But are they implemented as reading files backwards? Reading datasets in any direction is very normal because all our media is, for all practical purposes, random-access. Stepping through data backwards is just a special case of random access.
Well, of course they are reading the file backwards, in terms of making successive calls to pread/preadv/preadv2/aio_read/lio_listio/io_uring/etc with decreasing file offsets, or successive reads to an mmap-ed file with decreasing memory addresses.
And of course, you can't read a file backwards with fseek/fread (or lseek/read), except on a very limited number of platforms that support that – but a serious database is unlikely to be using seek+read begin with, except in unusual circumstances such as VSAM under z/OS (z/OS pread/etc only work with file descriptors, which are only supported for UNIX files, not MVS datasets)