The COBOL Connection
COBOL Examples
http://www.simotime.com
 Copyright © 1987-2010  SimoTime Enterprises  All Rights Reserved
  Table of Contents Version 09.05.17 
 
Introduction
  Introduction, Shared Callable Routines & Driver Programs
  Introduction, The Customer Master File
  Introduction, The Item Master File
  The Sample COBOL Programs
 
  Bit Manipulation with COBOL
  Case Conversion with COBOL
  COBOL Call with Procedure Pointer & External Data Items
  Collating Sequences for EBCDIC and ASCII Environments
  Copy File with Replacing Function
  Data Access Programming Examples using COBOL
 
  Alternate Index with a VSAM, Keyed Sequential Data Set (KSDS)
  Callable Access, Sequential Files, 80-Byte Records
  Comma Separated Values, Create a New CSV File
  Comma Separated Values, Read and Parse an Existing CSV File
  Embedded SQL, Relational Data Base
  Generation Data Group (GDG)
  QSAM processing with a Single COBOL Program
  QSAM processing using COBOL with a COBOL I/O Routine
  QSAM processing using COBOL with an Assembler I/O Routine
  Data File Processing with Multiple Record Types
  Variable Length Records (process using Standard COBOL)
  Variable Length Records (with Byte-Stream I/O)
  Variable Length Records (Transfer, Share, Convert and Compare)
  VSAM, KSDS processing with a Single COBOL Program
  VSAM, KSDS processing using COBOL with a COBOL I/O Routine
  VSAM, KSDS processing using COBOL with an Assembler I/O Routine
  Large Files with Micro Focus (greater than 2-gig)
  Data Fields (Editing, Manipulating and Validating)
 
  Data Fields (Binary or Hexadecimal)
 
  Print or Display a Field with Binary Values
  Data Fields (Text or Alpha-numeric)
 
  Text Field, Justify Text within a Field (Center, Left or Right Justify)
  Text Field, Parse a Data String , Process Leading and Multiple, Embedded Spaces
  Text Field, Parse, Convert, Dump
  Text Field, Search and Replace a Text String (Different Lengths)
  Data Fields (Numeric)
 
  Numeric Field, Right-Adjust and Zero-Fill
  Numeric Field, Commonly Used Formats and Sizes
  Numeric Field, Testing or Scanning
  Numeric Field, Printing and Editing
  Numeric Field, Convert Numbers to Words or Digits to Text
  Numeric Field, Leading Spaces and Zeroes
  Numeric Field, Convert between Numeric Field Formats
  Numeric Field, Convert between Comma-Separated-Values & Fixed-Field-Length
  Date Validation, Formatting and Conversion
  Date Calculation, Difference-in-Days
  Diagnostic Aids
 
  Diagnostic Aids, Hexadecimal Format, Display or Dump of Data Files
 
  Diagnostic Aids, Embedded or Non-Printable Characters in Source Code
  Diagnostic Aids, Hex-Dump of Fields or Data Items
  Diagnostic Aids, Hex-Dump of VSAM, KSDS
  Diagnostic Aids, Hex-Dump of Sequential or ASCII/Text Files
  Diagnostic Aids, Hex-Dump of VSAM, KSDS
  Diagnostic Aids, Snap Dump of Working Storage
  Diagnostic Aids, ABEND Routine for Micro Focus Environment
  Diagnostic Aids, Program Tracking and Elapsed Time
  Diagnostic Aids, Compare Directory Content
  Environment, Command Line & File Name for Net Express
  File Conversion, Volume 1, EBCDIC & ASCII, QSAM & VSAM
  File Conversion, Volume 2, Host to PC to Host
  File Status Codes, Program Example, Format and Display
  Floating Point Arithmetic
  Internal Reader (INTRDR), Submit a Job
  Mailing Labels, Read an Indexed File, Create and Sort a Sequential File
  Parameter Passing from JCL
  Record Layout from COBOL Copy File
  Street Address, Parsing, Editing and Formatting
  Table Processing, Define, Load, Search and Sort
 
  Table Processing, Define, Load, Search and Sort
  Table Processing, Bubble Sort
  Table Processing, Create or Define a Table of Binary Values
  Tips and Coding Techniques with COBOL
  Java and COBOL
 
  Java, COBOL and Micro Focus
  Java, COBOL and Bridgewater
  Summary
 
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Glossary of Terms
  Comments or Suggestions
  About SimoTime

Introduction
(Next) (Previous) (Table-of-Contents)

The COBOL Connection provides a suite of sample programs (or COBOL programming examples) that are written using the IBM VS COBOL II dialect with few exceptions. For example, programs that access the system date may require the COBOL/390 dialect to be Y2K compliant. In many examples the programs are coded to the ANSII'85 standard with the exception of programs that use hexadecimal notation (i.e. value X'1F'). The Hexadecimal notation is a COBOL II syntax and is also part of the ANSI/2000 standard. The programs will also work with COBOL for MVS, COBOL/370 and COBOL/390. A few programs use Micro Focus syntax and are documented as such and will not run on the mainframe. These programs are intended for a Windows or UNIX platform running Micro Focus (or microfocus) COBOL. JCL members are provided to run the batch jobs as M

