IBM MTM: Part Three – Challenge #11

Challenge 11… we’re getting there. From now on all following challenges will be about learning a new programming or scripting language. I’ll be shown how to compile, execute and debug a program/script.

In this challenge I’ll be working with some C code. I’ve never written any C in my life, only C# but I doubt it’s the same. Well, I’ll see when I get to the code.

Run C Fun

IBM Master the Mainframe Part Three – Challenge #11

First I’ll continue to OMVS by using the primary command tso omvs then I’ll copy the C source code to my unix directory using cp “//’zos.mtm2018.public.source(cpgm)'” cpgm.c Now we’re able to compile the code using xlc -o cpgm cpgm.c. If it compiled successfully then I should be able to execture it the same way we execute a shell script inside Linux: ./cpgm

The C program counted from 1 to 10, writing each number to the display and wrote a message in Unix cpgm.output. I’ve checked the message and wrote it to //pds.data(cmsg1).

Now I need to modify the code. I need to change the text it outputs from My first C program on z/OS to Fail fast to succeed!. I’ll edit the file using the primary command oedit cpgm.c. 

I’ve highlighted the most interesting part of the code. Line 000021 is where the message needs to be changed. Line 000028 is where they display the code to write text to a DD name.

To clarify the code, my first guess is that they open the connection using the fopen function, then pass the DD parameter as DD:DDNAME and the second parameter w probably stands for write (to clarify the action they want to perform).

I know the comments at line 000026 and 000027 say comment/uncomment this to write to a Data Set but I’m not sure if I actually need to do it? I’m just going to assume we don’t need to as they don’t instruct us to do so in the assignment.

Now I’ll save using F3, compile and run using the previous commands. And lastly I’ll read the output and write it to pds.data(cmsg2).

That’s done! I’ll now copy the C executable module from my Unix file system to my MVS data set using cp cpgm ‘//load(cpgm)’. Now we’re ready to exit omvs. I’m told there are multiple ways to compile code. We can also compile C code using JCL.

  • CPGM is the program to be executed
  • STEPLIB DD tells the system where to search first for CPGM
    You copied CPGM from the Unix directory to your MVS LOAD data set
  • HANDLER DD is coded in the JCL

We’re going to submit the JCL using tso submit ‘zos.public.jcl(cpgmjcl)’ as we need the output to be inside P3.OUTPUT(#11). Is HANDLER here DD:HANDLER inside the C-code? It probably is.

The objective is to change the C program source code to write the text message to JCL HANDLER DD instead of cpgm.output

Oh schnitzel, I’ll go and do that. I kind of gave it away I think? Oh… they give it away too when I read a bit further. No harm done.

  • Locate C statement used to write text to cpgm.output
  • Locate C statement used to write text DD:HANDLER
  • Comment statement used to write text to cpgm.output
  • Uncomment statement used to write text DD:HANDLER
  • F3 to save and return to Unix shell prompt

Done! That’s it for challenge #11 🙂

Schedule?

I know… I try to release periodically but work and free time won’t allow me to. But I already prepared a lot of stuff for the coming two weeks. I want to devote the entirety of december to challenge #15!

Share this:

Leave a Reply

Your email address will not be published.