Today I’m going to get to know COBOL. I’ve already used COBOL in IBM’s Master the Mainframe 2018 contest, but this time I’m working in MVS 3.8!
What am I planning to do here? Well, before I start learning COBOL I want to know how I can edit, compile and run it on my own mainframe. MVS3.8 provides a small piece of test code in SYS2.JCLLIB called TESTCOB.
So I go to RFE. Then I need to navigate in the DSLIST utility, so that means I enter 3.4 to quickly get there. The data set name prefix is SYS2.JCLLIB. When editing, I am able to scroll down and edit TESTCOB.
So this is TESTCOB. Normally any piece of COBOL production code has four divisions.
- IDENTIFICATION DIVISION
- Here we identify the COBOL program, the name of the program itself. Typically, the program documentation goes here.
- ENVIRONMENT DIVISION
- Here we link the program with external data sets.
- DATA DIVISION
- Here we define the local variables, exclusive to this program only.
- PROCEDURE DIVISON
- Here we code all our logic.
As you can see on the image below, TESTCOB indeed has the four divisions.
Now what have I highlighted in pink? Those are sections. Sections can be omitted but they have chosen not to in this case. At line 000027 you can see 000-DISPLAY, that is a routine. The next two lines are statements/sentences inside a paragraph. These state that the machine needs to DISPLAY the HELLO-CONST in CNSL. The HELLO-CONST is defined at line 000025 in the data division. CNSL is an alias for CONSOLE defined in the CONFIGURATION section. The code pretty much speaks for itself right? Display HELLO, WORLD in the console and then STOP running.
Now what is HELLO-CONST PIC X(12) VALUE ‘HELLO, WORLD’? This means that HELLO-CONST can carry 12 bytes. 1 byte equals to 1 character in an EBCDIC mainframe. You can see X as a template, in theory HELLO-CONST is XXXXXXXXXXXX. We fill those X’s with ‘HELLO, WORLD’, X means the repetition factor meaning X is repeated 12 times.
SPOILER ALERT: change MSGCLASS=A to MSGCLASS=H on line 000004!
When you’re finished checking this file, enter the primary command save to save your changes. To execute your program, enter the primary command submit.
JOB TESTCOB(JOB00002) SUBMITTED
To check our output we need to go back to the root RFE and navigate to the OUTLIST (3.8). Select the correct job by using the line command s.
Kevin’s Coding Blog is experiencing technical difficulties
It’s not here? Where is it? The COBOL job isn’t outputting to the OUTLIST?
Please allow me to add some Google tags for those with the same issue: cobol mainframe MVS 3.8 tk4 no job output help sysprint please google.
I forgot to change the MSGCLASS to H. This means you want the output from the compiler to be held. Now let’s submit it again and check the output.
JOB TESTCOB(JOB00025) SUBMITTED
Yes I know, 25… I’ve been struggling. Again the job output was empty, but after entering the primary command ST * I can see all the jobs.
TESTCOB is there! Now I’ll select with s and see what it did.
There it is! HELLO, WORLD. We have done it!
Next up: our own custom mix of JCL and COBOL!
Are you experiencing any technical difficulties?
Tell me all about it!