Table Processing
 Bubble Sort
When technology complements business    Copyright © 1987-2012  SimoTime Enterprises  All Rights Reserved
  Table of Contents Version 10.11.01 
  Introduction
  Sample Routines
  Sample Routines, Load the Table
  Sample Routines, Sort Table By Postal Code
  Sample Routines, Sequentially Retrieve the Elements in the Table
  JCL Member for Execution
  CMD Member for Execution
  The COBOL Demonstration Program
  Summary
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Downloads and Links, Internet Access Required
  Downloads and Links, Local Access
  Glossary of Terms
  Comments, Suggestions or Feedback
  Company Overview
The SimoTime Home Page

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

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.

The source code for the CMD file, the JCL member and the COBOL programs is provided and may be modified to fit your environment. The COBOL program will run on an IBM Mainframe System or in a Micro Focus environment on Windows.

Sample Routines
(Next) (Previous) (Table-of-Contents)

The intent of this section is to provide a summary of the sub-routines by function and a quick link to the sub-routines within the main program.

Sample Routines, Load the Table
(Next) (Previous) (Table-of-Contents)

This sub-routine will read a record sequential file of eighty-byte records and load each record into an element of an in-memory table. The table contains one-hundred (100) elements.

Click on this link to view the code in the program that does the Load the Table. This will be displayed in a separate window.

Sample Routines, Sort Table By Postal Code
(Next) (Previous) (Table-of-Contents)

Once the table is loaded it will be sorted based on the postal code value.

Click on this link to view the code in the program that does the Sort Table By Postal Code. This will be displayed in a separate window.

Sample Routines, Sequentially Retrieve the Elements in the Table
(Next) (Previous) (Table-of-Contents)

Next, the table will be processed sequentially to produce a file of mailing labels in postal code sequence.

Click on this link to view the code in the program that will Sequentially Retrieve the Elements in the Table. This will be displayed in a separate window.

JCL Member for Execution
(Next) (Previous) (Table-of-Contents)

The following (CBLTBLJ1.JCL) is a sample of the Mainframe JCL needed to run this job.

//CBLTBLJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1
//* *******************************************************************
//*        This program is provided by: SimoTime Enterprises          *
//*           (C) Copyright 1987-2012 All Rights Reserved             *
//*             Web Site URL:   http://www.simotime.com               *
//*                   e-mail:   helpdesk@simotime.com                 *
//* *******************************************************************
//*
//* Text   - COBOL code for table processing tasks.
//* Author - SimoTime Enterprises
//* Date   - January 01, 1989
//*
//* This set of programs illustrate the use of COBOL programs that
//* perform table processing tasks.
//*
//* This set of programs will run on a mainframe under MVS or on
//* a Personal Computer running Windows and Mainframe Express by
//* Micro Focus.
//*
//*   ************                    ************
//*   *  Entry   *                    *  Entry   *
//*   *   MVS    *                    * Windows  *
//*   ************                    ************
//*        *                               *
//*   ************                    ************
//*   * CBLTBLJ1 *                    * CBLTBLE1 *
//*   ********jcl*                    ********cmd*
//*        *                               *
//*   ************                    ************
//*   * IEFBR14  *                    * If Exist *
//*   ********utl*                    *******stmt*
//*        *                               *
//*        *********************************
//*                        *
//*                        *
//*   ************    ************    ************
//*   * CURS0080 *----* CBLTBLC1 *----* LABEL1X6 *
//*   *******rseq*    ********cbl*    *******rseq*
//*                        *
//*                        *
//*                   ************
//*                   *   EOJ    *
//*                   ************
//*
//* *******************************************************************
//* Step   1 of 2  This job step will delete a previously created
//*        LABELS file.
//*
//CBLTBLS1 EXEC PGM=IEFBR14
//LABEL1X6 DD  DSN=SIMOTIME.DATA.LABEL1X6,DISP=(MOD,DELETE,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=48,BLKSIZE=480,DSORG=PS)
//* *******************************************************************
//* Step   2 of 2  Execute the Sample program....
//*
//CBLTBLS2 EXEC PGM=CBLTBLC1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//CURS0080 DD  DSN=SIMOTIME.DATA.CUST0080,DISP=SHR
//LABEL1X6 DD  DSN=SIMOTIME.DATA.LABEL1X6,DISP=(NEW,CATLG,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=48,BLKSIZE=480,DSORG=PS)
//SYSOUT   DD  SYSOUT=*
//*

