Lua4z
A binary distribution of Lua for z/OS, with batteries
-- Count the records in a VSAM KSDS

if #arg == 0 then
  print "Usage: ksds dsname"
  os.exit(8)
end

-- Open the data set for read
local file = assert(io.open(arg[1], "rb, type=record"))

local count = 0

repeat
  local rec = file:read()
  if rec then
    count = count + 1
  end
until not rec

print("Records: " .. count)