Run C Fun
Part Three - Challenge #11

Background:

C program source is used to demonstrate z/OS flexibility

z/OS environment includes MVS data sets and Unix files.
MVS was the z/OS grandfather operating system.
MVS excluded the Unix component.
 Therefore, MVS excluded Unix files.
 In z/OS, 'MVS data sets' and 'Unix files' are separate and unique.

While MVS and Unix are technically 2 separate operating systems, z/OS is a blend of both.
 Executable programs can be in MVS data sets or Unix files.
 Executable programs can simultaneously read and write MVS data sets and Unix files.
 Executable programs can be copied between MVS data sets and Unix files.
 The above is true for all compiled programming languages.

Challenge #11 uses C program source code to demonstrate flexibility of z/OS.

C program source is provided with comments explaining the code.

You will make simple modifications to the C program source code.

You do not need to be proficient with C programming languange to figure out the modifications. However, the challenge is opportunity to become familiar with C programming language.


Challenge:

Copy C program to your Unix directory
From ISPF enter the following to launch Unix shell prompt:
tso omvs

Copy the C program source to your Unix directory:
cp "//'zos.mtm2018.public.source(cpgm)'" cpgm.c

Compile C program from Unix shell prompt

Compile C program source creating executable in your Unix directory:
xlc -o cpgm cpgm.c

Execute the C program module from Unix shell prompt:
./cpgm

The C program counted from 1 to 10, writing each number to the display and wrote a message in Unix cpgm.output

Review cpgm.output to read the message
cat cpgm.output

Write the cpgm.output to an MVS partitioned data set member
cp cpgm.output '//pds.data(cmsg1)'


Modify and Compile Unix C program

Edit C program source in your Unix directory:
oedit cpgm.c

Observe the following:

  • /* is a comment line where the */ is the end of the comment
      Take the time to read the comments and the C code below each comment
      You may be able recognize how 1 to 10 is written to the display
      and how the text message is written to cpgm.output
  • Line 26 to 29 explains writing text message to a JCL DDNAME when the program is executed using JCL
     The specific JCL DDNAME is in the C code
Modify the C source code:
from
"My first C program on z/OS"
to
"Fail fast to succeed!"

F3 to save and return to Unix shell prompt

Compile C program source creating executable in your Unix directory:
xlc -o cpgm cpgm.c

Execute the C program module from Unix shell prompt:
./cpgm

Review cpgm.output to read the message
cat cpgm.output

Write the cpgm.output to a different MVS partitioned data set member, cmsg2
cp cpgm.output '//pds.data(cmsg2)'


Copy C executable module from Unix file system to MVS data set

From Unix shell prompt:
cp cpgm '//load(cpgm)'

Return to ISPF session
exit
enter


Execute MVS data set C program executable using JCL

JCL is available to compile C program source. However, JCL to compile the C program will not be used in the challenge.

The C program source was already compiled into an executable module from the Unix shell prompt and copied to an MVS data set. JCL can be used to execute the C program executable copied to the MVS data set without recompiling.

Observe the following in the JCL below:
  • 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
Submit the JCL from the TSO/ISPF environment and review the JCL job output using SDSF
tso submit 'zos.public.jcl(cpgmjcl)'

While TSO/ISPF environment was used to submit the JCL, the C program code is currently writing text message to a file in your unix directory, cpgm.output

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

To accomplish the objective, a modification and subsequent execution of the C program is required to write to JCL HANDLER DD. You will learn several z/OS tricks to accomplish the objective.


Complete the challenge while learning new z/OS tricks

Back to the Unix shell prompt
tso omvs

Edit the C program source code
oedit cpgm.c

Observe the following in the C program source:

  • 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
Compile the modified C program source code
xlc -o cpgm cpgm.c

If compile fails, then correct error and recompile.

Write the cpgm executable to an MVS partitioned data set member
cp cpgm '//load(cpgm)'

From the Unix shell prompt - submit the JCL to execute CPGM writing text to HANDLER DD
submit "//'zos.public.jcl(cpgmjcl)'"

Verify the C program wrote the text message into P3.OUTPUT(#11)
cat '//p3.output(#11)'

If p3.output(#11) has the text message, then you successfully completed the challenge.

If p3.output(#11) is empty, then exit back to ISPF sessions and use SDSF to view JCL job output.
Locate and correct problems.


You learned a few new z/OS tricks in the challenge that other experienced z/OS technicians might be unaware of.

Next: Challenge #12