CMD Member for Execution
(Next) (Previous) (Table-of-Contents)

The following (CBLTBLE1.CMD) is a sample of the Windows CMD needed to run this job.

@echo OFF
rem  * *******************************************************************
rem  *               CBLTBLE1.CMD - a Windows Command File               *
rem  *         This program is provided by SimoTime Enterprises          *
rem  *           (C) Copyright 1987-2012 All Rights Reserved             *
rem  *             Web Site URL:   http://www.simotime.com               *
rem  *                   e-mail:   helpdesk@simotime.com                 *
rem  * *******************************************************************
rem  *
rem  *
rem  * Text   - COBOL code for table processing tasks.
rem  * Author - SimoTime Enterprises
rem  * Date   - January 01, 1989
rem  *
rem  * This set of programs illustrate the use of COBOL programs that
rem  * perform table processing tasks.
rem  *
rem  * This set of programs will run on a mainframe under MVS or on
rem  * a Personal Computer running Windows and Mainframe Express by
rem  * Micro Focus.
rem  *
rem  * ********************************************************************
rem  * Step   1 of 2  Set the global environment variables...
rem  *
     setlocal
     set CmdName=CblTblE1
     call ..\Env1BASE
     set path
     set JobStatus=0000
     if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
rem  *
     call SimoNOTE "*******************************************************%CmdName%"
     call SimoNOTE "Starting JobName %CmdName%"
rem  * ********************************************************************
rem  * Step   2 of 2  Execute the sample program...
rem  *
     set CURS0080=%BaseLib1%\DataLibA\Asc1\SIMOTIME.DATA.CURA0080.DAT
     set LABEL1X6=%BaseLib1%\DataLibA\Wrk1\SIMOTIME.DATA.LABEL1X6.DAT
     if exist %LABEL1X6% erase %LABEL1X6%
     run CblTblC1
     if not "%ERRORLEVEL%" == "0" set JobStatus=0010
     if not "%JobStatus%" == "0000" goto :EojNOK
:EojAOK
     call SimoNOTE "Produced %LABEL1X6%"
     call SimoNOTE "Finished JobName %CmdName%, Job Status is %JobStatus%"
     goto :End
:EojNOK
     call SimoNOTE "ABENDING JobName %CmdName%, Job Status is %JobStatus%"
     echo %CmdName% is ABENDING>>%BaseLib1%\LOGS\ABENDLOG.TXT
     goto :End
:End
     call SimoNOTE "Conclude SysLog is %SYSLOG%"
     if not "%1" == "nopause" pause
     endlocal

The COBOL Demonstration Program
(Next) (Previous) (Table-of-Contents)

