
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
compiling .cbl programs to create .o and use in batch script
We have a set of .cbl files in the Linux environment. Have installed Visual COBOL for Eclipse for SUSE.
I need to compile the source code and use the executable in the script to run the batch jobs.
Will executing the command "cob -z -P Program1.cbl" create a .o file and can we use the .o executable in my script to run the batch like
DD_SYS001=input_file
/location/program1.o unix >>outputfile
Is the approach fine? Since I am a novice, can someone please guide me step by step of how to go ahead executing it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
.o files are object files - they contain programs compiled to native code (that is, machine code specific to a particular platform) but in a form that is not quite ready to run. For the operating system to be able to run the program it must first be linked to form either an executable (which can be run by the OS) or a shared object (which contains a library of programs ready to be called by other programs).
You can use "cob -x" to create an executable or "cob -z" to create a shared object - see the topic "Compiling and Linking from the Command Line" in the Visual COBOL documentation for more on using "cob".
It looks as though you want to create a program you can run, so you would want
cob -x Program1.cbl
to create an executable file simply called "Program1" (If you are used to running on Windows, remember that UNIX is case-sensitive so "Program1" is not the same as "program1"). Then you can run it:
./Program1
This is the simplest case, running in the current directory with no arguments. To adapt your script snippet above:
export DD_SYS001=input_file
/location/Program1 unix >> outputfile

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I have a set of programs which needs to be run in SUSE Linux with the help of a shell script.
For that I am using Visual COBOL for Eclipse to create executable, but was not sure what kind of executable will it give.
Have created a script as below to compile the programs.
#usr/bin/bash
for i in `ls *.cbl`
do
echo "Begin Compiling $i"
cob -xcvPC "DIRECTIVES=/home/satya/options" $i
ReturnCode=$?
if [ $ReturnCode -ne 0 ]
then
echo "Error detected during cob of $i" >> COMPALL.err
else
echo "Compile completed successsfully for $i" >> COMPALL.err
rm $i
fi
done
Will this work fine to successfully create executable

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
cob -xcvPC "DIRECTIVES=/home/satya/options"
-x (compile to executable)
-c (compile no further than object file)
-v (verbose)
-P (produce a listing file)
-C "DIRECTIVES=/home/satya/options" (pass this DIRECTIVES setting to the syntax checker)
So this will produce the right kind of object files to be linked into an executable, but not link them - it will produce the object files along with listing files, and produce verbose output as it does so. It will also look for compiler directives in /home/satya/options.
So you will still need to link your object files to be able to run them. How to do this depends what you need:
If you want a separate executable produced from each source file, simply delete the "c" option that stops it producing executables in the first place. So change that line to
cob -xcvPC "DIRECTIVES=/home/satya/options" $i
and the compiler will produce an executable from each .cbl source file.
If you want to produce a single executable from all the files compiled, you will need to do that after compiling them all to object code - so keep the loop as you have it to produce the object files, then after the loop add a line
cob -xve Program1 *.o
(where Program1 is the name of the main program for your executable)
to build the executable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
cob -xcvPC "DIRECTIVES=/home/satya/options" $I
I am planning to link them like below:
#usr/bin/bash
linkpgm program1 copybook1 >> COMPALL.err
linkpgm program2 copybook1 copybook2 >> COMPALL.err
Please let me know if the approach if good to go.
Then will be using the executable in the script to run in batch script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
If you want to make sure the script is run using bash, that first line should be
#!/usr/bin/bash
Remember that UNIX is case-sensitive, so $I is not the same as $i.
Now the linking question. I'm not sure what linkpgm is - is that a script you are using?
To link a program (compiled to object code, program1.o) and some subprograms (compiled to object code, subprog1.o and subprog2.o) into an executable using cob:
cob -x program1.o subprog1.o subprog2.o
(this is the simplest version - you can add other options like -v as above)
It might be helpful to create a very simple COBOL program (or use one of the samples included with Visual COBOL) and practice compiling, linking and running that from the command line so you can get used to how that works before you use it in your script.