IBM Z and LinuxONE - Languages - Group home

Data Set I/O with Metal C

  

Being able to use the C language to write a program that runs natively on z/OS is great. However, one of the areas missing was being able to use the fwrite and fread interfaces to read and write data from z/OS data sets in your MetalC program. Because the MetalC allows your code to run natively on z/OS, the DFSMS Access Method interfaces need to be used. Unfortunately, there is only an Assembler interface to those Access Methods.

 

Below, I have included Metal C code that uses the QSAM access method to read records from a sequential data set and write them out to a SYSPRINT output stream. The code is a mix of MetalC, and inline assembler for the few times that the Access Method interface is needed.

The z/OS DFSMS Using Data Sets manual, specifically the chapter on Non-VSAM Access to Data Sets and UNIX Files, is good background knowledge about the QSAM access method (using GET and PUT requests).
The z/OS DFSMS Macro Instructions for Data Sets manual, specifically the chapter on Non-VSAM macro descriptions, has more details about the various executable macros (OPEN, GET, PUT, CLOSE), and control blocks (DCB, DCBE), that are used in the code below.

readds.c

In preparation for writing this code, I needed to translate the assembler version of the DCB macro into a C style mapping so that I could reference the fields. I used the DSECT conversion utility, EDCDSECT, to do most of the work, passing the DCBD macro from SYS1.MACLIB as input. (It was a little more complicated than that, in that I needed to create Assembler source (ihadcbc.s) that included the DCBD macro. If there are other Assembler macros that you need to convert to C, similar steps can be done.
ihadcb.h
ihadcbc.s- Assembler source that includes the DCBD map

Following, I have included the JCL batch job I use to compile, assemble, and bind the MetalC code. Some modifications will be necessary based on how MetalC is installed in your environment. I have also included a small JCL job that runs the READDS program.
cmetal.jcl
readdeck.jcl
readtest.jcl