VS batch jobs on an IBM mainframe or as a project with Micro Focus Mainframe Express (MFE) running on a PC with Windows. For more information about Micro Focus refer to http://www.microfocus.com.

The sample programs may also be compiled using Micro Focus Net Express running on a PC with Windows. In the Net Express environment adjustments for the ASCII environment, the mapping of the COBOL file names to the PC file names and replacing JCL with BAT or CMD files will be required. For more information about this environment contact the helpdesk@simotime.com. SimoTime does provide the predefined project files for Mainframe Express and Net Express running on Windows/2000, NT or XP.

Most of the COBOL programs may also be compiled and executed on a UNIX system or an AS/400. SimoTime does not formally test the sample programs in these environments. However, we do have customers that have used many of the sample programs in these environments.

Many of the applications (sometimes referred to as Legacy Applications) running on IBM Mainframes are written in COBOL and have been providing mission critical business information for ten years or longer. Some applications or parts of an application were written over twenty-five years ago. The mainframe continues to be the largest, single platform running applications that leverage the use of the COBOL language. However, it is important to note that COBOL source code that adheres to the ANSI'85 standard may be easily downloaded from the mainframe to a personal computer or UNIX system. Once downloaded it may be compiled and executed on a personal computer or a UNIX system.

The advantages and disadvantages of the proliferation, maintenance or replacement of COBOL applications are not discussed. The COBOL Connection uses a simple value proposition - Legacy Applications, longevity based on continued business value.

Introduction, Shared Callable Routines & Driver Programs
(Next) (Previous) (Table-of-Contents)

This is a collection of the common callable routines and driver programs that may be used by many of the COBOL sample programs provided by SimoTime Enterprises. The COBOL programs are written using the COBOL/2 or COBOL/390 dialect but also work with COBOL for MVS, COBOL/370 and COBOL/390. The date and logging routines require COBOL/390 to be Y2K compliant. Simply click on one of the following items for more informations

1. Learn more by viewing the documentation for the shared modules
2. Download an evaluation copy of the executables for the shared modules
3. Download an evaluation copy of the source code for the shared modules

Introduction, The Customer Master File
(Next) (Previous) (Table-of-Contents)

On the IBM Mainframe the Customer Master File is a VSAM Keyed Sequential Data Set (referred to as KSDS). On a Windows or UNIX System using Micro Focus the Customer Master File is an Indexed File or Key Sequenced File.

The Customer Master file contains variable length records with the minimum and average record length being the same length of 512 bytes. The key starts in the first position of the record and is 12 bytes in length. The record layout is defined in a COBOL copy file and contains text strings and various numeric formats including zoned-decimal, packed and binary.

This program suite provides an example of how to create and populate a Customer Master File. On the Mainframe System the file is a VSAM, Key-Sequenced-Data-Set (or KSDS). On a Windows or UNIX System the Micro Focus Indexed File format is used. The file contains 512 byte records and the key (or customer number) is twelve (12) bytes starting in the first position of each record. Simply click on one of the following items to  learn more by viewing the documentation or download an evaluation copy this sample set of programs.

Introduction, The Item Master File
(Next) (Previous) (Table-of-Contents)

On the IBM Mainframe the Item Master File is a VSAM Keyed Sequential Data Set (referred to as KSDS). On a Windows or UNIX System using Micro Focus the Item Master File is an Indexed File or Key Sequenced File.

The Item Master file contains variable length records with the minimum and average record length being the same length of 512 bytes. The key starts in the first position of the record and is 12 bytes in length. The record layout is defined in a COBOL copy file and contains text strings and various numeric formats including zoned-decimal, packed and binary.

This program suite provides an example of how to create and populate the Item Master File. On the Mainframe System the file is a VSAM, Key-Sequenced-Data-Set (or KSDS). On a Windows or UNIX System the Micro Focus Indexed File format is used. The file contains 512 byte records and the key (or item number) is twelve (12) bytes starting in the first position of each record. Simply click on one of the following items to  learn more by viewing the documentation  or  download an evaluation copy  this sample set of programs.

The Sample COBOL Programs
(Next) (Previous) (Table-of-Contents)

This section provides a brief description of each of the sample COBOL programs. Also, a link for downloading or accessing detailed information is provided.

Bit Manipulation
(Next) (Previous) (Table-of-Contents)

Bit manipulation is usually considered something that cannot be done using COBOL. This is an example of how COBOL can do bit-level manipulation. Both COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to  learn more by viewing the documentation  or  download an evaluation copy  this sample set of programs.

Case Conversion with COBOL
(Next) (Previous) (Table-of-Contents)