The following (CBLTBLC1.CBL) is a sample of a COBOL program.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLTBLC1.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2012 SimoTime Enterprises.                 *
      *                                                               *
      * 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 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.                                                  *
      *                                                               *
      * 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.                                                  *
      *                                                               *
      * SimoTime Enterprises makes no warranty or representations     *
      * about the suitability of the software for any purpose. It is  *
      * provided "AS IS" without any expressed 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       *
      *                                                               *
      *****************************************************************
      * MAINTENANCE
      * -----------
      * 1994/02/27 Simmons, Created program.
      *
      *****************************************************************
      * Source Member: CBLTBLC1.CBL
      * Copy Files:    CU2SEQB1
      * Calls to:      none...
      *****************************************************************
      *                                                               *
      *                                   Record    Record     Key    *
      *  Function  Name     Organization  Format    Max-Min  Pos-Len  *
      *  INPUT     CURS0080 ASCII/CRLF    VARIABLE   00512            *
      *  OUTPUT    MEMCODEA ASCII/CRLF    VARIABLE   00512            *
      *                                                               *
      *****************************************************************
      * This program will load a table with data from a sequential
      * file. The maximum number of table entries for this sample is
      * fifty (50) items.
      *
      * After loading the table it will be sorted using a bubble sort
      * routine to arrange the items in Postal Code sequence.
      *
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT CURS0080-FILE  ASSIGN TO       CURS0080
                  ORGANIZATION IS SEQUENTIAL
                  ACCESS MODE  IS SEQUENTIAL
                  FILE STATUS  IS CURS0080-STATUS.
           SELECT LABEL1X6-FILE  ASSIGN TO       LABEL1X6
                  ORGANIZATION IS SEQUENTIAL
                  ACCESS MODE  IS SEQUENTIAL
                  FILE STATUS  IS LABEL1X6-STATUS.

      *****************************************************************
       DATA DIVISION.
       FILE SECTION.
       FD  CURS0080-FILE
           DATA RECORD    IS CURS0080-RECORD
           .
       COPY CUST80B1.

       FD  LABEL1X6-FILE
           DATA RECORD    IS LABEL1X6-RECORD
           .
       01  LABEL1X6-RECORD.
           05  LABEL1X6-LINE           PIC X(48).

      *****************************************************************
       WORKING-STORAGE SECTION.
      *****************************************************************
      *    Data-structure for Title and Copyright...
      *****************************************************************
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLTBLC1 '.
           05  T2 pic X(34) value 'Example for Table Processing      '.
           05  T3 pic X(10) value ' v08.02.28'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLTBLC1 '.
           05  C2 pic X(20) value 'Copyright 1987-2012 '.
           05  C3 pic X(28) value '--- SimoTime Enterprises ---'.
           05  C4 pic X(20) value ' All Rights Reserved'.

       01  SIM-THANKS-01.
           05  C1 pic X(11) value '* CBLTBLC1 '.
           05  C2 pic X(32) value 'Thank you for using this softwar'.
           05  C3 pic X(32) value 'e provided from SimoTime Enterpr'.
           05  C4 pic X(04) value 'ises'.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* CBLTBLC1 '.
           05  C2 pic X(32) value 'Please send all inquires or sugg'.
           05  C3 pic X(32) value 'estions to the helpdesk@simotime'.
           05  C4 pic X(04) value '.com'.

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

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

       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  IO-STATUS-4             pic 9(4)  value 0.
       01  IO-STATUS-4A            redefines IO-STATUS-4 pic X(4).

      *****************************************************************
      * Message Buffer used by the Z-DISPLAY-MESSAGE-TEXT routine.    *
      *****************************************************************
       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* CBLTBLC1 '.
           05  MESSAGE-TEXT.
               10  MESSAGE-TEXT-1  pic X(68)   value SPACES.
               10  MESSAGE-TEXT-2  pic X(188)  value SPACES.

      *****************************************************************
      *    Data-structure for environment variable get routine...
      *****************************************************************
       01  ENV-VAR-NAME            pic X(16)   value SPACES.
       01  ENV-VAR-VALUE           pic X(256)  value SPACES.

       01  ENV-VAR-SIZE            pic 9(3)    value 0.
       01  BUFFER-SIZE             pic 9(3)    value 80.
       01  PTR-01                  pic 9(3)    value 0.
       01  NUMB-01                 pic 9(3)    value 0.

       01  TASK-FLAGS.
           05  TASK-FLAG-BANNER    pic X       value 'Y'.
           05  TASK-FLAG-THANKS    pic X       value 'Y'.
           05  TASK-FLAG-DISPLAY   pic X       value 'Y'.
           05  TASK-FLAG-SYSOUT    pic X       value 'Y'.

       01  CURS0080-TOTAL.
           05  filler      pic X(23)   value 'Source member count is '.
           05  CURS0080-RDR  pic 9(9)    value 0.
           05  filler      pic X       value SPACE.
       01  CURS0080-TOTAL-2.
           05  filler      pic X(23)   value 'Total Lines of Code is '.
           05  TOTAL-LOC   pic 9(9)    value 0.
           05  filler      pic X(20)   value ' Total Hex count is '.
           05  TOTAL-ERR   pic 9(9)    value 0.

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

       01  WRK-202                 pic X(202)  value SPACES.
       01  ROUTINE-NAME            pic X(31).

       01  INSERT-COMMA.
           05  FILLER              pic X(2)    value ', '.
           05  WRK-18              pic X(18)   value SPACES.
       01  INSERT-COMMA-X          redefines INSERT-COMMA
                                   pic X(20).

       01  INSERT-SPACE.
           05  FILLER              pic X       value ' '.
           05  WRK-28              pic X(28)   value SPACES.
       01  INSERT-SPACE-X          redefines INSERT-SPACE
                                   pic X(29).

       01  TIX-1                   pic 9(3)    value 0.
       01  TIX-LO                  pic 9(3)    value 0.
       01  TIX-HI                  pic 9(3)    value 0.
       01  TIX-DIFF                pic 9(3)    value 0.
       01  TIX-CURR                pic 9(3)    value 0.
       01  TIX-SWAP-LO             pic 9(3)    value 0.
       01  TIX-SWAP-HI             pic 9(3)    value 0.
       01  NUMBER-OF-ACTIVE-ITEMS  pic 9(3)    value 0.

       COPY LABTABLE.

      *****************************************************************
       PROCEDURE DIVISION.

      *    Perform First-Time processing...
           perform Z-POST-COPYRIGHT

      *    Load the table with data from a file...
           perform LOAD-THE-TABLE

      *    Sort the table by Postal Code
           add TIX-1 to ZERO giving TIX-HI
           add 1 to ZERO giving TIX-LO
           perform SORT-TABLE-BY-POSTAL-CODE

      *    Write the Mailing Labels in Postal Code sequence...
           perform CREATE-LABELS-FROM-TABLE

      *    Possible Abnormal Termination (ABEND)...
           if  APPL-AOK
               if  CURS0080-EOF not = 'Y'
               or  LABEL1X6-EOF not = 'Y'
                   add 16 to ZERO giving APPL-RESULT
               end-if
           end-if
           if  not APPL-AOK
               move 'is ABENDING...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
           end-if

      *    End-of-Job...
           if  TASK-FLAG-BANNER = 'Y'
               perform Z-THANK-YOU
           end-if

           GOBACK.

      *****************************************************************
      * CREATE-LABELS-FROM-TABLE
      * This routine will access the table sequentially and produce
      * mailing labels in postal code sequence.
      *
       CREATE-LABELS-FROM-TABLE.
           move 'CREATE-LABELS-FROM-TABLE' to ROUTINE-NAME
           perform Z-ROUTINE-STARTING
           add 1 to ZERO giving TIX-1
           perform LABEL1X6-OPEN
             perform until TIX-1 > NUMBER-OF-ACTIVE-ITEMS
      *        Put the First name to Last name separated by a
      *        space on line one (1) of the mailing label.
               move TABL-FIRST-NAME(TIX-1)      to LABEL1X6-LINE
               move TABL-LAST-NAME(TIX-1)      to WRK-28
               inspect LABEL1X6-LINE replacing
                       first '                             '
                       by INSERT-SPACE-X
               perform LABEL1X6-WRITE-WITH-CLEAR

               if  TABL-ADDRESS-1(TIX-1) not = SPACES
                   move TABL-ADDRESS-1(TIX-1)   to LABEL1X6-LINE
                   perform LABEL1X6-WRITE-WITH-CLEAR
               end-if
               if  TABL-ADDRESS-2(TIX-1) not = SPACES
                   move TABL-ADDRESS-2(TIX-1)   to LABEL1X6-LINE
                   perform LABEL1X6-WRITE-WITH-CLEAR
               end-if
      *        Put the City, State and Postal Code on a single line
      *        of the mailing label.
               move TABL-CITY(TIX-1)       to LABEL1X6-LINE
               move TABL-STATE(TIX-1)      to WRK-18
               inspect LABEL1X6-LINE replacing
                       first '                    '
                       by INSERT-COMMA-X
               move TABL-POSTAL-CODE(TIX-1)      to WRK-28
               inspect LABEL1X6-LINE replacing
                       first '                             '
                       by INSERT-SPACE-X
               perform LABEL1X6-WRITE-WITH-CLEAR

               perform LABEL1X6-WRITE-WITH-CLEAR
               perform LABEL1X6-WRITE-WITH-CLEAR
               if  TABL-ADDRESS-1(TIX-1) = SPACES
                   perform LABEL1X6-WRITE-WITH-CLEAR
               end-if
               if  TABL-ADDRESS-2(TIX-1) = SPACES
                   perform LABEL1X6-WRITE-WITH-CLEAR
               end-if
               add 1 to TIX-1
             end-perform
           perform LABEL1X6-CLOSE
           perform Z-ROUTINE-FINISHED
           exit.

      *****************************************************************
      * LOAD-THE-TABLE
      * This routine will read a file and load the records into a table
      * in memory. The maximum number of entries in the table is
      * one-hundred (100).
      *
       LOAD-THE-TABLE.
           move 'LOAD-THE-TABLE' to ROUTINE-NAME
           perform Z-ROUTINE-STARTING
           perform CURS0080-OPEN
           move ZERO to TIX-1
           perform until CURS0080-STATUS not = '00'
               perform CURS0080-READ
               if  CURS0080-STATUS = '00'
               and CUST-80-RECORD not = SPACES
                   add 1 to TIX-1
                   move CUST-80-LNAME  to TABL-LAST-NAME(TIX-1)
                   move CUST-80-FNAME  to TABL-FIRST-NAME(TIX-1)
                   move CUST-80-ZIP    to TABL-POSTAL-CODE(TIX-1)
                   move CUST-80-STREET to TABL-ADDRESS-1(TIX-1)
                   move SPACES         to TABL-ADDRESS-2(TIX-1)
                   move CUST-80-CITY   to TABL-CITY(TIX-1)
                   move CUST-80-STATE  to TABL-STATE(TIX-1)
               end-if
           end-perform
           add TIX-1 to ZERO giving NUMBER-OF-ACTIVE-ITEMS
           perform CURS0080-CLOSE
           perform Z-ROUTINE-FINISHED
           exit.

      *****************************************************************
      * SORT-TABLE-BY-POSTAL-CODE
      * This routine expects TIX-LO to be set to one (1) or point to
      * the first table to be processed. TIX-HI should be set to the
      * number of active entries in the table.
      *
       SORT-TABLE-BY-POSTAL-CODE.
           move 'SORT-TABLE-BY-POSTAL-CODE' to ROUTINE-NAME
           perform Z-ROUTINE-STARTING
           perform until TIX-HI = 0
      *        Prepare for a Low-to-High pass of Table...
               add TIX-LO to ZERO GIVING TIX-CURR
               move 0 to TIX-SWAP-HI
      *        Low-to-High pass of Table, reset High-Limit for Scan...
               perform until TIX-CURR not less than TIX-HI
                   if  TABL-POSTAL-CODE(TIX-CURR) GREATER THAN
                       TABL-POSTAL-CODE(TIX-CURR + 1)
                       move TABLE-OF-CUSTOMERS(TIX-CURR) to WRK-202
                       move TABLE-OF-CUSTOMERS(TIX-CURR + 1)
                         to TABLE-OF-CUSTOMERS(TIX-CURR)
                       move WRK-202 to TABLE-OF-CUSTOMERS(TIX-CURR + 1)
                       add TIX-CURR to ZERO giving TIX-SWAP-HI
                   end-if
                   add 1 to TIX-CURR
               end-perform
      *        Set a new HIGH-LIMIT for table scan...
               add TIX-SWAP-HI to ZERO giving TIX-HI

      *        Prepare for a High-to-Low pass of Table...
               add TIX-HI to ZERO giving TIX-CURR
               move 0 to TIX-LO
      *        High-to-Low pass of Table, reset Low-Limit for Scan...
               perform until TIX-CURR not greater than TIX-LO
                   if  TABL-POSTAL-CODE(TIX-CURR) GREATER THAN
                       TABL-POSTAL-CODE(TIX-CURR + 1)
                       move TABLE-OF-CUSTOMERS(TIX-CURR) to WRK-202
                       move TABLE-OF-CUSTOMERS(TIX-CURR + 1)
                         to TABLE-OF-CUSTOMERS(TIX-CURR)
                       move WRK-202 to TABLE-OF-CUSTOMERS(TIX-CURR + 1)
                       add TIX-CURR to ZERO giving TIX-SWAP-LO
                   end-if
                   subtract 1 from TIX-CURR
               end-perform
      *        Set a new LOW-LIMIT for table scan...
               add TIX-SWAP-LO to ZERO giving TIX-LO
           end-perform
           perform Z-ROUTINE-FINISHED
           exit.

      *****************************************************************
      * I/O ROUTINES FOR LABEL1X6...                                 *
      *****************************************************************
       LABEL1X6-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close LABEL1X6-FILE
           if  LABEL1X6-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               move 'Y' to LABEL1X6-EOF
           else
               move 'LABEL1X6-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move LABEL1X6-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       LABEL1X6-WRITE-WITH-CLEAR.
           perform LABEL1X6-WRITE
           move SPACES to LABEL1X6-RECORD
           exit.

      *---------------------------------------------------------------*
       LABEL1X6-WRITE.
           write LABEL1X6-RECORD
           if  LABEL1X6-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  LABEL1X6-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 LABEL1X6-EOF
               else
                   move 'LABEL1X6-Failure-PUT...' to MESSAGE-TEXT
                   perform Z-DISPLAY-MESSAGE-TEXT
                   move LABEL1X6-STATUS to IO-STATUS
                   perform Z-DISPLAY-IO-STATUS
                   perform Z-ABEND-PROGRAM
               end-if
           end-if
           exit.
      *---------------------------------------------------------------*
       LABEL1X6-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open output LABEL1X6-FILE
           if  LABEL1X6-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to LABEL1X6-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'LABEL1X6-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move LABEL1X6-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.

      *****************************************************************
      * I/O ROUTINES FOR TXTA06512...                                 *
      *****************************************************************
       CURS0080-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close CURS0080-FILE
           if  CURS0080-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               move 'Y' to CURS0080-EOF
           else
               move 'CURS0080-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CURS0080-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       CURS0080-READ.
           read CURS0080-FILE
           if  CURS0080-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  CURS0080-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 CURS0080-EOF
               else
                   move 'CURS0080-Failure-GET...' to MESSAGE-TEXT
                   perform Z-DISPLAY-MESSAGE-TEXT
                   move CURS0080-STATUS to IO-STATUS
                   perform Z-DISPLAY-IO-STATUS
                   perform Z-ABEND-PROGRAM
               end-if
           end-if
           exit.
      *---------------------------------------------------------------*
       CURS0080-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open input CURS0080-FILE
           if  CURS0080-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to CURS0080-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'CURS0080-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CURS0080-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-MESSAGE-TEXT
           end-if
           move 'PROGRAM-IS-ABENDING...'  to MESSAGE-TEXT
           perform Z-DISPLAY-MESSAGE-TEXT
           add 12 to ZERO giving RETURN-CODE
           STOP RUN.
      *    exit.

      *****************************************************************
       Z-POST-COPYRIGHT.
           move SIM-TITLE to MESSAGE-BUFFER
           perform Z-DISPLAY-MESSAGE-TEXT
           move SIM-COPYRIGHT to MESSAGE-BUFFER
           perform Z-DISPLAY-MESSAGE-TEXT
           exit.

      *****************************************************************
      * Display the file status bytes. This routine will display as   *
      * four digits. If the full two byte file status is numeric it   *
      * will display as 00nn. If the 1st byte is a numeric nine (9)   *
      * the second byte will be treated as a binary number and will   *
      * display as 9nnn.                                              *
      *****************************************************************
       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
               add TWO-BYTES-BINARY to ZERO giving IO-STATUS-4
               move IO-STAT1 to IO-STATUS-4A(1:1)
               move 'File Status is: nnnn' to MESSAGE-TEXT
               move IO-STATUS-4A to MESSAGE-TEXT(17:4)
               perform Z-DISPLAY-MESSAGE-TEXT
           else
               move '0000' to IO-STATUS-4A
               move IO-STATUS to IO-STATUS-4A(3:2)
               move 'File Status is: nnnn' to MESSAGE-TEXT
               move IO-STATUS-4A to MESSAGE-TEXT(17:4)
               perform Z-DISPLAY-MESSAGE-TEXT
           end-if
           exit.

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

      *****************************************************************
       Z-ROUTINE-STARTING.
           if  TASK-FLAG-DISPLAY = 'Y'
               move all '-' to MESSAGE-TEXT(1:64)
               move     '*' to MESSAGE-TEXT(1:1)
               move     '*' to MESSAGE-TEXT(64:1)
               perform Z-DISPLAY-MESSAGE-TEXT
               move 'Starting ' to MESSAGE-TEXT
               move ROUTINE-NAME to MESSAGE-TEXT(10:32)
               perform Z-DISPLAY-MESSAGE-TEXT
           end-if
           exit.

      *****************************************************************
       Z-ROUTINE-FINISHED.
           if  TASK-FLAG-DISPLAY = 'Y'
               move 'Finished ' to MESSAGE-TEXT
               move ROUTINE-NAME to MESSAGE-TEXT(10:32)
               perform Z-DISPLAY-MESSAGE-TEXT
               move SPACES to ROUTINE-NAME
           end-if
           exit.


      *****************************************************************
       Z-THANK-YOU.
           move SIM-THANKS-01 to MESSAGE-BUFFER
           perform Z-DISPLAY-MESSAGE-TEXT
           move SIM-THANKS-02 to MESSAGE-BUFFER
           perform Z-DISPLAY-MESSAGE-TEXT
           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 program is to provide examples for loading and processing tables within a COBOL program.

