Lua4z
A binary distribution of Lua for z/OS, with batteries
--- Count record types in an SMF file

--  Example: LUA FILEIO "'SMF.GDG(0)'"

-- link to struct docs http://www.inf.puc-rio.br/~roberto/struct/
local struct = require "struct"

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

local file, msg = io.open(arg[1], "rb, type=record, noseek")
if not file then error(msg) end

local smftype = {}
setmetatable(smftype, {__index = function () return 0 end})
while true do
  local rec = file:read()
  if not rec then break end
  local flag, type = struct.unpack("BB",rec)
  smftype[type] = smftype[type] + 1
end

-- copy the sparse array to a real array and sort it by record type
local types = {}
for type, count in pairs(smftype) do
  table.insert(types, {type, count})
end
table.sort(types, function (a,b) return a[1] < b[1] end)

for _, v in pairs(types) do
  print("type("..v[1]..") = "..v[2])
end