This is an example of how COBOL programs do case conversion. The example shows simple conversion between upper and lower case plus capitalization and editing of specific words within a text string. Both COBOL programs were written and tested using the VS COBOL II dialect. Also, both COBOL programs will work with COBOL for MVS and COBOL/370. A JCL member is provided to run the job as an MVS batch job on an IBM mainframe or as a project with Micro Focus Mainframe Express (MFE) running on a PC with Windows. Also, a CMD member is provided to run the job with Micro Focus Net Express (MFE) running on a PC with Windows. Simply click on one of the following items to  learn more by viewing the documentation  or  download an evaluation copy  this sample set of programs.

COBOL Call with Procedure Pointer & External Data Items
(Next) (Previous) (Table-of-Contents)

This suite of programs will describe how to use procedure pointers and external data items. A procedure pointer will be defined in a primary (or mainline) program. The procedure pointer will then be used to call a secondary program. A linkage section will not be required in the secondary program since the data will be accessed (or shared) using external data items. Both COBOL programs are written using the COBOL/390 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to  learn more by viewing the documentation  or  download an evaluation copy  this sample set of programs.

Collating Sequence for EBCDIC and ASCII Environments
(Next) (Previous) (Table-of-Contents)

This suite of sample programs describes the ASCII and EBCDIC sorting or collating sequences and provides an example of programming logic that will work in an EBCDIC environment (i.e. mainframe) but fail in an ASCII environment (i.e. PC with Windows or UNIX). The COBOL programs were written using the COBOL/390 dialect and will execute on an IBM Mainframe or the platforms supported by Micro Focus COBOL (i.e. Windows and UNIX). Simply click on one of the following items to learn more by viewing the documentation or download an evaluation copy of this sample set of programs.

Copy File with Replacing Function
(Next) (Previous) (Table-of-Contents)

This suite of sample programs describes how to use the replacing function with a copy file in a COBOL program. The COBOL programs were written using the COBOL/390 dialect and will execute on an IBM Mainframe or the platforms supported by Micro Focus COBOL (i.e. Windows and UNIX). Simply click on one of the following items to learn more by viewing the documentation or download an evaluation copy of this sample set of programs.

Note: The COBOL language also has an INSPECT REPLACING function that is used to replace characters or text strings within a field at program execution time. For more information about this function refer to the  Text Field, Search and Replace a Text String  section of this document..

Data Access Programming Examples using COBOL
(Next) (Previous) (Table-of-Contents)

This section contains links or references to programming examples that access various data bases or flat files. The COBOL programs were written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370.

The examples read existing data sets. Therefore, it will be necessary to create the files or data sets prior to running the examples. To create the data sets refer to the following references.

JCL Name Description
CRTQ0080.JCL This example will create and populate a QSAM file.
CRTK0080.JCL This example will create a catalog entry for a VSAM, Keyed Sequential Data Set (KSDS).
KSD080J1.JCL This example will populate the VSAM, Keyed Sequential Data Set (KSDS) with data records.

Alternate Index for VSAM, KSDS
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a COBOL program can process a VSAM, Keyed Sequential Data Set (KSDS) with a primary key and an alternate index. The COBOL programs are written using the COBOL/2 dialect but work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Callable Access, Sequential Files, 80-Byte Records
(Next) (Previous) (Table-of-Contents)

This program suite provides examples of accessing sequential files with 80-byte records via a simply call to an I/O routine. The COBOL programs are written using the COBOL/2 dialect but work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Comma Separated Values, Create a New CSV File
(Next) (Previous) (Table-of-Contents)

This suite of sample programs describes how to read a file of fixed field lengths and create a sequential file of variable length records with variable length fields with the leading and trailing spaces removed. The fields are usually separated (or delimited) using a comma between the fields. Simply click on one of the following items to learn more or download this sample set of programs.

Comma Separated Values, Read and Parse an Existing CSV File
(Next) (Previous) (Table-of-Contents)

This suite of sample programs describes how to read an existing comma-delimited file and create a new column-oriented, fixed-field-length sequential file. Simply click on one of the following items to learn more or download this sample set of programs.

Embedded SQL, Relational Data Base
(Next) (Previous) (Table-of-Contents)

This suite of sample programs will show how to create, manipulate and delete a table within a relational data base. Simply click on one of the following items to learn more or download this sample set of programs.