This document may be used as a tutorial for new programmers or as a quick reference for experienced programmers. In the world of programming there are many ways to solve a problem. This document and the links to other documents are intended to provide a choice of alternatives.

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

Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Enterprises. Once the fee is received by SimoTime the latest version of the software, documentation or training material 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.

SimoTime Enterprises makes no warranty or representations about the suitability of the software, documentation or learning material for any purpose. It is provided "AS IS" without any expressed 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, documentation or training material.

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

This section includes links to documents with additional information that is beyond the scope and purpose of this document. The first sub-section requires an internet connection, the second sub-section references locally available documents.

Downloads and Links, Internet Access Required
(Next) (Previous) (Table-of-Contents)

The following links will require an internet connect.

A good place to start is The SimoTime Home Page for access to white papers, program examples and product information.

You may download this example from the library of software packages that are available for review and evaluation.

Explore The ASCII and EBCDIC translation tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats.

Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and QSAM files.

Explore The Micro Focus Web Site for more information about products and services available from Micro Focus.

Downloads and Links, Local Access
(Next) (Previous) (Table-of-Contents)

The following links are intended to provide local access on a server or a laptop computer.

Note:  A SimoTime License is required for the items to be made available on a Local Server, Workstation and/or a Laptop.

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

Document Description
binbit01.htm 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.htm 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.htm 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.htm 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.
  Hyperlinks to Sample COBOL Programs that do Table Processing

Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and QSAM files.

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, Suggestions or Feedback
(Next) (Previous) (Table-of-Contents)

This document was created and is maintained by SimoTime Enterprises.

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

We appreciate hearing from you.

Company Overview
(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
Table Processing, Bubble Sort
Copyright © 1987-2012 SimoTime Enterprises  All Rights Reserved
When technology complements business
http://www.simotime.com