Data Set I/O with Metal C
andrewwilt 060000GNFW Visits (6499)
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.
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.)
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.