Generation Data Groups (GDG's)
(Next) (Previous) (Table-of-Contents)

This suite of sample programs describes how to define a Generation Data Group (GDG). Once the GDG is defined the creation of a Generation Date Set (referred to as a generation or GDS) within the group is discussed. The COBOL program is written using the COBOL/2 dialect but works with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

QSAM processing with a Single COBOL Program
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a single COBOL program is used to access a QSAM or Sequential file. The COBOL programs are written using COBOL/2 dialect but also works with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

QSAM processing using COBOL with a COBOL I/O Routine
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a mainline COBOL program calls a mainframe COBOL I/O routine to access a QSAM or Sequential file. The I/O routine will also display the file status codes when an I/O error occurs. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

QSAM processing using COBOL with an Assembler I/O Routine
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a mainline COBOL program calls a mainframe Assembler I/O routine to access a QSAM sequential file. The COBOL program is written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. The assembler IO routine is written in IBM Mainframe Assembler, it will compile using Assembler/H or HLASM. Simply click on one of the following items to learn more or download this sample set of programs.

Data File Processing with Multiple Record Types
(Next) (Previous) (Table-of-Contents)

This link provides an example of  processing a file with multiple record types using COBOL programs. This suite of sample programs and documentation may be downloaded for training and evaluation purposes.

Variable Length Records (process using Standard COBOL)
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how to create and access a sequential file containing variable length records using standard SELECT and FD statements. The COBOL programs are written using the COBOL/2 dialect but also works with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Variable Length Records (using Byte-Stream I/O)
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how to transfer and convert a sequential file containing variable length records. The example includes a description of how to use FTP to download a file without doing a conversion on the Mainframe System. The COBOL programs are written using the Micro Focus dialect and requires Micro Focus Net Express or Micro Focus Mainframe Express. Simply click on one of the following items to learn more or download this sample set of programs.

Variable Length Records (Transfer, Share, Convert, Compare)
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how to Transfer, Share, Convert and Compare record and line sequential files containing variable length records. The example includes a description of how to use FTP to download a file without doing a conversion on the Mainframe System. The COBOL programs are written using the Micro Focus dialect and requires Micro Focus Net Express. Simply click on one of the following items to learn more or download this sample set of programs.

VSAM, KSDS processing with a Single COBOL Program
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a single COBOL program is used to access a VSAM data set. The COBOL programs are written using COBOL/2 dialect but also works with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

VSAM, KSDS processing using COBOL with a COBOL I/O Routine
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a mainline COBOL program calls a mainframe COBOL I/O routine to access a VSAM data set. The I/O routine will also display the file status codes when an I/O error occurs. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

VSAM, KSDS processing using COBOL with an Assembler I/O Routine
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a mainline COBOL program calls a mainframe Assembler I/O routine to access a VSAM data set. The COBOL program is written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. The assembler IO routine is written in IBM Mainframe Assembler, it will compile using Assembler/H or HLASM. Simply click on one of the following items to learn more or download this sample set of programs.

Large Files with Micro Focus (greater than 2-gig)
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how to access large files using Micro Focus COBOL. The COBOL program is written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Data Fields (Editing, Manipulating and Validating)
(Next) (Previous) (Table-of-Contents)

This section contains links or references to programming examples that process data at the field level. The COBOL programs were written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370.

On an EBCDIC or ASCII encoded system each byte is made-up of eight bits. Many of the bytes represent the alphabet, numbers or special characters such as the ampersand or decimal point. The remaining bytes are used for various purposes such as control characters for printing, displaying or transferring data. The COBOL language works with data fields. A field may be a single byte or a string of bytes.

A field may be defined as a text-oriented string of data that contains alpha-numeric values. These fields normally contain values that are printable (i.e. letters, number or special characters). However, this type of field may contain any of the 256 characters. On the mainframe this does not usually cause a serious problem since the print and display managers replace non-printable or non-display values with spaces when the field is moved to the I/O buffer. This can be confusing and a hexadecimal dump of the memory containing the data string would be required to view the actual content. This type of field will be discussed in more detail in the following section about text fields.

A field may be defined as a numeric field that should only contain numeric values. It is possible to get non-numeric values into this type of field and this can cause a serious problem that requires special handling. On the mainframe is an arithmetic operation is attempted on using a numeric field that contains a non-numeric value a program check level 7 will occur. This is also referred to as an S0C7 check (or Sock-Seven check). With Micro Focus this condition will give a 163 error message that states a non-numeric value in a numeric field. Numeric fields come in a variety of different formats that will be discussed in the following section about numeric fields.

Data Fields (Hexadecimal Content)
(Next) (Previous) (Table-of-Contents)

This section will focus on data fields (or data strings) that may have hexadecimal content that is not alphabetic and numeric values.

Print or Display a Field with Binary Values
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of a routine that will replace non-display or non-print values with spaces prior to displaying or printing. The example also shows what happens if a display is attempted with the binary or non-display characters in the text string. The COBOL program is written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Data Fields (Text or Alpha-Numeric Content and Definition)
(Next) (Previous) (Table-of-Contents)

This section will focus on data fields (or data strings) that may have alphabetic and numeric content. The various examples will show how the fields are defined and typical processing techniques used with alpha-numeric fields.

Text Field, Justify Text within a Field (Center, Right or Left Justification)
(Next) (Previous) (Table-of-Contents)

This suite of programs provides an example of a routine that will center a text string within a field. It also shows how to left or right justify a text string within a field. Two COBOL programs are provided. The first program is a demonstration program that reads a file containing the JUSTIFY information records and calls the second COBOL program that actually does the text justification. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Text Field, Parse a Data String , Process Leading and Multiple, Embedded Spaces
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a COBOL program can parse a data string using reference modification. This example will also show how to create a new field (or data string) with the leading spaces removed and the multiple, embedded spaces replaced with a single space. The length of the text within the new field (or data string) is also calculated. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Text Field, Pass, Parse and Convert a Data String
(Next) (Previous) (Table-of-Contents)

This suite of programs provides examples of how to parse, edit, modify, format and display (standard or hexadecimal dump) various words within a data string. The editing and formatting of a date field are used in this example. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Text Field, Search and Replace a Text String
(Next) (Previous) (Table-of-Contents)

The objective of this suite of programs is to replace a text string within a field based on a search argument with a text string based on a replacement value of a different length. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more by viewing the documentation or download an evaluation copy of this sample set of programs.

Note: The COBOL language also has a REPLACING function that is used to replace text strings in a COBOL copy file at compile time. For more information about this function refer to the  Copy File with Replacing Function  section of this document..

Data Fields (Numeric Content and Definition)
(Next) (Previous) (Table-of-Contents)

This section will focus on data fields (or data strings) that have numeric content only. The various examples will show how the fields are defined and typical processing techniques used with numeric fields. The following list provides links to additional SimoTime documents about numeric data fields.

Numeric Type Description
Zoned Decimal This document describes the zoned-decimal format. This is coded in COBOL as USAGE IS DISPLAY and is the default format if the USAGE clause is missing.
Packed Decimal This document describes the packed-decimal format. This is coded in COBOL as USAGE IS COMPUTATIONAL-3 and is usually coded in its abbreviated form of COMP-3.
Binary This document describes the binary format. This is coded in COBOL as USAGE IS COMPUTATIONAL and is usually coded in its abbreviated form of COMP. This may also be coded with the keyword BINARY.
Edited Numeric This document describes the edited numeric format. This is coded in COBOL using an edit mask in the picture clause. An example would be PIC ZZZ.99+.
number01 This example describes some commonly used techniques for managing various numeric formats available on the mainframe.
spsnum01 This is an introductory, self-study course about the commonly used numeric formats available on the mainframe. The course material may be purchased from SimoTime. The documentation may be viewed on-line.

Numeric Field, Right-Adjust and Zero-Fill
(Next) (Previous) (Table-of-Contents)

This suite of programs provides an example of a routine that will Right-Adjust a text string within a field and fill the left-most or high-order bytes with zeroes. The resulting field is also tested for numeric values and a return code (RA12-RESPOND) is set to zero (0) if numeric and eight (8) if not numeric. Two COBOL programs are provided. The first program is a demonstration program that reads a file containing "RIGHTADJ-info" records and calls the second COBOL program that actually does the right-adjust, zero-fill processing. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on the following item to learn more or download this set of programs.

Numeric Field, Commonly Used Formats and Sizes
(Next) (Previous) (Table-of-Contents)

This suite of example programs will describe the use, format and size of some of the commonly used numeric fields of the COBOL programming language. This example also illustrates how to redefine a numeric field and how to display the actual hexadecimal content of a numeric field. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Numeric Field, Testing or Scanning
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a COBOL program can test a numeric field for a numeric value or scan a numeric field using reference modification. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Numeric Field, Printing and Editing
(Next) (Previous) (Table-of-Contents)

This suite of example programs will describe how to prepare various numeric fields (i.e. packed or COMP-3, binary or COMP and signed, zoned decimal or USAGE IS DISPLAY) for printing. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Numbers to Words or Digits to Text
(Next) (Previous) (Table-of-Contents)

This suite of programs provides an example of how a COBOL program calls a COBOL routine to create a 150-character text data string from a 12-digit numeric field. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Numeric Field, Leading Spaces and Zeroes
(Next) (Previous) (Table-of-Contents)

This suite of example programs (COBOL, JCL and CMD files) will describe the process to compile and execute a COBOL program that is downloaded from a mainframe. The challenge with this program is that it is expected to process the various numeric items in the same manner as the mainframe. For example, a zoned-decimal field that contains leading spaces should not cause an ABEND (i.e. 163 error on Micro Focus) but should treat the leading spaces as zeroes and complete the arithmetic calculation. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Numeric Field, Convert between Numeric Formats
(Next) (Previous) (Table-of-Contents)

This suite of programs provides an example of how to convert between the various numeric formats used with COBOL and on an IBM Mainframe System. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Convert between Comma-Separated-Values & Fixed-Field-Length
(Next) (Previous) (Table-of-Contents)

This suite of programs provides an example of how to convert variable-length, display-oriented numeric values separated by a delimiter character (Comma-Separated-Value) into data strings of a fixed field length format. The fixed field length may be signed or unsigned values in a display, packed or binary format. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Date Processing Routine
(Next) (Previous) (Table-of-Contents)

This is an example of a callable routine that will validate, format or convert dates. The program will accept a gregorian date in the ccyymmdd, ccyy/mm/dd, ccyy/m/d format then check for numeric values for ccyymmdd. The month and day will also be checked for a valid range of 1-12 and 1-nn according to the month. It also provides conversion to julian and text. For example, 2001/01/15 will be converted to a julian date of 2001015 and a text string of January 15, 2001. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Date Difference Routine
(Next) (Previous) (Table-of-Contents)

This is an example of a callable routine that will calculate the difference between two gregorian dates in the ccyymmdd format. Allowances have been made for leap years with the four-year and four-hundred-year cycles. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Diagnostic Aids
(Next) (Previous) (Table-of-Contents)

This section provides documentation and examples of programs that may be used to assist in a program debugging effort in a development environment or to track the results of program execution in a development or production environment.

Diagnostic Aids, Hexadecimal Format, Display or Dump of Data Files
(Next) (Previous) (Table-of-Contents)

This sub-section contains examples of how to process hexadecimal data using COBOL. The ability to convert a text string or a record within a file to its hexadecimal value and display the information can be quite useful when debugging a program. The ability to write the information to a log file can be useful when trying to isolate an intermittent problem. The examples provide two hexadecimal dump formats, The first is primarily for data strings and the second is for records within a file. Examples of the dump formats are included in the following programs. The programs also have the capability of performing in an ASCII or EBCDIC environment.

Diagnostic Aids, Embedded Hex or Non-Printable Characters in Source Code
(Next) (Previous) (Table-of-Contents)

This suite of programs provides an example of how to identify and process embedded hexadecimal or non-printable characters in a text string or field. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Diagnostic Aids, Hex-Dump of Fields or Data Items
(Next) (Previous) (Table-of-Contents)

This suite of programs provides a demonstration program and a callable program to display a data string in a hexadecimal format for both EBCDIC and ASCII. Both COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Diagnostic Aids, Hex-Dump of Sequential or ASCII/Text Files
(Next) (Previous) (Table-of-Contents)

This suite of sample programs describes Sequential File I/O and HEX-Dump formatting. The programs describe how to dump the input records to an output file in Hexadecimal format. This suite of programs will run on a Personal Computer with Windows and Micro Focus COBOL. The use of the EXTFHTAB.CFG file is used to override the Micro Focus default that replaces TAB characters with SPACE characters. The COBOL programs are compiled with the ASSIGN(EXTERNAL) and the SEQUENTIAL(LINE) directives. The former provides for external file mapping of file names. The latter provides for the mapping of the SEQUENTIAL files specified in the COBOL program to LINE SEQUENTIAL (or ASCII/TEXT) files. This technique provides for the use of a single COBOL source program that uses standard COBOL/2 dialect for sequential file processing. Simply click on one of the following items to learn more or download this sample set of programs.

Diagnostic Aids, Hex-Dump of VSAM Data Set
(Next) (Previous) (Table-of-Contents)

This is an interesting program that would have required an assembler routine prior to the introduction of COBOL/2 for the mainframe. This program reads a VSAM, Keyed-Sequential-Data-Set (KSDS) and writes a sequential (QSAM) file that contains hexadecimal information. Simply click on one of the following items to  learn more  or  download  this sample set of programs.

Diagnostic Aids, Snap Dump of Working Storage
(Next) (Previous) (Table-of-Contents)

This example illustrates the use of a callable routine that does a snap memory dump for a linear area of memory. Its primary purpose is to dump the working storage section of a program but may be used to dump other areas of memory or partial areas of working storage. Simply click on one of the following items for  more information or to download this packet of programs and documentation.

Diagnostic Aids, ABEND Routine for Micro Focus Environment
(Next) (Previous) (Table-of-Contents)

This suite of sample programs describes how to call an ABEND (ABnormal ENDing) routine in a Micro Focus environment. This routine will display the call stack starting with the program that called the ABEND routine. Simply click on one of the following items for  more information or to download this packet of programs and documentation.

Diagnostic Aids, Program Tracking and Elapsed Time
(Next) (Previous) (Table-of-Contents)

The SimoTRAK Series is an optional collection of callable routines and a preprocessor for use with the Micro Focus COBOL Compiler. The callable routines are used at execution time to track program execution with start, stop and elapsed times. The information is written to a log file and may be imported into an excel spread sheet. Simply click on one of the following items for  more information or to download this packet of programs and documentation.

Diagnostic Aids, Compare Directory Content
(Next) (Previous) (Table-of-Contents)

The Directory Compare Utility Program may be used to compare the contents of two different directories or to compare the contents of the same directory before and after a job has executed. Simply click on one of the following items for  more information or to download this packet of programs and documentation.

Environment, Command Line & File Name for Net Express
(Next) (Previous) (Table-of-Contents)

This is an example of how a COBOL program can access (i.e. Get or Set) environment variables using Micro Focus Net Express. The sample programs start by setting an environment variable for a file name. The program then gets the environment variable and displays the environment value on the screen. Next the program calls a second program that does file I/O. Since the second program is compiled with the SEQUENTIAL(LINE) directive the second program will read the ASCII/Text file specified in the environment value that was set in the first program. The COBOL programs were compiled and executed on a PC using Micro Focus Net Express. The first COBOL program was created using Net Express. The second COBOL program reads a flat, sequential file and was downloaded from the mainframe. The source code was not changed and it was compiled, called and executed on the PC using Micro Focus Net Express. Simply click on one of the following items to learn more or download this sample set of programs.

File Conversion, Volume 1, EBCDIC & ASCII, QSAM & VSAM
(Next) (Previous) (Table-of-Contents)

This following programs show how to convert the organization of a file between sequential and keyed indexed, change the file content between ASCII and EBCDIC or change the organization by position within a record. Simply click on one of the following items to learn more or download this sample set of programs.

The following is a list of additional examples for various conversions programs that may be easily created using The SimoZAPS Utility Program

Program Description
cble2a01 Convert from an EBCDIC-Sequential file to an ASCII-Sequential file. This example includes a mainframe JCL member.
zap00101 Convert from an EBCDIC-Sequential file to an ASCII-Text file.
zap00201 Convert from an EBCDIC-Sequential file to an ASCII-Indexed file (Sequential-Add).
zap00301 Convert from an EBCDIC-Sequential file to an ASCII-Sequential file.
zap00401 Convert from an ASCII-Text file to an EBCDIC-Indexed file (Sequential-Add).
zap00501 Convert from an ASCII-Text file to an EBCDIC-Indexed file (Random-Add).

Note: The preceding five examples are included in the download.

File Conversion, Volume 2, Host to PC to Host
(Next) (Previous) (Table-of-Contents)

This suite of programs and documentation will discuss the cycle of how to convert a VSAM, KSDS to a flat Sequential file on the mainframe, download the flat sequential file from the mainframe to the PC and create an Indexed file of ASCII content on the PC. Additional programs are included for converting ASCII, Text files to Indexed files. These examples also show how to manage Packed-Decimal and BINARY or COMP fields. Simply click on one of the following items to learn more or download this sample set of programs.

File Status Codes, Program Example, Format and Display
(Next) (Previous) (Table-of-Contents)

This COBOL programming example will show how to display the file status code by converting the two byte file status code that may contain binary data to a four byte numeric value. This example contains two COBOL programs. The first is a demonstration program that generates various two byte, file status codes. The second COBOL routine does the actual conversion to a four byte, numeric value that may be displayed. A brief description of the file status code is also provided. Sample mainframe JCL and a sample COBOL program are included. Simply click on one of the following items to learn more or download this sample set of programs.

Floating Point Arithmetic
(Next) (Previous) (Table-of-Contents)

This suite of sample programs provides an example of a COBOL program doing floating point arithmetic and writing the information to a Sequential file. Sample mainframe JCL and a sample COBOL program are included. Simply click on one of the following items to learn more or download this sample set of programs.

Internal Reader (INTRDR), Submit a Job
(Next) (Previous) (Table-of-Contents)

This suite of programs will describe how to submit a second job to the internal reader from within the currently running job using a COBOL program. The second job simply executes IEFBR14 with a return to the caller.

Simply click on one of the following items to  learn more by viewing the documentation  or  download an evaluation copy  of this sample set of programs.

Mailing Labels, Read an Indexed File, Create & Sort a Sequential File
(Next) (Previous) (Table-of-Contents)

This suite of programs provides an example of how a mainline application processes a VSAM, KSDS or Indexed File containing Name, Address information and creates a sorted (by postal code sequence) sequential file containing mailing labels that are formatted with 1, 2, 3 or 4 labels across of six lines for each label. This example uses a two-dimensional array to build the label-printing output. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to  learn more by viewing the documentation  or  download an evaluation copy  of this sample set of programs.

Parameter Passing from JCL
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a COBOL program accesses and processes a data string specified as a parameter as part of the EXEC statement in the JCL that is running the job. The COBOL program is written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Record Layout from Copy File
(Next) (Previous) (Table-of-Contents)

This suite of programs provides examples of how to generate a record layout for a file using a COBOL copy file. The information included in the record layout is in HTML format and includes the position of fields within a record and the length of group items. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on the following item to learn more about this set of programs.

Street Address Parsing, Editing and Formatting
(Next) (Previous) (Table-of-Contents)

This program suite provides an example of how a COBOL program can parse a data string containing a street address and produce a new data string with an edited street address (i.e. case formatting and word substitution). The program also identifies a Post Office Box address. The COBOL programs are written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370. Simply click on one of the following items to learn more or download this sample set of programs.

Table Processing
(Next) (Previous) (Table-of-Contents)

This section provides information about table processing within a COBOL program. The sample programs provide a variaty of table processing techniques.

Table Processing, Define, Load, Search and Sort
(Next) (Previous) (Table-of-Contents)

This program suite describes how to define, load, search (Linear or Binary) and sort a table using standard COBOL or custom written search routines. The COBOL programs are written using the COBOL/390 dialect but also work with Enterprise COBOL. Simply click on one of the following items to learn more or download this sample set of programs.

Table Processing, Bubble Sort
(Next) (Previous) (Table-of-Contents)

This program suite describes how to define, load, search (Linear or Binary) and sort a table using standard COBOL or custom written search routines. The COBOL programs are written using the COBOL/390 dialect but also work with Enterprise COBOL. Simply click on one of the following items to learn more or download this sample set of programs.

Table Processing, Create of Define a Table of Binary Values
(Next) (Previous) (Table-of-Contents)

This suite of sample programs describes how to use COBOL to create a table of binary values from X'00' through X'FF'. The COBOL programs are written using the COBOL/390 dialect but also work with Enterprise COBOL. Simply click on one of the following items to  learn more  or  download  this sample set of programs.

Tips and Coding Techniques with COBOL
(Next) (Previous) (Table-of-Contents)

This program suite describes how to define, load, search (Linear or Binary) and sort a table using standard COBOL or custom written search routines. The COBOL programs are written using the COBOL/390 dialect but also work with Enterprise COBOL. Simply click on one of the following items to  learn more  or  download  this sample set of programs.

Java and COBOL
(Next) (Previous) (Table-of-Contents)

This section contains information about COBOL and Java working together as complementary technologies.

Java, COBOL and Micro Focus
(Next) (Previous) (Table-of-Contents)

A fifteen (15) day "Discovery-Session and Proof-of-Concept" project was completed by SimoTime Enterprises during December, 2001. The objective of this project was to determine the practicality of using existing COBOL programs or parts of programs to backend an Internet frontend written in Java. This project used the Java Developer's Kit (JDK) from Sun Micro systems, Micro Focus Net Express for the COBOL and a Lite Web Server from Gefion Software. The Java and COBOL   document presents the results of the SimoTime December Project.

Java, COBOL and Bridgewater
(Next) (Previous) (Table-of-Contents)

A company that provides technology and expertise for "Rapid Application Development" is Bridgewater. Bridgewater has experience in both mainframe legacy systems and Java Internet systems. Bridgewater can provide technology and expertise to Web-enable an existing CICS application or develop new applications written in all COBOL, Java calling COBOL or all Java. For more information visit the Bridgewater web site.

Summary
(Next) (Previous) (Table-of-Contents)

The purpose of this document is to assist as a tutorial for new programmers or as a quick reference for experienced programmers. These COBOL programming examples are made available on an "as-is" basis and may be downloaded in accordance with the Software Agreement and Disclaimer that is explained in the following section of this document. As always, it is the programmer's responsibility to thoroughly test all programs.

Software Agreement and Disclaimer
(Next) (Previous) (Table-of-Contents)

Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to SimoTime Enterprises. Once the fee is received by SimoTime the latest version of the software will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appears on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.

Permission to use, copy, modify and distribute this software for a non-commercial purpose and without fee is hereby granted, provided the SimoTime copyright notice appears on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.

SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software.

If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com

Downloads and Links to Similar Pages
(Next) (Previous) (Table-of-Contents)

You may download the COBOL examples at http://www.simotime.com/sim4dzip.htm#ZipsforCOBOL as a Z-Packs. The Z-Packs provide individual programming examples, documentation and test data files in a single package. The Z-Packs are usually in zip format to reduce the amount of time to download.

Please view the complete list of SimoTime Z-Pack Examples at http://www.simotime.com/sim4dzip.htm.

Note: You must be attached to the Internet to download a Z-Pack or view the list.

This site is a member of the  All Things COBOL  web Ring.

Check out   The Assembler Connection in the SimoTime Library for more examples of mainframe Assembler techniques and sample code.

Check out   The JCL Connection in the SimoTime Library for more mainframe JCL examples.

Check out   The SQL Connection in the SimoTime Library for more mainframe SQL examples.

Check out   The VSAM - QSAM Connection in the SimoTime Library for more examples of mainframe VSAM and QSAM coding techniques and sample code.

Check out   The SimoTime Library  for a wide range of topics for Programmers, Project Managers and Software Developers.

To review all the information available on this site start at   The SimoTime Home Page .

Glossary of Terms
(Next) (Previous) (Table-of-Contents)

Check out  The SimoTime Glossary  for a list of terms and definitions used in the documents provided by SimoTime.

Comments or Suggestions
(Next) (Previous) (Table-of-Contents)

If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com

About SimoTime Enterprises
(Next) (Previous) (Table-of-Contents)

Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com


Return-to-Top
Copyright © 1987-2010 SimoTime Enterprises  All Rights Reserved
When technology complements business
http://www.simotime.com
Version 08.07.11