COBOL for the Approved Workman
()
About this ebook
Drawing from many years of professional software development and teaching experience, I prepared an innovative text that presents the COBOL language in a simple, yet powerful way, at the same time integrating Biblical perspective. Few textbooks address the simplicity of COBOL, many are unable to address the complexity of real-world systems, and few if any have attempted to integrate faith with content to prepare the Christian student for the workplace. This textbook has three goals. The first is to arm the Christian student or developer with Scripture compatible with business-oriented programming, that they may be able witnesses for Christ. The second is to present COBOL in all its simplicity, that it may be a joy to use. The third is to present real-world prototype systems at a high level so students can be prepared for good works in their business endeavors. Software applications illustrating major concepts in each chapter are available electronically upon request. These can be used as is, or tailored to suit a variety of information processing applications.
The text was written primarily with the PC market in mind. However, since the essential elements of COBOL are standardized, the concepts, software and structures presented here can be used on mainframe computers as well with slight modifications. Having started using COBOL on mainframes in 1977, it has been my experience that COBOL is consistent on all varieties of computer platforms. Micro Focus COBOL was used extensively for many examples. Micro Focus has improved its products since this text was originally written so be sure to reference those aspects of the product currently available at https://www.microfocus.com/.
I have found it a great joy to develop this text under the influence and leading of the Holy Spirit of God, and count it a privilege to present it to you.
Also be sure to check out my latest inspirational book "Becoming an Approved Workman".
Wesley Sweetser, Jr
I have over 40 years experience in the private sector and government developing software and databases and managing projects and teaching. I "retired" in 2018 and continue working in Florida, glorifying God, doing home remodeling, publishing three programming eBooks in the Approved Workman series, along with finding work at a local college. God is good! May God bless you as you serve him.
Read more from Wesley Sweetser, Jr
Visual Basic for the Approved Workman Rating: 0 out of 5 stars0 ratingsC# for the Approved Workman Rating: 0 out of 5 stars0 ratingsBecoming an Approved Workman Rating: 0 out of 5 stars0 ratingsSic Transit Gloria Mundi Rating: 0 out of 5 stars0 ratings
Related to COBOL for the Approved Workman
Related ebooks
Cobol Rating: 0 out of 5 stars0 ratingsCOBOL Language Fundamentals Quick Start Rating: 0 out of 5 stars0 ratingsCOBOL Language Fundamentals with DB2 Quick Start Rating: 0 out of 5 stars0 ratingsCOBOL Basic Training Using VSAM, IMS and DB2 Rating: 5 out of 5 stars5/5COBOL Language Fundamentals with VSAM Quick Start Rating: 0 out of 5 stars0 ratingsMastering IBM i: The Complete Resource for Today's IBM i System Rating: 3 out of 5 stars3/5Software Development with C++: Maximizing Reuse with Object Technology Rating: 0 out of 5 stars0 ratingsFunctional Programming in C#, Second Edition Rating: 0 out of 5 stars0 ratingsObjective-C Programming Nuts and bolts Rating: 0 out of 5 stars0 ratingsImplementing C# 11 and .NET 7.0: Learn how to build cross-platform apps with .NET Core (English Edition) Rating: 0 out of 5 stars0 ratingsIBM COBOL A Complete Guide - 2020 Edition Rating: 0 out of 5 stars0 ratingsProfessional Test Driven Development with C#: Developing Real World Applications with TDD Rating: 0 out of 5 stars0 ratingsLearn Docker - .NET Core, Java, Node.JS, PHP or Python: Learn Collection Rating: 5 out of 5 stars5/5Cobol for Students Rating: 5 out of 5 stars5/5MVS JCL Utilities Quick Reference, Third Edition Rating: 5 out of 5 stars5/5COBOL Programming Interview Questions: COBOL Job Interview Preparation Rating: 5 out of 5 stars5/5DB2 11 for z/OS: Basic Training for Application Developers Rating: 5 out of 5 stars5/5Programming in COBOL: Library of Computer Education Rating: 5 out of 5 stars5/5PLI Basic Training Using VSAM, IMS and DB2 Rating: 1 out of 5 stars1/5Mvs Jcl in Plain English Rating: 5 out of 5 stars5/5DB2 11 for z/OS: SQL Basic Training for Application Developers Rating: 4 out of 5 stars4/5Interview Questions for IBM Mainframe Developers Rating: 1 out of 5 stars1/5A Guide to Db2 Performance for Application Developers: Code for Performance from the Beginning Rating: 0 out of 5 stars0 ratingsDB2 11 for z/OS: Intermediate Training for Application Developers Rating: 0 out of 5 stars0 ratingszOS JCL (Job Control Language) Rating: 0 out of 5 stars0 ratingsInterview Questions for DB2 z/OS Application Developers Rating: 0 out of 5 stars0 ratingsMainframe Interview Cases Rating: 0 out of 5 stars0 ratingsDB2 Interview Questions, Answers, and Explanations: DB2 Database Certification Review Rating: 0 out of 5 stars0 ratingsThe Programmer's Guide to iSeries Navigator Rating: 0 out of 5 stars0 ratingsDB2 11.1 for LUW: Basic Training for Application Developers Rating: 0 out of 5 stars0 ratings
Christianity For You
Anxious for Nothing: Finding Calm in a Chaotic World Rating: 4 out of 5 stars4/5Boundaries Updated and Expanded Edition: When to Say Yes, How to Say No To Take Control of Your Life Rating: 4 out of 5 stars4/5The Screwtape Letters Rating: 4 out of 5 stars4/5Mere Christianity Rating: 4 out of 5 stars4/5The Four Loves Rating: 4 out of 5 stars4/5The 5 Love Languages: The Secret to Love that Lasts Rating: 4 out of 5 stars4/5Good Boundaries and Goodbyes: Loving Others Without Losing the Best of Who You Are Rating: 5 out of 5 stars5/5Uninvited: Living Loved When You Feel Less Than, Left Out, and Lonely Rating: 4 out of 5 stars4/5Decluttering at the Speed of Life: Winning Your Never-Ending Battle with Stuff Rating: 4 out of 5 stars4/5Present Over Perfect: Leaving Behind Frantic for a Simpler, More Soulful Way of Living Rating: 4 out of 5 stars4/5Less Fret, More Faith: An 11-Week Action Plan to Overcome Anxiety Rating: 4 out of 5 stars4/5Law of Connection: Lesson 10 from The 21 Irrefutable Laws of Leadership Rating: 4 out of 5 stars4/5The Purpose Driven Life: What on Earth Am I Here For? Rating: 4 out of 5 stars4/5Girl, Wash Your Face: Stop Believing the Lies About Who You Are so You Can Become Who You Were Meant to Be Rating: 3 out of 5 stars3/5The Book of Enoch Rating: 4 out of 5 stars4/5Winning the War in Your Mind: Change Your Thinking, Change Your Life Rating: 5 out of 5 stars5/5The Good Girl's Guide to Great Sex: Creating a Marriage That's Both Holy and Hot Rating: 4 out of 5 stars4/5Boundaries Workbook: When to Say Yes, How to Say No to Take Control of Your Life Rating: 4 out of 5 stars4/5The 21 Irrefutable Laws of Leadership: Follow Them and People Will Follow You Rating: 4 out of 5 stars4/5Boundaries with Kids: How Healthy Choices Grow Healthy Children Rating: 4 out of 5 stars4/5NIV, Holy Bible Rating: 4 out of 5 stars4/5Changes That Heal: Four Practical Steps to a Happier, Healthier You Rating: 4 out of 5 stars4/5Wild at Heart Expanded Edition: Discovering the Secret of a Man's Soul Rating: 4 out of 5 stars4/5Everybody, Always: Becoming Love in a World Full of Setbacks and Difficult People Rating: 4 out of 5 stars4/5The Stories We Tell: Every Piece of Your Story Matters Rating: 3 out of 5 stars3/5I'll Start Again Monday: Break the Cycle of Unhealthy Eating Habits with Lasting Spiritual Satisfaction Rating: 4 out of 5 stars4/5The Holy Bible (World English Bible, Easy Navigation) Rating: 4 out of 5 stars4/5The Story: The Bible as One Continuing Story of God and His People Rating: 4 out of 5 stars4/5
Reviews for COBOL for the Approved Workman
0 ratings0 reviews
Book preview
COBOL for the Approved Workman - Wesley Sweetser, Jr
Foundation
1 Corinthians 3:10-11
According to the grace of God which was given to me, as a wise master builder I laid a foundation, and another is building upon it.
But let each man be careful how he builds upon it. For no man can lay a foundation other than the one which is laid, which is Jesus Christ.
CHAPTER ONE
Return to contents
Introduction to
COBOL
Isaiah 28:10
"For He says,
'Order on order, order on order,
Line on line, line on line,
A little here, a little there.' "
1.1 COBOL Overview
COBOL is a sophisticated, file-oriented language capable of creating and retrieving data on a massive scale with great flexibility and ease, both in a batch and interactive mode. COBOL stands for Common Business-Oriented Language and remains the mainstay of many businesses today.
COBOL is a symbolic language that brings order to business enterprises. Where there is disorder, we can use COBOL to create systems of programs to organize and rearrange data in meaningful ways. In a much more awesome manner, God created order from disorder and it was good:
Genesis 1:3-4
Then God said, Let there be light
; and
there was light. And God saw that the
light was good; and God separated the
light from the darkness.
Colossians 1:16
For by Him all things were created, both
in the heavens and on earth, visible and
invisible, whether thrones or dominions
or rulers or authorities -- all things
have been created by Him and for Him.
Throughout Scripture, we see how God has continued to order the world, particularly Israel in the Old Testament and the church in the New Testament. Each of the twelve tribes of Israel had a particular order in marching through the desert and in the setting up of the tabernacle, and there was order in constructing and rebuilding the Temple, to cite some Old Testament examples. With respect to the New Testament, the body of Christ is well ordered. It consists of many members, each with a particular function or purpose. We are admonished to do everything decently and in order
(1 Corinthians 14:40) with regard to congregational worship.
Bringing order out of chaos is not only prized within the business enterprise, but order is also highly valued within a COBOL program itself. If bringing order out of chaos was good to God, then writing a well-ordered COBOL program is a good work. To accomplish orderliness, we will desire to have each component of our COBOL programs have a particular function or purpose, just as each member of the body of Christ has a particular function. We will accomplish this by making use of structured programming concepts that are based on using modules, process objects, or functions to carry out specific tasks.
The advantage to a business of having highly structured or well-ordered programs and systems of programs, built upon functional objects, lies in the reduced cost to develop the software initially and to maintain these programs and systems as changes need to be made over time. Our desire is to honor and to be like our God, who is a God of order, especially since we are His workmanship created in Him to perform good works (Eph. 2:10). For these reasons, the concept of functions is stressed throughout this text.
1.2 The Structure of COBOL
The structure of COBOL is somewhat precise. There are as many as four divisions
that segregate programs into two minor regions and two major regions. The two minor regions identify the program and its operating environment, while the two major regions define the data elements and the processes or functions. We call these divisions
Identification Division.
Environment Division.
Data Division.
Procedure Division.
The following is a sample COBOL program showing two of these divisions:
identification division.
program-id. sample1.
* this is a comment line
procedure division.
display Hello
stop run.
The Program-ID entry should always correspond to the external file name, not including the file extension, which is used to identify the program. In Windows this limits the file name to 8 characters. Use the words stop run. to terminate a program. The period after the words stop run is recommended.
Columns have significance in the language in the ANSI 85 standard and earlier. Column 7 is reserved for asterisks to identify comment lines. You cannot go beyond column 72, except that columns 73-80 may be used for such things as a date or your initials to help provide an audit trail when changes are made.
When this program is executed, the word Hello is displayed on the screen. The lines display Hello
and stop run. are referred to as statements. In addition to statements, COBOL uses functions and data elements.
1.3 Functions in COBOL
The Procedure Division has the capability of combining statements into functions or processes. These functions can be in line or they can be grouped at the end of the program. When grouped at the end of the program, it’s good programming practice to include function headers and function exit points to facilitate testing and to make the programs easier to read and understand. For example, the program sample1 could be rewritten two ways as follows:
identification division.
program-id. sample1A.
* sample showing
* in line function
procedure division.
perform
display Hello
end-perform
stop run.
OR
identification division.
program-id. sample1B.
* sample showing function
* at the end of the program
procedure division.
top-level.
perform display-routine thru dr-exit
stop run.
display-routine.
display Hello
.
dr-exit. exit.
A function generally carries out some specific task and is limited in size, say up to a page in length. The size of the function will often help determine whether you choose to have it at the end of a program, or as an in line function. A period is generally required at the end of the last statement in a function.
Regarding column positions, process headers and exit points should begin in column 8, while process statements (instructions or commands) historically have begun in column 12 with indentation used beyond that for nested instructions to enhance readability. You cannot go beyond column 72, except that columns 73-80 may be used for such things as a date or initials to help provide an audit trail when changes are made.
1.3.1 Functions as Separate Files
It’s also possible and quite useful to store functions in separate files and have them automatically copied into your programs. This offers the advantage of reusing software already developed, thereby reducing development time and cost. This technique is used extensively throughout this text. Copying is accomplished using the COPY feature, as illustrated in the following example:
identification division.
program-id. sample1C.
* sample showing function at end of
* program copied from separate file
procedure division.
top-level.
perform display-routine thru dr-exit
stop run.
copy display1.pro.
For this example, a separate file must exist called display1.pro, which in this instance contains the following lines:
display-routine.
display Hello
display Hello
display Hello
display Hello again
.
dr-exit. exit.
Notice the period required at the end of the function's last statement before the exit point. Also notice the periods used to terminate the header itself, the exit point name and the word exit.
The starting column for function headers and exit points is column 8, function statements (instructions or commands) begin in column 12. Nesting of instructions is seen in later chapters where further indentation is used beyond column 12 to enhance readability and maintainability. If statements go beyond column 72, the program will never reach the stage where it can be run or executed. In these cases, simply move an entire word or words to the next line to resolve the problem. For instance,
display
This is the day that the Lord has made
display
-- let us rejoice!
Another way to use functions is to have them as separately compiled programs. Discussion of this topic is delayed until the next chapter.
1.4 Data Elements in COBOL
The following is a sample COBOL program showing three of the COBOL divisions plus one Data Division Section:
identification division.
program-id. sample2.
data division.
working-storage section.
1 my-object pic x(5) value Hello
.
procedure division.
display my-object
stop run.
The Data Division is used to declare data objects or define data elements. In this Division there are typically up to five sections (discussed in greater detail in later chapters):
Section Name Used to declare
File Section file data elements or objects
Working-Storage general purpose variable and constant objects
Report Section special report-writing object components
Screen Section screen object lines and columns
Linkage Section variables or objects to be transferred to external functions
If all are used in a single program, it’s advisable to include them in this order. Usually the Report Section and Screen Section would not reside in the same program.
The COPY feature is used to copy data descriptions as well as functions in order to reduce development effort and make programs easier to read and maintain. For instance,
identification division.
program-id. sample2B.
data division.
COPY c:\projects\objects.ws
.
procedure division.
display my-object
stop run.
Here, a separate file must exist on drive C:\ in sub directory projects called objects.ws, which in this instance could contain this code:
1 my-object pic x(5) value Hello
.
1 my-object-again pic x(5) value
Hello
.
Regarding columns and syntax, data elements generally are preceded starting with number 1 beginning in column 8. If a data element consists of several components, these would use numbers 2 through 49. Column 7 may be used for a hyphen to identify a continuation line in the Data Division, if needed, since code cannot extend beyond column 72. To avoid the use of the hyphen altogether, place your literal on a single line below the object name as illustrated above.
If the literal is still too long, break it up into two or more literals, each of which will fit within the constraints as in this example
1 my-big-object pic x(100) value
This is an example of a literal that does not fit This is an example of a literal that does not fit
.
1 split-object.
3 my-object-part-1 pic x(50) value
This is an example of a literal that fits
.
3 my-object-part-2 pic x(50) value
This is an example of a literal that fits
.
The object split-object is referred to as a group and is assigned the number 1, while the number 3 was chosen for the group's two components. Periods are needed to terminate data declaration lines in the Data Division.
Notice that there is no period after the word value, since the literal on the line following actually completes the data declaration. Therefore the line with the literal requires the period.
Consider the following:
1 in-date.
5 id-yy pic 99.
5 id-mm pic 99.
5 id-dd pic 99.
In the preceding code, in-date is a data element of length 6 consisting of three components, each of length 2. The object in-date is the group and assigned the number 1, while number 5 is chosen for the group's components. Names are assigned by the programmer. Pic stands for picture and establishes the length and type of an object. Nines (9's) are used to specify a numeric data type, while x's would be used to specify a character data type. Periods are needed at the end of each line.
Lower case and mixed case is acceptable for names. Data elements and commands are not case sensitive in COBOL. For instance, WAGE and Wage represent the same data element. Names may use up to 30 characters, which helps to make COBOL programs relatively self-documenting. Use letters, numbers and the hyphen in your names.
1.4.1 Character Data Type
Define character objects or data elements in a variety of ways. First we consider variable data elements -- those whose values may be altered during processing.
Consider the following, which must appear in the Data Division:
1 my-object pic x(6).
OR
1 my-object pic x(6) value Hello
.
OR
1 my-object pic xxxxxx value Hello
.
In all the above, a character object of length 6 is being declared. Use an x to indicate the character data type. To specify a length of up to 255 characters or bytes, you may use that number of x's or include a number in parentheses immediately after a single x. Optionally, you may specify an initial value by using the word value followed by a literal contained in quotation marks. If the size of a character object is larger than the value of the literal assigned to it, the literal is aligned or justified on the left with spaces added onto the right to fill the field.
Literals are case sensitive. For instance Hello
is different from HELLO
.
You can also specify constant character data elements -- those which you do not wish to alter or change. There is no protection against a constant being altered, however, as there is in some other languages. A typical example of a character constant is a report title or heading. For instance,
1 report-title-1.
7 pic x(43) value
This is an example of a title 43 bytes long
.
7 pic x(37) value spaces.
Notice the absence of a name between the number 7 and the word pic. When you do not plan on changing the value of an object, you need not assign a name to it. The group name report-title-1 is used to refer to the entire group, and it could be used to alter the group's state or value