Binary & Linear Table Search
 Define, Load, Search and Sort
http://www.simotime.com
When technology complements business    Copyright © 1987-2010  SimoTime Enterprises  All Rights Reserved
  Table of Contents Version 10.05.20 
  Introduction
 
  Programming Objectives
  Programming Input and Output
  Programming Requirements
  Programming Overview
  The CMD Member for Net Express
  The JCL Member for z/OS or Mainframe Express
  The COBOL Source Member
  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]

This suite of programs provides an example of how a COBOL program does various table functions such as a table load, a standard COBOL "SEARCH", a standard COBOL "SEARCH ALL", a user written binary search and a user written linear search. The COBOL program is written using the IBM COBOL for OS/390 dialect and will also work with IBM Enterprise COBOL. 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. A batch or command file is provided to run the job as a Windows batch job on a Wintel platform using Micro Focus Net Express (refer to http://www.microfocus.com).

Programming Objectives
(Next) (Previous) (Table-of-Contents)

This example illustrates the following functions.

1. Demonstrate how to define a table.
2. Demonstrate how to load a table.
3. Demonstrate how to search a table using standard COBOL functions.
4. Demonstrate how to do a binary search of a table using standard COBOL functions.
5. Provide an example of a uniquely coded linear search of a table
6. Provide an example of a uniquely coded binary search of a table
7. Provide an example of how to sort a table using a bubble sort routine

Programming Input and Output
(Next) (Previous) (Table-of-Contents)

The following is an example of an input file (STATEGET) that contains records with a keyword that identifies the type of search and the name of a state that will be used as the search argument..

/LINEAR        Texas           * A custom LINEAR search with expected hit
/BINARY        Texas           * A custom BINARY search with expected hit
/LINEAR        Illinois        * Custom LINEAR search from first to last
/BINARY        Illinois        * A custom BINARY search with expected hit
/SEARCH        Indiana         * Use standard COBOL dialect
/BINARY        Alabama         * First entry in table, custom BINARY search
/BINARY        Wyoming         * Last entry in table, custome BINARY search
/BINARY        Turkey          * A custom BINARY search with expected no hit
/LINEAR        Turkey          * A custom LINEAR search with expected no nit
/SEARCHALL     Vermont         * Binary search using standard COBOL dialect
/SEARCHALL     Delaware        * Binary search using standard COBOL dialect

The following is an example of the output file (STATEPUT) created from the preceding input file.

* CBLBINC1 ********************************************************************
* CBLBINC1 /LINEAR        Texas           * A custom LINEAR search with expected hit
* CBLBINC1 * TABLE-LINEAR-SEARCH is starting
* CBLBINC1 The indexed attempt is 043
* CBLBINC1 State Name......... Texas          TX
* CBLBINC1 State Capitol...... Austin
* CBLBINC1 State Bird......... Mockingbird
* CBLBINC1 State Flower....... Bluebonnet
* CBLBINC1 Population......... 00020044141
* CBLBINC1 Size (Sq Miles).... 00000261914
* CBLBINC1
* CBLBINC1 ********************************************************************
* CBLBINC1 /BINARY        Texas           * A custom BINARY search with expected hit
* CBLBINC1 * TABLE-BINARY-SEARCH is starting
* CBLBINC1 The indexed attempt is 003
* CBLBINC1 State Name......... Texas          TX
* CBLBINC1 State Capitol...... Austin
* CBLBINC1 State Bird......... Mockingbird
* CBLBINC1 State Flower....... Bluebonnet
* CBLBINC1 Population......... 00020044141
* CBLBINC1 Size (Sq Miles).... 00000261914
* CBLBINC1
* CBLBINC1 ********************************************************************
* CBLBINC1 /LINEAR        Illinois        * Custom LINEAR search from first to last
* CBLBINC1 * TABLE-LINEAR-SEARCH is starting
* CBLBINC1 The indexed attempt is 013
* CBLBINC1 State Name......... Illinois       IL
* CBLBINC1 State Capitol...... Springfield
* CBLBINC1 State Bird......... Cardinal
* CBLBINC1 State Flower....... Violet
* CBLBINC1 Population......... 00012128370
* CBLBINC1 Size (Sq Miles).... 00000055593
* CBLBINC1
* CBLBINC1 ********************************************************************
* CBLBINC1 /BINARY        Illinois        * A custom BINARY search with expected hit
* CBLBINC1 * TABLE-BINARY-SEARCH is starting
* CBLBINC1 The indexed attempt is 002
* CBLBINC1 State Name......... Illinois       IL
* CBLBINC1 State Capitol...... Springfield
* CBLBINC1 State Bird......... Cardinal
* CBLBINC1 State Flower....... Violet
* CBLBINC1 Population......... 00012128370
* CBLBINC1 Size (Sq Miles).... 00000055593
* CBLBINC1
* CBLBINC1 ********************************************************************

The following shows the content of the original table after it has been moved to a working table in memory. The working table is sorted in descending sequence by population.

* CBLBINC1 01  California           33,871,648
* CBLBINC1 02  Texas                20,851,820
* CBLBINC1 03  New York             18,976,457
* CBLBINC1 04  Florida              15,982,378
* CBLBINC1 05  Illinois             12,419,293
* CBLBINC1 06  Pennsylvania         12,281,054
* CBLBINC1 07  Ohio                 11,353,140
* CBLBINC1 08  Michigan              9,938,444
* CBLBINC1 09  New Jersey            8,414,350
* CBLBINC1 10  Georgia               8,186,453
* CBLBINC1 11  North Carolina        8,049,313
* CBLBINC1 12  Virginia              7,078,515
* CBLBINC1 13  Massachusetts         6,349,097
* CBLBINC1 14  Indiana               6,080,485
* CBLBINC1 15  Washington            5,894,121
* CBLBINC1 16  Tennessee             5,689,283
* CBLBINC1 17  Missouri              5,595,211
* CBLBINC1 18  Wisconsin             5,363,675
* CBLBINC1 19  Maryland              5,296,486
* CBLBINC1 20  Arizona               5,130,632
* CBLBINC1 21  Minnesota             4,919,479
* CBLBINC1 22  Louisiana             4,468,976
* CBLBINC1 23  Alabama               4,447,100
* CBLBINC1 24  Colorado              4,301,261
* CBLBINC1 25  Kentucky              4,041,769
* CBLBINC1 26  South Carolina        4,012,012
* CBLBINC1 27  Oklahoma              3,450,654
* CBLBINC1 28  Oregon                3,421,399
* CBLBINC1 29  Connecticut           3,405,565
* CBLBINC1 30  Iowa                  2,926,324
* CBLBINC1 31  Mississippi           2,844,658
* CBLBINC1 32  Kansas                2,688,418
* CBLBINC1 33  Arkansas              2,673,400
* CBLBINC1 34  Utah                  2,233,169
* CBLBINC1 35  Nevada                1,998,257
* CBLBINC1 36  New Mexico            1,819,046
* CBLBINC1 37  West Virginia         1,808,344
* CBLBINC1 38  Nebraska              1,711,263
* CBLBINC1 39  Idaho                 1,293,953
* CBLBINC1 40  Maine                 1,274,923
* CBLBINC1 41  New Hampshire         1,235,786
* CBLBINC1 42  Hawaii                1,211,537
* CBLBINC1 43  Rhode Island          1,048,319
* CBLBINC1 44  Montana                 902,195
* CBLBINC1 45  Delaware                783,600
* CBLBINC1 46  South Dakota            754,844
* CBLBINC1 47  North Dakota            642,200
* CBLBINC1 48  Alaska                  626,932
* CBLBINC1 49  Vermont                 608,827
* CBLBINC1 50  Wyoming                 493,782

Programming Requirements
(Next) (Previous) (Table-of-Contents)

This suite of samples programs will run on the following platforms.

1. Executes on Windows/2000, Windows/NT and Windows/XP using Micro Focus Net Express and the CMD file provided.
2. May be ported to run on the UNIX platforms supported by Micro Focus COBOL.
3. Executes on a mainframe with OS/390 or Windows/2000, Windows/NT and Windows/XP using Micro Focus Mainframe Express and the JCL file provided.

Programming Overview
(Next) (Previous) (Table-of-Contents)

This program reads a file (STATEDB1) that contains the table information. This table information contains the name of a state, the two byte abbreviation, the state flower, the state bird, the population (1999) and the size of the state (square miles). The information in the file will be used to load a table.

The program then reads a file (STATEGET) that contains records with control information as to how to search the table and the name of a state that will be used as the search argument. If a matching element is found the information about the state is written to an output file and displayed to the screen.

The following is a block diagram of the table processing demonstration. The BLUE boxes are unique to the mainframe and Micro Focus Mainframe Express. The RED boxes are unique to the PC with Windows and Micro Focus Net Express. The GREEN boxes are platform independent and will execute on the mainframe or a PC with Windows. Also, the GREEN boxes may be ported to a UNIX platform that is supported by Micro Focus COBOL.

                   
 
CBLBINJ1
jcl
     
CBLBINE1
cmd
      The JCL or CMD member for running the application.
 
 
     
 
       
 
IEFBR14
utl
     
IF Exist
stmt
      Delete any previously created STATEPUT file.
 
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
       
 
STATEGET
data
     
     
     
CBLBINC1
CBL
     
     
     
STATEPUT
data
      Load the table from the STATEDB1 file. Read the input file (STATEGET) containing the search type and argument. Create a new file (STATEPUT) containing the results of the searches.
 
STATEDB1
data
     
     
     
 
           
     
 
           
     
End-of-Job
EOJ
           
                   
 Flowchart of the Table Processing using Various Search Techniques

The CMD Member
[Next] [Previous] [Table-of-Contents]

The following is the Windows CMD (CBLBINE1.CMD) required to run the sample COBOL program. This is a two step job. The first step (identified by the :STATEDEL statement) will delete the file that was created from a previous run of this job. The second step (identified by the :CBLBINS1 statement) will execute the sample program.

@echo OFF
REM  * *******************************************************************
REM  *                   This program is provided by:                    *
REM  *                    SimoTime Enterprises, LLC                      *
REM  *           (C) Copyright 1987-2010 All Rights Reserved             *
REM  *             Web Site URL:   http://www.simotime.com               *
REM  *                   e-mail:   helpdesk@simotime.com                 *
REM  * *******************************************************************
REM  *
REM  * Text   - Create a Sequential Data Set on disk using ECHO function.
REM  * Author - SimoTime Enterprises
REM  * Date   - January 24, 1996
REM  *
REM  * The first job step (DeleteQSAM) will delete any previously created
REM  * file.
REM  *
REM  * The second job step (CreateQSAM) will create a new file that shows
REM  * the table searches.
REM  * For this program to work the COBOL program must be compiled with
REM  * the ASSIGN(EXTERNAL) and SEQUENTIAL(LINE) directives under
REM  * Net Express.
REM  *
REM  * This set of programs will run on a Personal Computer with
REM  * Windows and Micro Focus Net Express.
REM  *
rem  * ********************************************************************
rem  * Step   1 of 2  Set the global environment variables,
rem  *                Delete any previously created file...
rem  *
     set JobStatus=0000
     if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
rem  *
     SimoEXEC NOTE *******************************************************CblBinE1
     SimoEXEC NOTE Starting JobName CblBinE1, User is %USERNAME%
     SimoEXEC NOTE Identify JobStep DeleteQSAM
:DeleteQSAM
     set STATEDB1=c:\SimoNXE4\AN01\DataAsc1\STAT1999.TXT
     set STATEGET=c:\SimoNXE4\AN01\DataAsc1\STATEGET.TXT
     set STATEPUT=c:\SimoNXE4\AN01\DataAsc1\STATEPUT.TXT
     if exist %STATEPUT% del %STATEPUT%
REM  *
REM  * *******************************************************************
REM  * Step   2 of 2  Create and populate a new QSAM file...
REM  *
:CreateQSAM
     SimoEXEC NOTE Identify JobStep CreateQSAM
     SimoEXEC EXEC CblBinC1
     if ERRORLEVEL 1 echo Error level is equal-to or Greater-then 1 . . .
     if ERRORLEVEL 1 set JobStatus=0001
     if not "%JobStatus%" == "0000" goto :EojNOK
     echo Error Level is 0 . . .
rem  *
     if exist %TXTNPUT1% goto :EojAok
     set JobStatus=0002
     goto :EojNok
:EojAok
     SimoEXEC NOTE Produced %STATEPUT%
     SimoEXEC NOTE Finished JobName CblBinE1, Job Status is %JobStatus%
     goto :End
:EojNok
     SimoEXEC NOTE ABENDING JobName CblBinE1, Job Status is %JobStatus%
:End
     SimoEXEC NOTE Conclude SysLog is %SYSLOG%
     if not "%1" == "nopause" pause

The JCL Member for z/OS or Mainframe Express
[Next] [Previous] [Table-of-Contents]

The following is the mainframe JCL (CBLBINJ1.JCL) required to run the sample COBOL program. This is a two step job. The first step (identified by the //STATEDEL statement) will delete the file that was created from a previous run of this job. The second step (identified by the //CBLBINS1 statement) will execute the sample program.

The JOB and DD statements will need to be modified for different mainframe environments.

//CBLBINJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1
//* *******************************************************************
//*                   This program is provided by:                    *
//*                    SimoTime Enterprises, LLC                      *
//*           (C) Copyright 1987-2010 All Rights Reserved             *
//*             Web Site URL:   http://www.simotime.com               *
//*                   e-mail:   helpdesk@simotime.com                 *
//* *******************************************************************
//*
//* Text   - Using COBOL to do a binary search
//* Author - SimoTime Enterprises
//* Date   - January 01, 1989
//*
//* This set of programs illustrate the use a COBOL program to do
//* a binary search of a table.
//*
//* This set of programs will run on a mainframe under MVS or on
//* a Personal Computer running Windows and Mainframe Express by
//* Micro Focus.
//*
//*                    ************
//*                    * CBLBINJ1 *
//*                    ********JCL*
//*                         *
//*                         *
//*   ************     ************     ************
//*   * STATEGET *--*--* CBLBINC1 *--*--* STATEPUT *
//*   ************  *  ********CBL*  *  ************
//*                 *       *        *
//*   ************  *       *        *  ************
//*   * STATEDB1 *--*       *        *--* DISPLAY  *
//*   ************          *           ************
//*                         *
//*                    ************
//*                    *   EOJ    *
//*                    ************
//*
//* *******************************************************************
//* Step   1 of 2  Delete previuosly created file.
//*
//STATEDEL EXEC PGM=IEFBR14
//STATEPUT DD  DSN=SIMOTIME.DATA.STATEPUT,
//             DISP=(MOD,DELETE,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=VB,LRECL=132,DSORG=PS)
//*
//* *******************************************************************
//* Step   2 of 2  Execute the sample table processing program.
//*
//CBLBINS1 EXEC PGM=CBLBINC1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//STATEDB1 DD  DSN=SIMOTIME.DATA.STATEDB1,DISP=SHR
//STATEGET DD  DSN=SIMOTIME.DATA.STATEGET,DISP=SHR
//STATEPUT DD  DSN=SIMOTIME.DATA.STATEPUT,
//             DISP=(NEW,CATLG,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=VB,LRECL=132,DSORG=PS)
//SYSOUT   DD  SYSOUT=*
//*

The COBOL Source Code
[Next] [Previous] [Table-of-Contents]

The following is the source code for the sample COBOL program. This program will read the STAT1999.TXT file as a sequential fileand load a table with information about the states in the United States.

Once the table is loaded the control file is read. Each record in the control file contains a keyword and the name of a state. The keyword indentifies the type of table search. This program includes four examples of accessing a table using COBOL.

The "/SEARCH" keyword will do a linear scan of the table starting at the first element. This search uses standard COBOL functionality to do a table search.

The "/SEARCHALL" keyword will do a binary search of the table. This search uses standard COBOL functionality to do a table search. For this function to work the table must be in sequence.

The "/LINEAR" keyword will do a linear scan of the table starting at the first element. This search uses a custome written routine to do a table search.

The "/BINARY" keyword will do a binary search of the table. This search uses written routine to do the table search. For this function to work the table must be in sequence.

Once the control file is processed through end-of-file the table is then moved to a working table in memory. This working table is then sorted by descending sequnce according to size by population. The working table information is then displayed to the screen and wriitten to the STATEPUT file.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLBINC1.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2010 SimoTime Enterprises, LLC.            *
      *                                                               *
      * All rights reserved.  Unpublished, all rights reserved under  *
      * copyright law and international treaty.  Use of a copyright   *
      * notice is precautionary only and does not imply publication   *
      * or disclosure.                                                *
      *                                                               *
      * 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 appear 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 and modify this software for any      *
      * non-commercial purpose and without fee is hereby granted,     *
      * provided the SimoTime copyright notice appear 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                                  *
      *                                                               *
      * SimoTime Enterprises                                          *
      * 15 Carnoustie Drive                                           *
      * Novato, CA 94949-5849                                         *
      * 415.883.6565                                                  *
      *                                                               *
      * RESTRICTED RIGHTS LEGEND                                      *
      * Use, duplication, or disclosure by the Government is subject  *
      * to restrictions as set forth in subparagraph (c)(1)(ii) of    *
      * the Rights in Technical Data and Computer Software clause at  *
      * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of          *
      * Commercial  Computer Software - Restricted Rights  at 48      *
      * CFR 52.227-19, as applicable.  Contact SimoTime Enterprises,  *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      * Source Member: CBLBINC1.CBL
      * Copy Files:    STINFOB1.CPY
      *
      * This program provides an example of how a COBOL program does
      * various table functions such as a table load, a standard
      * COBOL search, a standard COBOL "search all", a user written
      * binary search and a user written linear search.
      *
      * The COBOL program is written using the IBM COBOL for OS/390
      * dialect and will also work with IBM Enterprise COBOL.
      *
      * 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.
      *
      * A batch or command file is provided to run the job as a
      * Windows batch job on a Wintel platform using Micro Focus Net
      * Express.
      *
      *****************************************************************
      *
      *                   ************
      *                   * CBLBINJ1 *
      *                   ********jcl*
      *                        *
      *                   ************
      *                   * IEFBR14  *
      *                   ********utl*
      *                        *
      *  ************     ************     ************
      *  * STATEGET *--*--* CBLBINC1 *--*--* STATEPUT *
      *  ********dat*  *  ********cbl*  *  ********dat*
      *                *       *        *
      *                *       *        *
      *  ************  *       *        *  ************
      *  * STATEDB1 *--*       *        *--* CONSOLE  *
      *  ********dat*          *           ******dsply*
      *                        *
      *                   ************
      *                   *   EOJ    *
      *                   ************
      *
      *****************************************************************
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT STATEDB1-FILE  ASSIGN to     STATEDB1
                  ORGANIZATION is SEQUENTIAL
                  ACCESS MODE  is SEQUENTIAL
                  FILE STATUS  is STATEDB1-STATUS.
           SELECT STATEGET-FILE  ASSIGN to     STATEGET
                  ORGANIZATION is SEQUENTIAL
                  ACCESS MODE  is SEQUENTIAL
                  FILE STATUS  is STATEGET-STATUS.
           SELECT STATEPUT-FILE  ASSIGN to     STATEPUT
                  ORGANIZATION is SEQUENTIAL
                  ACCESS MODE  is SEQUENTIAL
                  FILE STATUS  is STATEPUT-STATUS.

      *****************************************************************
       DATA DIVISION.
       FILE SECTION.
       FD  STATEDB1-FILE
           DATA RECORD    is STATEDB1-RECORD.

       COPY STINFOB1.

       FD  STATEGET-FILE
           DATA RECORD    is STATEGET-RECORD.

       01  STATEGET-RECORD.
           05  STATEGET-DATA-01.
               10  STATEGET-CONTROL.
                   15  STATEGET-SLASH      pic X.
                   15  STATEGET-CONTROL    pic X(14).
               10  FILLER                  pic X.
               10  STATEGET-SEARCH         pic X(15).
               10  STATEGET-COMMENT        pic X(40).
               10  FILLER
                                           pic X(9).
       FD  STATEPUT-FILE
           DATA RECORD    is STATEPUT-RECORD
           RECORDING MODE is V
           RECORD is VARYING in SIZE from 4 to 128
           DEPENDING ON STATEPUT-LRECL.

       01  STATEPUT-RECORD.
           05  STATEPUT-DATA-01  pic X(128).

       WORKING-STORAGE SECTION.
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLBINC1 '.
           05  T2 pic X(34) value 'Table Processing, A COBOL Example '.
           05  T3 pic X(10) value ' v06.05.04'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLBINC1 '.
           05  C2 pic X(20) value 'Copyright 1987-2010 '.
           05  C3 pic X(28) value '  SimoTime Enterprises, LLC '.
           05  C4 pic X(20) value ' All Rights Reserved'.

       01  SIM-THANKS-01.
           05  C1 pic X(11) value '* CBLBINC1 '.
           05  C2 pic X(32) value 'Thank you for using this sample '.
           05  C3 pic X(32) value 'by SimoTime Enterprises, LLC    '.
           05  C4 pic X(04) value '    '.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* CBLBINC1 '.
           05  C2 pic X(32) value 'Please send comments or suggesti'.
           05  C3 pic X(32) value 'ons to helpdesk@simotime.com    '.
           05  C4 pic X(04) value '    '.

       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* CBLBINC1 '.
           05  MESSAGE-TEXT.
               10  MESSAGE-TEXT-1  pic X(68)   value SPACES.
               10  MESSAGE-TEXT-2  pic X(188)  value SPACES.

       01  STATEDB1-STATUS.
           05  STATEDB1-STATUS-L     pic X.
           05  STATEDB1-STATUS-R     pic X.
       01  STATEDB1-EOF              pic X       value 'N'.
       01  STATEDB1-OPEN-FLAG        pic X       value 'C'.

       01  STATEGET-STATUS.
           05  STATEGET-STATUS-L     pic X.
           05  STATEGET-STATUS-R     pic X.
       01  STATEGET-EOF              pic X       value 'N'.
       01  STATEGET-OPEN-FLAG        pic X       value 'C'.

       01  STATEPUT-STATUS.
           05  STATEPUT-STATUS-L     pic X.
           05  STATEPUT-STATUS-R     pic X.
       01  STATEPUT-EOF              pic X       value 'N'.
       01  STATEPUT-OPEN-FLAG        pic X       value 'C'.
       01  STATEPUT-LRECL            pic 9(5)    value 128.

       01  IO-STATUS.
           05  IO-STAT1            pic X.
           05  IO-STAT2            pic X.
       01  TWO-BYTES.
           05  TWO-BYTES-LEFT      pic X.
           05  TWO-BYTES-RIGHT     pic X.
       01  TWO-BYTES-BINARY        redefines TWO-BYTES pic 9(4) comp.

       01  APPL-RESULT             pic S9(9)   comp.
           88  APPL-AOK            value 0.
           88  APPL-EOF            value 16.

      *    The "ASSCENDING KEY" and "INDEXED BY" clauses are used and
      *    required by the "SEARCH ALL" and "SEARCH" functions.
       01  T-STATEDB1-BUFFER.
           05  T-STATEDB1-TABLE        occurs 50 times
                                       ascending key T-STATE-NAME
                                       indexed by IX-1.
               10  T-STATE-NAME        pic X(15).
               10  T-STATE-SHORT       pic X(2).
               10  T-STATE-CAPITOL     pic X(16).
               10  T-STATE-BIRD        pic X(28).
               10  T-STATE-FLOWER      pic X(26).
               10  T-STATE-POPULATION  pic 9(11).
               10  T-STATE-SQ-MILES    pic 9(11).

       01  W-STATEDB1-BUFFER.
           05  W-STATEDB1-TABLE        occurs 50 times.
               10  W-STATE-NAME        pic X(15).
               10  W-STATE-SHORT       pic X(2).
               10  W-STATE-CAPITOL     pic X(16).
               10  W-STATE-BIRD        pic X(28).
               10  W-STATE-FLOWER      pic X(26).
               10  W-STATE-POPULATION  pic 9(11).
               10  W-STATE-SQ-MILES    pic 9(11).

       01  WORK-109                    pic X(109).

       01  LO-1            pic 9(3)    value 0.
       01  HI-1            pic 9(3)    value 0.
       01  PT-1            pic 9(3)    value 0.
       01  SWAP-COUNT      pic 9(3)    value 0.
       01  HIT-FLAG        pic X       value 'N'.

       01  WORK-15         pic X(15)   value SPACES.

       01  POPULATION-DISPLAY.
           05  POP-SEQ     pic 9(2)    value 0.
           05  filler      pic X(2)    value SPACES.
           05  POP-NAME    pic X(15).
           05  filler      pic X(2)    value SPACES.
           05  POP-COUNT   pic ZZ,ZZZ,ZZZ,ZZZ.

       01  DISPLAY-LINE.
           05  DISPLAY-DESCRIPTION     pic X(20).
           05  DISPLAY-CONTENT         pic X(32).

       01  ACCESS-TOTAL.
           05  filler       pic X(23)  value 'The indexed attempt is '.
           05  ACCESS-COUNT pic 9(3) value 0.

       01  SEARCH-NAME             pic X(15).

       01  STATEDB1-TOTAL.
           05  filler       pic X(23)  value 'STATEDB1 line count is '.
           05  STATEDB1-LOC pic 9(7) value 0.

       01  STATEGET-TOTAL.
           05  filler       pic X(23)  value 'STATEGET line count is '.
           05  STATEGET-LOC pic 9(7) value 0.

      *****************************************************************
       PROCEDURE DIVISION.
           perform Z-POST-COPYRIGHT
           perform STATEPUT-OPEN
      *
      *    Load and display the table for State information...
           perform TABLE-LOAD
           perform TABLE-DISPLAY
      *
      *    Perform various table search examples using input from
      *    the STATEGET file.
           perform STATEGET-OPEN
           perform until STATEGET-STATUS not = '00'
             perform STATEGET-READ
             if  STATEGET-STATUS = '00'
      *          Display Start-Up banner...
                 move all '*' to MESSAGE-TEXT-1
                 perform Z-DISPLAY-CONSOLE-MESSAGE
                 move STATEGET-RECORD to MESSAGE-TEXT
                 perform Z-DISPLAY-CONSOLE-MESSAGE
                 move STATEGET-RECORD(1:15)  to WORK-15
                 move STATEGET-RECORD(16:15) to SEARCH-NAME
                 add 1 to STATEGET-LOC
      *          Determine the type of search and execute...
                 evaluate WORK-15
                   when '/BINARY        ' perform TABLE-BINARY-SEARCH
                   when '/LINEAR        ' perform TABLE-LINEAR-SEARCH
                   when '/SEARCH        ' perform TABLE-SEARCH
                   when '/SEARCHALL     ' perform TABLE-SEARCH-ALL
                   when other display WORK-15 ' - Invalid request'
                 end-evaluate
             end-if
           end-perform
           if  STATEGET-EOF = 'Y'
               move 'is Finished...' to MESSAGE-TEXT
           else
               move 'is ABENDING...' to MESSAGE-TEXT
           end-if
           perform Z-DISPLAY-CONSOLE-MESSAGE
           move STATEGET-TOTAL to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE
           perform STATEGET-CLOSE
      *
      *    Move the existing table to a work table then sort the work
      *    table. Display the results showing the states in sequence
      *    by descending order according to population.
           perform TABLE-SORT-BY-POPULATION
      *
      *    End-of-Job Processing
           perform STATEPUT-CLOSE
           perform Z-THANK-YOU.
           GOBACK.

      *****************************************************************
      * Process a /BINARY contol record with custom written code...   *
      *****************************************************************
       TABLE-BINARY-SEARCH.
           move '* TABLE-BINARY-SEARCH is starting'
             to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE
      *    Prepare for the binary search...
           add 1 to ZERO giving LO-1
           add 50 to ZERO giving HI-1
           move ZERO to ACCESS-COUNT
      *    Do the binary search...
           perform until HI-1 - LO-1 < 1
             if  HI-1 - LO-1 - 1 > 1
                 compute PT-1 = LO-1 + (HI-1 - LO-1) / 2
             else
      *          The following will ensure access to the first and last
      *          entries in the table. When the search argument does
      *          not find a match in the table this will ensure the
      *          search proceeds down to the last of two elements.
                 if  PT-1 - 1 = LO-1
                     add LO-1 to ZERO giving PT-1
                     add LO-1 to ZERO giving HI-1
                 else
                     add HI-1 to ZERO giving PT-1
                     add HI-1 to ZERO giving LO-1
                 end-if
             end-if

             if  SEARCH-NAME > T-STATE-NAME(PT-1)
                 add PT-1 to ZERO giving LO-1
             else
                 if  SEARCH-NAME = T-STATE-NAME(PT-1)
                     if  PT-1 > 1
                     and SEARCH-NAME not = T-STATE-NAME(PT-1 - 1)
                         add PT-1 to ZERO giving HI-1
                         add PT-1 to ZERO giving LO-1
                     end-if
                 else
                     add PT-1 to ZERO giving HI-1
                 end-if
             end-if
             add 1 to ACCESS-COUNT
           end-perform
      *    Display closing information...
           move ACCESS-TOTAL to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE

           if  PT-1 > 0
           and PT-1 < 51
           and T-STATE-NAME(PT-1) = SEARCH-NAME
               perform TABLE-DISPLAY-SINGLE-ELEMENT
           else
               display SEARCH-NAME ' not found...' upon console
           end-if
           exit.

      *****************************************************************
       TABLE-DISPLAY.
           perform varying PT-1 from 1 by 1 until PT-1 > 50
             perform TABLE-DISPLAY-SINGLE-ELEMENT
           end-perform
           exit.

      *****************************************************************
       TABLE-DISPLAY-SINGLE-ELEMENT.
           move 'State Name......... ' to DISPLAY-DESCRIPTION
           move SPACES                 to DISPLAY-CONTENT
           move T-STATE-Name(PT-1)     to DISPLAY-CONTENT(1:15)
           move T-STATE-SHORT(PT-1)    to DISPLAY-CONTENT(16:2)
           move DISPLAY-LINE to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE

           move 'State Capitol...... ' to DISPLAY-DESCRIPTION
           move T-STATE-CAPITOL(PT-1)  to DISPLAY-CONTENT
           move DISPLAY-LINE to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE

           move 'State Bird......... ' to DISPLAY-DESCRIPTION
           move T-STATE-BIRD(PT-1)     to DISPLAY-CONTENT
           move DISPLAY-LINE to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE

           move 'State Flower....... ' to DISPLAY-DESCRIPTION
           move T-STATE-FLOWER(PT-1)   to DISPLAY-CONTENT
           move DISPLAY-LINE to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE

           move 'Population......... ' to DISPLAY-DESCRIPTION
           move T-STATE-POPULATION(PT-1)  to DISPLAY-CONTENT
           move DISPLAY-LINE to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE

           move 'Size (Sq Miles).... ' to DISPLAY-DESCRIPTION
           move T-STATE-SQ-MILES(PT-1)  to DISPLAY-CONTENT
           move DISPLAY-LINE to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE

           move ' ' to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE
           exit.

      *****************************************************************
      * Process a /LINEAR contol record with custom written code...   *
      *****************************************************************
       TABLE-LINEAR-SEARCH.
           move '* TABLE-LINEAR-SEARCH is starting'
             to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE
      *    Do the Linear search...
           perform varying PT-1 from 1 by 1
             until PT-1 > 50
             or T-STATE-NAME(PT-1) = SEARCH-NAME
           end-perform
      *    Prepare and display closing information...
           add PT-1 to ZERO giving ACCESS-COUNT
           set IX-1 to PT-1
           move ACCESS-TOTAL to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE
           if  PT-1 > 0
           and PT-1 < 51
           and T-STATE-NAME(PT-1) = SEARCH-NAME
               perform TABLE-DISPLAY-SINGLE-ELEMENT
           else
               display SEARCH-NAME ' not found...' upon console
           end-if
           exit.

      *****************************************************************
       TABLE-LOAD.
      *    Display Start-Up banner...
           move all '*' to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE
           move '* TABLE-LOAD is starting'
             to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE
      *    Prepare to load the table
           perform STATEDB1-OPEN
           add 1 to ZERO giving PT-1
      *    Read the file and load the table...
           perform until STATEDB1-STATUS not = '00'
             perform STATEDB1-READ
             if  STATEDB1-STATUS = '00'
                 add 1 to STATEDB1-LOC
                 move STATE-NAME       to T-STATE-NAME(PT-1)
                 move STATE-SHORT      to T-STATE-SHORT(PT-1)
                 move STATE-CAPITOL    to T-STATE-CAPITOL(PT-1)
                 move STATE-BIRD       to T-STATE-BIRD(PT-1)
                 move STATE-FLOWER     to T-STATE-FLOWER(PT-1)
                 move STATE-POPULATION to T-STATE-POPULATION(PT-1)
                 move STATE-SQ-MILES   to T-STATE-SQ-MILES(PT-1)
                 add 1 to PT-1
             end-if
           end-perform
      *    Prepare and display closing information...
           perform STATEDB1-CLOSE
           move STATEDB1-TOTAL to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE
           exit.

      *****************************************************************
      * Process a /SEARCH contol record using standard COBOL dialect  *
      *****************************************************************
       TABLE-SEARCH.
           move '* TABLE-SEARCH is starting using COBOL SEARCH...'
             to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE
      *    Do the search...
           add 1 to ZERO giving PT-1
           move 'N' to HIT-FLAG
           search T-STATEDB1-TABLE varying PT-1
                  at end
                     move 'N' to HIT-FLAG
                  when T-STATE-NAME(IX-1) = SEARCH-NAME
                       move 'Y' to HIT-FLAG
           end-search.
      *    Prepare and display closing information...
      *    Set pointer for use by the TABLE DISPLAY function....
           add PT-1 to ZERO giving ACCESS-COUNT
           move ACCESS-TOTAL to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE
           if  HIT-FLAG = 'Y'
               perform TABLE-DISPLAY-SINGLE-ELEMENT
           end-if
           exit.

      *****************************************************************
      * Process a /SEARCHALL contol record use standard COBOL dialect *
      *****************************************************************
       TABLE-SEARCH-ALL.
           move '* TABLE-SEARCH-ALL is starting using COBOL SEARCH...'
             to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE
      *    Do the SEARCH ALL, this will do a binary search. The table
      *    must be in sequence for the SEARCH ALL to work properly...
           add 1 to ZERO giving PT-1
           move 'N' to HIT-FLAG
           search all T-STATEDB1-TABLE
                  at end
                     move 'N' to HIT-FLAG
                  when T-STATE-NAME(IX-1) = SEARCH-NAME
                       move 'Y' to HIT-FLAG
           end-search.
      *    Prepare and display closing information...
      *    Set pointer for use by the TABLE DISPLAY function....
           set PT-1 to IX-1
           move 'SEARCH ALL does a binary search' to MESSAGE-TEXT-1
           perform Z-DISPLAY-CONSOLE-MESSAGE
      *    If a table hit then display table element.
           if  HIT-FLAG = 'Y'
               perform TABLE-DISPLAY-SINGLE-ELEMENT
           end-if
           exit.

      *****************************************************************
      * Sort the table by the population value                        *
      *****************************************************************
       TABLE-SORT-BY-POPULATION.
           move T-STATEDB1-BUFFER to W-STATEDB1-BUFFER
           add  1 to ZERO giving PT-1
           add  1 to ZERO giving LO-1
           add 50 to ZERO giving HI-1
           move 'Y' to HIT-FLAG
      *
      *    Do a descending bubble sort of the work table by population
           perform until HIT-FLAG = 'N'
             move 'N' to HIT-FLAG
             add  1 to ZERO giving PT-1
             perform until PT-1 > HI-1
                        or PT-1 = HI-1
               if  W-STATE-POPULATION(PT-1)
                <  W-STATE-POPULATION(PT-1 + 1)
                   move 'Y' to HIT-FLAG
                   move W-STATEDB1-TABLE(PT-1) to WORK-109
                   move W-STATEDB1-TABLE(PT-1 + 1)
                     to W-STATEDB1-TABLE(PT-1)
                   move WORK-109 to W-STATEDB1-TABLE(PT-1 + 1)
               end-if
               add 1 to PT-1
             end-perform
           end-perform
      *
      *    Display the list of states with largest to smallest in
      *    size by population using the sorted work table.
           perform varying PT-1 from 1 by 1 until PT-1 > 50
             add PT-1 to ZERO giving POP-SEQ
             move W-STATE-NAME(PT-1)       to POP-NAME
             move W-STATE-POPULATION(PT-1) to POP-COUNT
      *      Display information to screen.
             move POPULATION-DISPLAY to MESSAGE-TEXT
             perform Z-DISPLAY-CONSOLE-MESSAGE
      *      Write to the file.
             move POPULATION-DISPLAY to STATEPUT-DATA-01
             perform STATEPUT-WRITE
           end-perform

           exit.

      *****************************************************************
      * I/O ROUTINES FOR STATEDB1...                                  *
      *****************************************************************
       STATEDB1-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close STATEDB1-FILE
           if  STATEDB1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'STATEDB1-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move STATEDB1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       STATEDB1-READ.
           read STATEDB1-FILE
           if  STATEDB1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  STATEDB1-STATUS = '10'
                   add 16 to ZERO giving APPL-RESULT
               else
                   add 12 to ZERO giving APPL-RESULT
               end-if
           end-if
           if  APPL-AOK
               CONTINUE
           else
               if  APPL-EOF
                   move 'Y' to STATEDB1-EOF
               else
                   move 'STATEDB1-Failure-GET...' to MESSAGE-TEXT
                   perform Z-DISPLAY-CONSOLE-MESSAGE
                   move STATEDB1-STATUS to IO-STATUS
                   perform Z-DISPLAY-IO-STATUS
                   perform Z-ABEND-PROGRAM
               end-if
           end-if
           exit.
      *---------------------------------------------------------------*
       STATEDB1-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open input STATEDB1-FILE
           if  STATEDB1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to STATEDB1-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'STATEDB1-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move STATEDB1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.

      *****************************************************************
      * I/O ROUTINES FOR STATEGET...                                  *
      *****************************************************************
       STATEGET-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close STATEGET-FILE
           if  STATEGET-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'STATEGET-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move STATEGET-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       STATEGET-READ.
           read STATEGET-FILE
           if  STATEGET-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  STATEGET-STATUS = '10'
                   add 16 to ZERO giving APPL-RESULT
               else
                   add 12 to ZERO giving APPL-RESULT
               end-if
           end-if
           if  APPL-AOK
               CONTINUE
           else
               if  APPL-EOF
                   move 'Y' to STATEGET-EOF
               else
                   move 'STATEGET-Failure-GET...' to MESSAGE-TEXT
                   perform Z-DISPLAY-CONSOLE-MESSAGE
                   move STATEGET-STATUS to IO-STATUS
                   perform Z-DISPLAY-IO-STATUS
                   perform Z-ABEND-PROGRAM
               end-if
           end-if
           exit.
      *---------------------------------------------------------------*
       STATEGET-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open input STATEGET-FILE
           if  STATEGET-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to STATEGET-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'STATEGET-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move STATEGET-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.

      *****************************************************************
      * I/O ROUTINES FOR STATEPUT...                                  *
      *****************************************************************
       STATEPUT-WRITE.
           if  STATEPUT-OPEN-FLAG = 'C'
               perform STATEPUT-OPEN
           end-if
           write STATEPUT-RECORD
           if  STATEPUT-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  STATEPUT-STATUS = '10'
                   add 16 to ZERO giving APPL-RESULT
               else
                   add 12 to ZERO giving APPL-RESULT
               end-if
           end-if.
           if  APPL-AOK
               CONTINUE
           else
               move 'STATEPUT-Failure-WRITE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move STATEPUT-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       STATEPUT-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open output STATEPUT-FILE
           if  STATEPUT-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to STATEPUT-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'STATEPUT-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move STATEPUT-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       STATEPUT-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close STATEPUT-FILE
           if  STATEPUT-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'C' to STATEPUT-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'STATEPUT-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move STATEPUT-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.

      *****************************************************************
      * The following Z-Routines perform administrative tasks         *
      * for this program.                                             *
      *****************************************************************
      * ABEND the program, post a message to the console and issue    *
      * a STOP RUN.                                                   *
      *****************************************************************
       Z-ABEND-PROGRAM.
           if  MESSAGE-TEXT not = SPACES
               perform Z-DISPLAY-CONSOLE-MESSAGE
           end-if
           move 'PROGRAM-IS-ABENDING...'  to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE
           add 12 to ZERO giving RETURN-CODE
           STOP RUN
           exit.

      *****************************************************************
      * Display CONSOLE messages...                                   *
      *****************************************************************
       Z-DISPLAY-CONSOLE-MESSAGE.
           if MESSAGE-TEXT-2 = SPACES
               display MESSAGE-BUFFER(1:79) upon console
           else
               display MESSAGE-BUFFER upon console
           end-if
           move all SPACES to MESSAGE-TEXT
           exit.

      *****************************************************************
      * Display the file status bytes. This routine will display as   *
      * two digits if the full two byte file status is numeric. If    *
      * second byte is non-numeric then it will be treated as a       *
      * binary number.                                                *
      *****************************************************************
       Z-DISPLAY-IO-STATUS.
           if  IO-STATUS not NUMERIC
           or  IO-STAT1    = '9'
               subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
               move IO-STAT2 to TWO-BYTES-RIGHT
               display '* CBLBINC1 File-Status-' IO-STAT1 '/'
                       TWO-BYTES-BINARY upon console
           else
               display '* CBLBINC1 File-Status-' IO-STATUS upon console
           end-if
           exit.

      *****************************************************************
       Z-POST-COPYRIGHT.
           display SIM-TITLE     upon console
           display SIM-COPYRIGHT upon console
           exit.

      *****************************************************************
       Z-THANK-YOU.
           display SIM-THANKS-01 upon console
           display SIM-THANKS-02 upon console
           exit.
      *****************************************************************
      *      This example is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

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. 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 appear 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 appear 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.

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

You may download this example at  http://www.simotime.com/sim4dzip.htm#COBOLTableProcessingZip  as a Z-Pack. 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.

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

The following chart provides a list of the sample COBOL programs that do table processing.

HTML Tag Description
binbit01 This suite of sample programs describes how to use COBOL to create a table or text string of binary values from X'00' through X'FF'.
cblbin01 This suite of programs provides an example of how a COBOL program does various table functions such as a table load, a standard COBOL "SEARCH", a standard COBOL "SEARCH ALL", a user written binary search and a user written linear search.
cbltbl01 This suite of sample programs describes how to use COBOL to load a table with customer information and then sort the table using a bubble sort routine. The elements in the table will be sorted in postal code sequence.
stamlr01 The program has the ability to print 1,2, 3 or 4 across labels. This example uses a two-dimensional array to build the label-printing output.

Check out  The COBOL Connection  for more examples of mainframe COBOL coding techniques and sample code.

Check out  The JCL Connection  for more mainframe JCL examples.

Check out  The SQL Connection  for more examples of mainframe Relational Data Dase management and accessing techniques with sample code.

Check out  The VSAM - QSAM Connection  for more examples of mainframe VSAM and QSAM accessing techniques and sample code.

This document provides a quick summary of the  File Status Key  for VSAM data sets and QSAM files.

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