Collating Sequence
The EBCDIC & ASCII Environments
  Table of Contents  v-14.03.28 - cblclt01.htm 
  Introduction
  Programming Objectives
  Programming Input and Output
  Sample Printable Character Set
  EBCDIC & ASCII, Side-by-Side Compare
  Programming Requirements
  Programming Overview
  Possibilities & Considerations
  EBCDIC & ASCII Considerations
  The Half-a-Range Check
  IF Logic Failure, Sample & Correction
  Tables & Binary Search
  Sample CMD File
  Run the Demonstration Program
  Sample JCL File
  Run the Demonstration Program
  The Demonstration Program
  The SORT Program
  The File Create Program
  Summary
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Current Server or Internet Access
  Internet Access Required
  Glossary of Terms
  Comments or Feedback
  Company Overview
The SimoTime Home Page

Table of Contents Previous Section Next Section Introduction

The sorting or collating sequence for an EBCDIC environment is not the same as the sorting or collating sequence for an ASCII environment. The hexadecimal values used to represent the character sets that may be printed or displayed are different. When creating reports that are sorted by an alpha-numeric field (with or without special characters) the sequence of the presentation of information will be different. The major difference is the numbers (or digits) are sorted after the alphabet (with lower case being sorted before upper case) for the EBCDIC environment. The numbers (or digits) are sorted before the alphabet (with upper case being sorted before lower case) for the ASCII environment. The special characters will also be sorted differently as shown later in this document. This problem can usually be resolved by explaining the difference to the business users before an application is migrated between the two environments.

A bigger problem is the potential exposure for a failure in the logic of a program because of the differences in the collating sequence. For example the following logic will work fine in an EBCDIC environment but will fail in an ASCII environment.

If BYTE-ONE is less than a SPACE-CHARACTER or Greater than DIGIT-NINE then BYTE-ONE is non-printable.

For more information about the potential for logic failures refer to the Possibilities and Considerations section of this document.

This suite of programs will show the differences between the EBCDIC and ASCII collating sequences. It also provides an example of possible logic failures in COBOL source code. This example is in COBOL but the failure would occur with other languages.

The COBOL programs are written using the VS COBOL II dialect and also work with COBOL for MVS and COBOL/370. A JCL member is provided to run the job as an MVS batch job on an IBM mainframe or as a project with Micro Focus Mainframe Express (MFE) running on a PC with Windows. A Windows Command (.CMD) file is provided to run the job on a PC with Micro Focus Net Express. This program may serve as a tutorial for new programmers and as a reference for experienced programmers. Additional information about data migration or data file conversion s provided in the Downloads and Links to Similar Pages section of this document. Our thanks to Larry Simmons of Micro Focus for providing us with much of the information in this document.


We have made a significant effort to ensure the documents and software technologies are correct and accurate. We reserve the right to make changes without notice at any time. The function delivered in this version is based upon the enhancement requests from a specific group of users. The intent is to provide changes as the need arises and in a timeframe that is dependent upon the availability of resources.

Copyright © 1987-2015
SimoTime Technologies
All Rights Reserved

Table of Contents Previous Section Next Section Programming Objectives

The following is a list of the functions provided in this example.

1 Show the sequencing for EBCDIC and ASCII environments.
2 Show how to create a file for the full, printable character set.
3 Show an example of source code that will produce different results between the EBCDIC and ASCII environments.
4 Show how to run the application on a mainframe using JCL.
5 Show how to run the application on a Windows platform using a .CMD file.
  Topics Included in this Document

Table of Contents Previous Section Next Section Programming Input and Output

A JCL member (CBLCLTJ1.JCL) for the mainframe or a CMD file for the Windows environment (CBLCLTE1.CMD) defines and executes a five step procedure. The first step will delete any files created in a previous run. The second step will create a sequential file consisting of eighty-byte records with the first position containing a printable character. The third step will read the file, test the character in the first position of a record for being a valid printable character and write the results to an output file (Note: this step will work correctly in an EBCDIC environment but fail in an ASCII environment). The fourth step will sort the file (Note: this step will produce different sequencing for an EBCDIC or ASCII environment). The fifth step will read the sorted file, test the first position for a valid printable character and write the results to an output file (Note: this step will work properly in an EBCDIC environment but fail in an ASCII environment. Also, the sequence of the presentation of the data will be different between the two environments).

Table of Contents Previous Section Next Section Sample Printable Character Set

The following is an example of the sequential file that is created (COLLATE1.DAT for EBCDIC and COLLATE1.TXT for ASCII) that shows numbers, the alphabet in upper case, the alphabet in lower case and the special characters.

 0 e=F0 a=30, Digit
 1 e=F1 a=31, Digit
 2 e=F2 a=32, Digit
 3 e=F3 a=33, Digit
 4 e=F4 a=34, Digit
 5 e=F5 a=35, Digit
 6 e=F6 a=36, Digit
 7 e=F7 a=37, Digit
 8 e=F8 a=38, Digit
 9 e=F9 a=39, Digit
 A e=C1 a=41, Upper-Case
 B e=C2 a=42, Upper-Case
 C e=C3 a=43, Upper-Case
 D e=C4 a=44, Upper-Case
 E e=C5 a=45, Upper-Case
 F e=C6 a=46, Upper-Case
 G e=C7 a=47, Upper-Case
 H e=C8 a=48, Upper-Case
 I e=C9 a=49, Upper-Case
 J e=D1 a=4A, Upper-Case
 K e=D2 a=4B, Upper-Case
 L e=D3 a=4C, Upper-Case
 M e=D4 a=4D, Upper-Case
 N e=D5 a=4E, Upper-Case
 O e=D6 a=4F, Upper-Case
 P e=D7 a=50, Upper-Case
 Q e=D8 a=51, Upper-Case
 R e=D9 a=52, Upper-Case
 S e=E2 a=53, Upper-Case
 T e=E3 a=54, Upper-Case
 U e=E4 a=55, Upper-Case
 V e=E5 a=56, Upper-Case
 W e=E6 a=57, Upper-Case
 X e=E7 a=58, Upper-Case
 Y e=E8 a=59, Upper-Case
 Z e=E9 a=5A, Upper-Case
 a e=81 a=61, Lower-Case
 b e=82 a=62, Lower-Case
 c e=83 a=63, Lower-Case
 d e=84 a=64, Lower-Case
 e e=85 a=65, Lower-Case
 f e=86 a=66, Lower-Case
 g e=87 a=67, Lower-Case
 h e=88 a=68, Lower-Case
 i e=89 a=69, Lower-Case
 j e=91 a=6A, Lower-Case
 k e=92 a=6B, Lower-Case
 l e=93 a=6C, Lower-Case
 m e=94 a=6D, Lower-Case
 n e=95 a=6E, Lower-Case
 o e=96 a=6F, Lower-Case
 p e=97 a=70, Lower-Case
 q e=98 a=71, Lower-Case
 r e=99 a=72, Lower-Case
 s e=A2 a=73, Lower-Case
 t e=A3 a=74, Lower-Case
 u e=A4 a=75, Lower-Case
 v e=A5 a=76, Lower-Case
 w e=A6 a=77, Lower-Case
 x e=A7 a=78, Lower-Case
 y e=A8 a=79, Lower-Case
 z e=A9 a=7A, Lower-Case
   e=40 a=20, Space Character
 " e=7F a=22, Double Quote
 ' e=7D a=27, Apostrophe
 ~ e=A1 a=7E, Tilde
 ! e=5A a=21, Exclamation Point
 @ e=7C a=40, At Sign
 # e=7B a=23, Square Symbol
 $ e=5B a=24, Dollar Sign
 % e=6C a=25, Per Cent Sign
 ^ e=B0 a=5E, Carat Symbol
 & e=50 a=26, Ampersand
 * e=5C a=2A, Asterisk
 ( e=4D a=2A, Left Parenthesis
 ) e=5D a=29, Right Parenthesis
 _ e=6D a=5F, Underscore
 + e=4E a=2B, Plus Sign
 { e=C0 a=7B, Left Brace
 } e=D0 a=7D, Right Brace
 | e=4F a=7C, Vertical Bar
 : e=7A a=3A, Colon
 < e=4C a=3C, Less Than
 > e=6E a=3E, Greater Than
 ? e=6F a=3F, Question Mark
 ` e=79 a=60, Back Apostrophe
 - e=60 a=2D, Minus Sign
 = e=7E a=3D, Equal Sign
 [ e=AD a=5B, Left Bracket
 ] e=BD a=5D, Right Bracket
 \ e=E0 a=5C, Back Slash
 ; e=5E a=3B, Semicolon
 , e=6B a=2C, Comma
 . e=4B a=2E, Period Full Stop
 / e=61 a=2F, Forward Slash

The preceding table is then sorted by position one (1) and produces a different sorting sequence for the EBCDIC-encoded and ASCII-encoded environments.

Table of Contents Previous Section Next Section EBCDIC & ASCII, Side-by-Side Compare

The following shows the programming logic that works in an EBCDIC-encoded environment and fails in an ASCII-encoded environment.

      *            The following logic will produce different results
      *            when in an EBCDIC or ASCII environment.
      *            This is because of the difference in the collating
      *            sequences of the two environments.
                   if  COLLATE1-FIRST-BYTE < SPACE
                   or  COLLATE1-FIRST-BYTE > 9
                       move 'NOT Printable'  to COLLATE2-RECORD(16:13)
                   else
                       move 'Printable AOK'  to COLLATE2-RECORD(16:13)
                   end-if
      *            End of example for logic differences

The following shows a side-by-side comparison of the results of the sorting and the programming logic that works in an EBCDIC environment and fails in an ASCII environment.

Sorted Output for EBCDIC Environment Sorted Output for ASCII Environment
Character is   Printable AOK e=40 a=20, Space Character 
Character is . Printable AOK e=4B a=2E, Period Full Stop
Character is < Printable AOK e=4C a=3C, Less Than
Character is ( Printable AOK e=4D a=2A, Left Parenthesis
Character is + Printable AOK e=4E a=2B, Plus Sign
Character is | Printable AOK e=4F a=7C, Vertical Bar
Character is & Printable AOK e=50 a=26, Ampersand
Character is ! Printable AOK e=5A a=21, Exclamation Point 
Character is $ Printable AOK e=5B a=24, Dollar Sign
Character is * Printable AOK e=5C a=2A, Asterisk
Character is ) Printable AOK e=5D a=29, Right Parenthesis 
Character is ; Printable AOK e=5E a=3B, Semicolon
Character is - Printable AOK e=60 a=2D, Minus Sign
Character is / Printable AOK e=61 a=2F, Forward Slash
Character is , Printable AOK e=6B a=2C, Comma
Character is % Printable AOK e=6C a=25, Per Cent Sign
Character is _ Printable AOK e=6D a=5F, Underscore
Character is > Printable AOK e=6E a=3E, Greater Than
Character is ? Printable AOK e=6F a=3F, Question Mark
Character is ` Printable AOK e=79 a=60, Back Apostrophe
Character is : Printable AOK e=7A a=3A, Colon
Character is # Printable AOK e=7B a=23, Square Symbol
Character is @ Printable AOK e=7C a=40, At Sign
Character is ' Printable AOK e=7D a=27, Apostrophe
Character is = Printable AOK e=7E a=3D, Equal Sign
Character is " Printable AOK e=7F a=22, Double Quote
Character is a Printable AOK e=81 a=61, Lower-Case
Character is b Printable AOK e=82 a=62, Lower-Case
Character is c Printable AOK e=83 a=63, Lower-Case
Character is d Printable AOK e=84 a=64, Lower-Case
Character is e Printable AOK e=85 a=65, Lower-Case
Character is f Printable AOK e=86 a=66, Lower-Case
Character is g Printable AOK e=87 a=67, Lower-Case
Character is h Printable AOK e=88 a=68, Lower-Case
Character is i Printable AOK e=89 a=69, Lower-Case
Character is j Printable AOK e=91 a=6A, Lower-Case
Character is k Printable AOK e=92 a=6B, Lower-Case
Character is l Printable AOK e=93 a=6C, Lower-Case
Character is m Printable AOK e=94 a=6D, Lower-Case
Character is n Printable AOK e=95 a=6E, Lower-Case
Character is o Printable AOK e=96 a=6F, Lower-Case
Character is p Printable AOK e=97 a=70, Lower-Case
Character is q Printable AOK e=98 a=71, Lower-Case
Character is r Printable AOK e=99 a=72, Lower-Case
Character is ~ Printable AOK e=A1 a=7E, Tilde
Character is s Printable AOK e=A2 a=73, Lower-Case
Character is t Printable AOK e=A3 a=74, Lower-Case
Character is u Printable AOK e=A4 a=75, Lower-Case
Character is v Printable AOK e=A5 a=76, Lower-Case
Character is w Printable AOK e=A6 a=77, Lower-Case
Character is x Printable AOK e=A7 a=78, Lower-Case
Character is y Printable AOK e=A8 a=79, Lower-Case
Character is z Printable AOK e=A9 a=7A, Lower-Case
Character is ^ Printable AOK e=B0 a=5E, Carat Symbol
Character is [ Printable AOK e=AD a=5B, Left Bracket
Character is ] Printable AOK e=BD a=5D, Right Bracket
Character is { Printable AOK e=C0 a=7B, Left Brace
Character is A Printable AOK e=C1 a=41, Upper-Case
Character is B Printable AOK e=C2 a=42, Upper-Case
Character is C Printable AOK e=C3 a=43, Upper-Case
Character is D Printable AOK e=C4 a=44, Upper-Case
Character is E Printable AOK e=C5 a=45, Upper-Case
Character is F Printable AOK e=C6 a=46, Upper-Case
Character is G Printable AOK e=C7 a=47, Upper-Case
Character is H Printable AOK e=C8 a=48, Upper-Case
Character is I Printable AOK e=C9 a=49, Upper-Case
Character is } Printable AOK e=D0 a=7D, Right Brace
Character is J Printable AOK e=D1 a=4A, Upper-Case
Character is K Printable AOK e=D2 a=4B, Upper-Case
Character is L Printable AOK e=D3 a=4C, Upper-Case
Character is M Printable AOK e=D4 a=4D, Upper-Case
Character is N Printable AOK e=D5 a=4E, Upper-Case
Character is O Printable AOK e=D6 a=4F, Upper-Case
Character is P Printable AOK e=D7 a=50, Upper-Case
Character is Q Printable AOK e=D8 a=51, Upper-Case
Character is R Printable AOK e=D9 a=52, Upper-Case
Character is \ Printable AOK e=E0 a=5C, Back Slash
Character is S Printable AOK e=E2 a=53, Upper-Case
Character is T Printable AOK e=E3 a=54, Upper-Case
Character is U Printable AOK e=E4 a=55, Upper-Case
Character is V Printable AOK e=E5 a=56, Upper-Case
Character is W Printable AOK e=E6 a=57, Upper-Case
Character is X Printable AOK e=E7 a=58, Upper-Case
Character is Y Printable AOK e=E8 a=59, Upper-Case
Character is Z Printable AOK e=E9 a=5A, Upper-Case
Character is 0 Printable AOK e=F0 a=30, Digit
Character is 1 Printable AOK e=F1 a=31, Digit
Character is 2 Printable AOK e=F2 a=32, Digit
Character is 3 Printable AOK e=F3 a=33, Digit
Character is 4 Printable AOK e=F4 a=34, Digit
Character is 5 Printable AOK e=F5 a=35, Digit
Character is 6 Printable AOK e=F6 a=36, Digit
Character is 7 Printable AOK e=F7 a=37, Digit
Character is 8 Printable AOK e=F8 a=38, Digit
Character is 9 Printable AOK e=F9 a=39, Digit
Character is   Printable AOK e=40 a=20, Space Character
Character is ! Printable AOK e=5A a=21, Exclamation Point
Character is " Printable AOK e=7F a=22, Double Quote
Character is # Printable AOK e=7B a=23, Square Symbol
Character is $ Printable AOK e=5B a=24, Dollar Sign
Character is % Printable AOK e=6C a=25, Per Cent Sign
Character is & Printable AOK e=50 a=26, Ampersand
Character is ' Printable AOK e=7D a=27, Apostrophe
Character is ( Printable AOK e=4D a=28, Left Parenthesis
Character is ) Printable AOK e=5D a=29, Right Parenthesis
Character is * Printable AOK e=5C a=2A, Asterisk
Character is + Printable AOK e=4E a=2B, Plus Sign
Character is , Printable AOK e=6B a=2C, Comma
Character is - Printable AOK e=60 a=2D, Minus Sign
Character is . Printable AOK e=4B a=2E, Period Full Stop
Character is / Printable AOK e=61 a=2F, Forward Slash
Character is 0 Printable AOK e=F0 a=30, Digit
Character is 1 Printable AOK e=F1 a=31, Digit
Character is 2 Printable AOK e=F2 a=32, Digit
Character is 3 Printable AOK e=F3 a=33, Digit
Character is 4 Printable AOK e=F4 a=34, Digit
Character is 5 Printable AOK e=F5 a=35, Digit
Character is 6 Printable AOK e=F6 a=36, Digit
Character is 7 Printable AOK e=F7 a=37, Digit
Character is 8 Printable AOK e=F8 a=38, Digit
Character is 9 Printable AOK e=F9 a=39, Digit
Character is : NOT Printable e=7A a=3A, Colon
Character is ; NOT Printable e=5E a=3B, Semicolon
Character is < NOT Printable e=4C a=3C, Less Than
Character is = NOT Printable e=7E a=3D, Equal Sign
Character is > NOT Printable e=6E a=3E, Greater Than
Character is ? NOT Printable e=6F a=3F, Question Mark
Character is @ NOT Printable e=7C a=40, At Sign
Character is A NOT Printable e=C1 a=41, Upper-Case
Character is B NOT Printable e=C2 a=42, Upper-Case
Character is C NOT Printable e=C3 a=43, Upper-Case
Character is D NOT Printable e=C4 a=44, Upper-Case
Character is E NOT Printable e=C5 a=45, Upper-Case
Character is F NOT Printable e=C6 a=46, Upper-Case
Character is G NOT Printable e=C7 a=47, Upper-Case
Character is H NOT Printable e=C8 a=48, Upper-Case
Character is I NOT Printable e=C9 a=49, Upper-Case
Character is J NOT Printable e=D1 a=4A, Upper-Case
Character is K NOT Printable e=D2 a=4B, Upper-Case
Character is L NOT Printable e=D3 a=4C, Upper-Case
Character is M NOT Printable e=D4 a=4D, Upper-Case
Character is N NOT Printable e=D5 a=4E, Upper-Case
Character is O NOT Printable e=D6 a=4F, Upper-Case
Character is P NOT Printable e=D7 a=50, Upper-Case
Character is Q NOT Printable e=D8 a=51, Upper-Case
Character is R NOT Printable e=D9 a=52, Upper-Case
Character is S NOT Printable e=E2 a=53, Upper-Case
Character is T NOT Printable e=E3 a=54, Upper-Case
Character is U NOT Printable e=E4 a=55, Upper-Case
Character is V NOT Printable e=E5 a=56, Upper-Case
Character is W NOT Printable e=E6 a=57, Upper-Case
Character is X NOT Printable e=E7 a=58, Upper-Case
Character is Y NOT Printable e=E8 a=59, Upper-Case
Character is Z NOT Printable e=E9 a=5A, Upper-Case
Character is [ NOT Printable e=AD a=5B, Left Bracket
Character is \ NOT Printable e=E0 a=5C, Back Slash
Character is ] NOT Printable e=BD a=5D, Right Bracket
Character is ^ NOT Printable e=B0 a=5E, Carat Symbol
Character is _ NOT Printable e=6D a=5F, Underscore
Character is ` NOT Printable e=79 a=60, Back Apostrophe
Character is a NOT Printable e=81 a=61, Lower-Case
Character is b NOT Printable e=82 a=62, Lower-Case
Character is c NOT Printable e=83 a=63, Lower-Case
Character is d NOT Printable e=84 a=64, Lower-Case
Character is e NOT Printable e=85 a=65, Lower-Case
Character is f NOT Printable e=86 a=66, Lower-Case
Character is g NOT Printable e=87 a=67, Lower-Case
Character is h NOT Printable e=88 a=68, Lower-Case
Character is i NOT Printable e=89 a=69, Lower-Case
Character is j NOT Printable e=91 a=6A, Lower-Case
Character is k NOT Printable e=92 a=6B, Lower-Case
Character is l NOT Printable e=93 a=6C, Lower-Case
Character is m NOT Printable e=94 a=6D, Lower-Case
Character is n NOT Printable e=95 a=6E, Lower-Case
Character is o NOT Printable e=96 a=6F, Lower-Case
Character is p NOT Printable e=97 a=70, Lower-Case
Character is q NOT Printable e=98 a=71, Lower-Case
Character is r NOT Printable e=99 a=72, Lower-Case
Character is s NOT Printable e=A2 a=73, Lower-Case
Character is t NOT Printable e=A3 a=74, Lower-Case
Character is u NOT Printable e=A4 a=75, Lower-Case
Character is v NOT Printable e=A5 a=76, Lower-Case
Character is w NOT Printable e=A6 a=77, Lower-Case
Character is x NOT Printable e=A7 a=78, Lower-Case
Character is y NOT Printable e=A8 a=79, Lower-Case
Character is z NOT Printable e=A9 a=7A, Lower-Case
Character is { NOT Printable e=C0 a=7B, Left Brace
Character is | NOT Printable e=4F a=7C, Vertical Bar
Character is } NOT Printable e=D0 a=7D, Right Brace
Character is ~ NOT Printable e=A1 a=7E, Tilde

For more informationj about the potential for logic failures refer to the Possibilities and Considerations section of this document.

Table of Contents Previous Section Next Section Programming Requirements

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

1 Executes on Windows/XP, Windows/7 and Windows Server using Micro Focus Net Express and the CMD file provided.
2 May be ported to run on the Linux and UNIX platforms supported by Micro Focus COBOL.
3 Executes on a mainframe with MVS or Windows/XP, Windows/7 or Windows Server using Micro Focus Mainframe Express and the JCL file provided.
  Possible Platforms for Program Execution

Table of Contents Previous Section Next Section Programming Overview

The following diagram is an overview of how the demonstration program fits into the example.

             
Entry Point
ZOS
Entry Point
Windows
   
   
CBLCLTJ1
jcl
CBLCLTE1
cmd
Submit the Job
   
   
IEFBR14
Utility
IF Exist
statement
Delete previously created output files
   
   
 
 
   
   
 
 
   
   
CBLCLTC2
cbl
 
 
COLLATE1
rseq
Job Step is MAKEFILE, create a file containing the printable character set (COLLATE1).
   
COLLATE1
rseq
 
 
CBLCLTC1
cbl
 
 
COLLATE2
rseq
Read the input file (COLLATE1), and write the results to the output file (COLLATE2).
   
COLLATE1
rseq
 
 
CBLS80C1
cbl
 
 
COLLATE3
rseq
Sort the file. This step produces different sequencing for the EBCDIC and ASCII environments.
   
COLLATE3
rseq
 
 
CBLS80C1
cbl
 
 
COLLATE4
rseq
This step works on the EBCDIC environment and fails in the ASCII environment.
   
EOJ
End-Of-Job
 
Overview of Collating Sequences for EBCDIC and ASCII

Color Associations: The  light-green  boxes are unique to the Mainframe and Micro Focus Enterprise Server/Studio (or Micro Focus Mainframe Express). The  light-red  boxes are unique to a Windows System and Micro Focus technologies. The  light-yellow  boxes are decision points or program transitions in the processing logic. The  light-blue  boxes identify the input/output data structures such as Documents, Spreadsheets, Data Files, VSAM Data Sets or Relational Tables. The  light-gray  boxes identify a system function or information item.

Table of Contents Previous Section Next Section Possibilities & Considerations

This section describes some of the possible problems that may occur when moving from an EBCDIC-encoded environment to an ASCII environment. Some coding changes may be required to get an application to produce the same results in both environments (reports and other output will most likely be in a different sequence when the fields that deternine the sort sequence is alpha-numeric).

Table of Contents Previous Section Next Section EBCDIC & ASCII Considerations

The section describe and demonstarte some of the EBCDIC to ASCII conversion considerations by identifying some of the program changes that will be required.

Table of Contents Previous Section Next Section The Half-a-Range Check

The section will list of some of the items to look for during an EBCDIC to ASCII conversion. The list uses the term "half-a-range" check and is used to describe the following comparison logic.

1 a GT or GE without a complimentary LT or LE
2 a LT or LE without a complimentary GT or GE
  Comparison Logic with Half-a-Range Check

The following will require extra time in the conversion process.

1. Logic that processes alpha-numeric values and does half-a-range check using the “IF” or “EVALUATE” capabilities of COBOL may work in an EBCDIC-encoded environment and fail in an ASCII-encoded environment.
2. The INCLUDE or OMIT statements in the SORT utility program that do half-a-range check for alpha-numeric values may work in an EBCDIC-encoded environment and fail in an ASCII-encoded environment.
3. Tables that are hard-coded in COBOL and are accessed using a binary search (i.e. SEARCH ALL) and the search argument is alpha-numeric may work in an EBCDIC-encoded environment and fail in an ASCII-encoded environment.
4. Items that are alpha-numeric and use the technique of comparing for 999999 to indicate end of table or last record in a file will work in EBCDIC-encoded environments but fail in ASCII-encoded environments.
5. When working with international character sets (i.e. accented characters such as the umlat and tilde) be aware the upper case “Y” with the umlat is x’FF’ in EBCDIC and this will get converted to x’9F’ which is the ASCII equivalent. This could cause a conflict if the actual value is used as a high-value and should not be converted.
6. The use of hexadecimal coding techniques (i.e. x’C1’). This is sometimes used in COBOL and is required with the ALTSEQ statement in the SORT utility.
Note: The ALTSEQ is frequently used on the mainframe to do a case-insensitive sort.
7. During the data file transfer process if MFA is not used (i.e. FTP is used) the following will require extra consideration.
 
7.1.  A VSAM KSDS has an alpha-numeric key and IDCAMS is used to REPRO the file to a sequential file.
7.2.  The sequential file is downloaded using FTP.
7.3.  The sequential file is read, the data is converted from EBCDIC to ASCII, a record is written to a new Key-Sequenced file. Since the key is alpha-numeric the sequencing will be different in ASCII and an ordered (or sequential) load of the new key-sequenced file will fail with a sequencing (or collating) error. There are two possible solutions to this problem.
 
7.3.1.  Do an unordered load of the new key-sequenced file.
7.3.2.  Convert the downloaded sequential file to ASCII and then sort the file. Use the sorted, ASCII-encoded, sequential file to do an ordered load of the new key-sequenced file.
8. Data that is sequenced by an alpha-numeric key or sorted based on the content of an alpha-numeric field may be presented in a different sequence.
9. Data that is sequenced using an alphabetic upper and lower case key or sorted based on the content of an alphabetic upper and lower case field may be presented in a different sequence.
Note: it is possible to do a case insensitve sort using the ALTSEQ statement of the sort program on the mainframe or with Micro Focus. Refer to the sample sort program provided on the SimoTime Web site.
10. The technique of comparing the units position of signed, zoned-decimal numbers for an "A-I" for positive values, a "J-R" for negative values and the right and left curly brace for zero that works in an EBCDIC environment may fail in an ASCII environment.
Note: Signed, zoned-decimal format may present some challenges depending on the coding techniques to prepare for printing or exporting. Refer to the zoned-decimal numeric format provided on the SimoTime Web site.

The preceding is a quick summary of some of the items that are encountered when changing from an EBCDIC-encoded environment to an ASCII encoded environment.

Doing this level of conversion will require the standard unit testing, application testing and system testing before deploying to a production environment. It is important to note that when doing data file compares to validate the results between a Mainframe (EBCDIC) process and a Window, Micro Focus (ASCII) process extra consideration will be required for both the differences in the encoding formats and collating sequences.

Table of Contents Previous Section Next Section IF Logic Failure, Sample & Correction

Think about this senario. A customer master file contains a twelve (12) byte key. If the first byte of the key is a number then it is an indivudual account. If the first byte of the key is a letter then it is a commercial account. If a program does a test as follows then the logic will work in an EBCDIC-encoded environment but fail in an ASCII-encoded environment.

If  CUSTOMER-KEY(1:1) is equal to or greater than 0
    ACCOUNT-TYPE = INDIVIDUAL
else
    ACCOUNT-TYPE = COMERCIAL
end-if

For the ASCII-encoded environment the preceding code example would conclude that all the accounts are individual accounts. The code would need to be changed to the following.

If  CUSTOMER-KEY(1:1) is equal to or greater than 0
and CUSTOMER-KEY(1:1) is equal to or less than 9
    ACCOUNT-TYPE = INDIVIDUAL
else
    ACCOUNT-TYPE = COMERCIAL
end-if

Note: The preceding coding example with the high-lighted change would work in both the EBCDIC-encoded and ASCII-encoded environments.

Table of Contents Previous Section Next Section Tables & Binary Search

Think about the following senario. A sequential file contains records that will be loaded into a table. The records are in sequence based on the content of an alpha-numeric field. The records in the file are used to load a table in a COBOL (or other language) program. The table is then accessed using a binary search routine. On the new platform we are now working in an ASCII-encoded environment. The original file was EBCDIC-encoded and in sequence by the EBCDIC collating sequence. If we simple convert the file to ASCII-encoded format it will still be in sequence by EBCDIC (or out of sequence in the ASCII-encoded environment). This will cause the binary search to fail. The file must be sorted after the EBCDIC to ASCII conversion (especially since the information in the records is aplha-numeric).

Note: Remember, a SEARCH ALL of a table in COBOL does a binary search and will most likely fail when accessing an ASCII-encoded table that is in EBCDIC collating sequence and contains alpha-numeric data. A SEARCH does a scan of the table starting at the first element and will work but will be much slower for large tables.

Table of Contents Previous Section Next Section Sample CMD File

This sample suite of programs has one CMD member that executes multiple job steps to sort and present data in the ASCII collating sequence. A subsequent step will then test the characters to determine if they are valid, printable characters. The CMD member will execute a COBOL program that will produce correct results in an EBCDIC environment but will fail in the ASCII environment.

Table of Contents Previous Section Next Section Run the Demonstration Program

The following (CBLCLTE1.cmd) is the CMD required to run the demonstration program on a Personal Computer with Micro Focus Net Express or Studio/Server.

@echo OFF
rem  * *******************************************************************
rem  *               CBLCLTE1.cmd - a Windows Command File               *
rem  *         This program is provided by SimoTime Technologies         *
rem  *           (C) Copyright 1987-2015 All Rights Reserved             *
rem  *             Web Site URL:   http://www.simotime.com               *
rem  *                   e-mail:   helpdesk@simotime.com                 *
rem  * *******************************************************************
rem *
rem * Text   - Create, Sort and Process a Sequential file using
rem *          a COBOL program.
rem * Author - SimoTime Technologies
rem * Date   - January 24, 1996
rem *
rem * The 1st step (QSAMDELT) will delete any previously created file.
rem *
rem * The 2nd step (MAKEFILE) will create a new file. The first
rem * position in each record will contain a printable character.
rem *
rem * The 3rd step will show a program that works properly in an
rem * EBCDIC environment but fails in an ASCII environment.
rem *
rem * The 4th step will SORT the file. This step will produce different
rem * results when executing on an EBCDIC or ASCII environment.
rem *
rem * The 5th step shows the sequencing for the two environments and
rem * will worked properly in an EBCDIC environment but fail in an
rem * ASCII environment.
rem *
rem * This set of programs will run on a mainframe under MVS or on a
rem * Personal Computer with Windows and Micro Focus Mainframe Express.
rem *
rem * *******************************************************************
rem * Step 1 Delete any previously created file...
rem *
     set CmdName=CBLCLTE1
     call ..\Env1BASE %CmdName%
     set JobStatus=0000
     if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
rem  *
     call SimoNOTE "*******************************************************%CmdName%"
     call SimoNOTE "Starting CmdName %CmdName%, V04.08.13, User is %USERNAME%"
     set SYSOUT=%BaseLib1%\LOGS\SYSOUT_%CmdName%.TXT
:DeleteQSAM
     call SimoNOTE "Identify JobStep DeleteQSAM"
     set COLLATE1=%BaseLib1%\DATA\Asc1\COLLATE1.DAT
     set COLLATE2=%BaseLib1%\DATA\Asc1\COLLATE2.DAT
     set COLLATE3=%BaseLib1%\DATA\Asc1\COLLATE3.DAT
     set COLLATE4=%BaseLib1%\DATA\Asc1\COLLATE4.DAT
     if exist %COLLATE1% del %COLLATE1%
     if exist %COLLATE2% del %COLLATE2%
     if exist %COLLATE3% del %COLLATE3%
     if exist %COLLATE4% del %COLLATE4%
rem *
rem * *******************************************************************
rem * Step 2 Create and populate a new QSAM file...
rem *
:MakeFile
     call SimoNOTE "Identify JobStep MakeFile"
     set COLLATE1=%BaseLib1%\DATA\Asc1\COLLATE1.DAT
     set COLLATE2=%BaseLib1%\DATA\Asc1\COLLATE2.DAT
     run CBLCLTC2
     if ERRORLEVEL = 1 set JobStatus=0020
     if not "%JobStatus%" == "0000" goto :EojNok
rem *
rem * *******************************************************************
rem * Step 3 Test for printable character, create a new output file.
rem *        the program used in this step will perform correctly
rem *        in an EBCDIC environment but fail in an ASCII environment
rem *
:Test0001
     call SimoNOTE "Identify JobStep Test0001"
     set COLLATE1=%BaseLib1%\DATA\Asc1\COLLATE1.DAT
     set COLLATE2=%BaseLib1%\DATA\Asc1\COLLATE2.DAT
     run CBLCLTC1
     if ERRORLEVEL = 1 set JobStatus=0030
     if not "%JobStatus%" == "0000" goto :EojNok
rem * *******************************************************************
rem * Step 4 Sort by character set using a cobol program. This step will
rem *        produce different sequencing results when running in an
rem *        EBCDIC or ASCII environment.
rem *
:SortFile
     call SimoNOTE "Identify JobStep SortFile"
     set SORTGET1=%BaseLib1%\DATA\Asc1\COLLATE1.DAT
     set SORTPUT1=%BaseLib1%\DATA\Asc1\COLLATE3.DAT
rem  set MF_ALIAS=MFJSORT SORT
     run CBLS80C1
     if ERRORLEVEL = 1 set JobStatus=0040
     if not "%JobStatus%" == "0000" goto :EojNok
rem *
rem * *******************************************************************
rem * Step 5 Test for printable character, create a new output file.
rem *        the program used in this step will perform correctly
rem *        in an EBCDIC environment but fail in an ASCII environment.
rem *        This step uses the sorted file and shows the sequencing
rem *        that will be different when running in an EBCDIC or ASCII
rem *        environment.
rem *
:Test0002
     call SimoNOTE "Identify JobStep Test0002"
     set COLLATE1=%BaseLib1%\DATA\Asc1\COLLATE3.DAT
     set COLLATE2=%BaseLib1%\DATA\Asc1\COLLATE4.DAT
     run CBLCLTC1
     if ERRORLEVEL = 1 set JobStatus=0050
     if not "%JobStatus%" == "0000" goto :EojNok
     goto :EojAok
rem  *
:EojNok
     call SimoNOTE "ABENDING CmdName %CmdName%, JobStatus %JobStatus%"
     pause
     goto :End
:EojAok
     call SimoNOTE "Finished CmdName %CmdName%, JobStatus %JobStatus%"
:End
     call SimoNOTE "Conclude SysLog is %SYSLOG%"
     if not "%1" == "nopause" pause

Table of Contents Previous Section Next Section Sample JCL File

This sample suite of programs has one JCL member that executes multiple job steps to sort and present data in the EBCDIC collating sequence. A subsequent step will then test the characters to determine if they are valid, printable characters. The JCL member will execute a COBOL program that will produce correct results in an EBCDIC environment but will fail in the ASCII environment.

Table of Contents Previous Section Next Section Run the Demonstration Program

The following (CBLCLTJ1.jcl) is the JCL required to run the demonstration program on the mainframe or with Micro Focus Mainframe Express.

//CBLCLTJ1 JOB SIMOTIME,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1
//* *******************************************************************
//*       CBLCLTJ1.JCL - a JCL Member for Batch Job Processing        *
//*       This JCL Member is provided by SimoTime Technologies        *
//*           (C) Copyright 1987-2015 All Rights Reserved             *
//*             Web Site URL:   http://www.simotime.com               *
//*                   e-mail:   helpdesk@simotime.com                 *
//* *******************************************************************
//*
//* Text   - Create, Sort and Process a Sequential file
//*          using a COBOL program.
//* Author - SimoTime Technologies
//* Date   - January 24, 1991
//*
//* The 1st step (QSAMDELT) will delete any previously created file.
//*
//* The 2nd step (MAKEFILE) will create a new file. The first
//* position in each record will contain a printable character.
//*
//* The 3rd step will show a program that works properly in an
//* EBCDIC environment but fails in an ASCII environment.
//*
//* The 4th step will SORT the file. This step will produce different
//* results when executing within an EBCDIC or ASCII environment.
//*
//* The 5th step shows the sequencing for the two environments and
//* will worked properly in an EBCDIC environment but fail in an
//* ASCII environment.
//*
//* This set of programs may be compiled and executed on a Mainframe
//* System with ZOS or a Linux, UNIX or Windows System with Micro Focus
//* Enterprise Server.
//*
//* *******************************************************************
//* Step 1 Delete any previously created file...
//*
//JOBSETUP EXEC PGM=IEFBR14
//COLLATE1 DD  DSN=SIMOTIME.DATA.COLLATE1,DISP=(MOD,DELETE,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS)
//COLLATE2 DD  DSN=SIMOTIME.DATA.COLLATE2,DISP=(MOD,DELETE,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=8000,DSORG=PS)
//COLLATE3 DD  DSN=SIMOTIME.DATA.COLLATE3,DISP=(MOD,DELETE,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=8000,DSORG=PS)
//COLLATE4  DD  DSN=SIMOTIME.DATA.COLLATE4,DISP=(MOD,DELETE,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=8000,DSORG=PS)
//*
//* *******************************************************************
//* Step 2 Create and populate a new QSAM file...
//*
//MAKEFILE EXEC PGM=CBLCLTC2
//COLLATE1 DD  DSN=SIMOTIME.DATA.COLLATE1,
//             DISP=(NEW,CATLG,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS)
//*
//* *******************************************************************
//* Step 3 Test for printable character, create a new output file.
//*        the program used in this step will perform correctly
//*        in an EBCDIC environment but fail in an ASCII environment
//*
//TEST0001 EXEC PGM=CBLCLTC1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//COLLATE1 DD  DSN=SIMOTIME.DATA.COLLATE1,DISP=SHR
//COLLATE2 DD  DSN=SIMOTIME.DATA.COLLATE2,
//             DISP=(NEW,CATLG,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS)
//SYSOUT   DD  SYSOUT=*
//* *******************************************************************
//* Step 4 Sort by character set using a cobol program. This step will
//*        produce different sequencing results when running in an
//*        EBCDIC or ASCII environment.
//*        The major difference is the numbers are sorted after the
//*        alphabetic characters for the EBCDIC environment and the
//*        numbers are sorted before the alhpabetic characters for
//*        the ASCII environment.
//*
//SORTFILE EXEC PGM=CBLS80C1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//SORTGET1 DD  DSN=SIMOTIME.DATA.COLLATE1,DISP=SHR
//SORTPUT1 DD  DSN=SIMOTIME.DATA.COLLATE3,DISP=(NEW,CATLG,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=8000,DSORG=PS)
//SYSOUT   DD  SYSOUT=*
//*
//* *******************************************************************
//* Step 5 Test for printable character, create a new output file.
//*        the program used in this step will perform correctly
//*        in an EBCDIC environment but fail in an ASCII environment.
//*        This step uses the sorted file and shows the sequencing
//*        that will be different when running in an EBCDIC or ASCII
//*        environment.
//*
//TEST0002 EXEC PGM=CBLCLTC1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//COLLATE1 DD  DSN=SIMOTIME.DATA.COLLATE3,DISP=SHR
//COLLATE2 DD  DSN=SIMOTIME.DATA.COLLATE4,
//             DISP=(NEW,CATLG,DELETE),
//             STORCLAS=MFI,
//             SPACE=(TRK,5),
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS)
//SYSOUT   DD  SYSOUT=*
//

Table of Contents Previous Section Next Section The Demonstration Program

The following (CBLCLTC1.cbl) is the source code listing for the demonstration program that shows the type of programming logic that will work in an EBCDIC environment and fail in an ASCII environment.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLCLTC1.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      * Copyright (C) 1987-2015 SimoTime Technologies.                *
      *                                                               *
      * 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 Technologies. 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           *
      * Technologies.                                                 *
      *                                                               *
      * 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           *
      * Technologies.                                                 *
      *                                                               *
      * SimoTime Technologies 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       *
      * Technologies 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 Technologies                                         *
      * 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 Technologies, *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      * Source Member: CBLCLTC1.CBL
      * Copy Files:    PASSRA12.CPY
      * Calls to:      SIMORA12
      *****************************************************************
      *
      *                   ************
      *                   * CBLCLTJ1 *
      *                   ********jcl*
      *                        *
      *                   ************
      *                   * IEFBR14  *
      *                   ********utl*
      *                        *
      *  ************     ************     ************
      *  * COLLATE1 *-----* CBLCLTC1 *-----* COLLATE2 *
      *  ********dat*     ********cbl*     ********dat*
      *                        *
      *                        *
      *                   ************
      *                   *   EOJ    *
      *                   ************
      *
      * The purpose of this program is to shaow an example of code
      * that will execute correctly in an EBCDIC environment but
      * fail in an ASCII environment.
      *
      *****************************************************************

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT COLLATE1-FILE  ASSIGN to     COLLATE1
                  ORGANIZATION is SEQUENTIAL
                  ACCESS MODE  is SEQUENTIAL
                  FILE STATUS  is COLLATE1-STATUS.
           SELECT COLLATE2-FILE  ASSIGN to     COLLATE2
                  ORGANIZATION is SEQUENTIAL
                  ACCESS MODE  is SEQUENTIAL
                  FILE STATUS  is COLLATE2-STATUS.

      *****************************************************************
       DATA DIVISION.
       FILE SECTION.
       FD  COLLATE1-FILE
           BLOCK CONTAINS 00800 CHARACTERS
           DATA RECORD    is COLLATE1-RECORD
           .
       01  COLLATE1-RECORD.
           05  COLLATE1-DATA-01.
               10  COLLATE1-FIRST-BYTE pic X.
               10  COLLATE1-2-80       pic X(79).

       FD  COLLATE2-FILE
           BLOCK CONTAINS 00800 CHARACTERS
           DATA RECORD    is COLLATE2-RECORD
           .
       01  COLLATE2-RECORD.
           05  COLLATE2-DATA-01  pic X(00080).

       WORKING-STORAGE SECTION.
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLCLTC1 '.
           05  T2 pic X(34) value 'Test for ASCII/EBCDIC collating   '.
           05  T3 pic X(10) value ' v07.07.30'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLCLTC1 '.
           05  C2 pic X(20) value 'Copyright 1987-2015 '.
           05  C3 pic X(28) value '   SimoTime Technologies    '.
           05  C4 pic X(20) value ' All Rights Reserved'.

       01  SIM-THANKS-01.
           05  C1 pic X(11) value '* CBLCLTC1 '.
           05  C2 pic X(32) value 'Thank you for using this program'.
           05  C3 pic X(32) value ' provided from SimoTime Technolo'.
           05  C4 pic X(04) value 'gies'.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* CBLCLTC1 '.
           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  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* CBLCLTC1 '.
           05  MESSAGE-TEXT.
               10  MESSAGE-TEXT-1  pic X(68)   value SPACES.
               10  MESSAGE-TEXT-2  pic X(188)  value SPACES.

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

       01  COLLATE2-STATUS.
           05  COLLATE2-STATUS-L     pic X.
           05  COLLATE2-STATUS-R     pic X.
       01  COLLATE2-EOF              pic X       value 'N'.
       01  COLLATE2-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  APPL-RESULT             pic S9(9)   comp.
           88  APPL-AOK            value 0.
           88  APPL-EOF            value 16.

       01  ONE-BYTE                pic X.

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

      *****************************************************************
       PROCEDURE DIVISION.
           perform Z-POST-COPYRIGHT
           perform COLLATE1-OPEN
           perform COLLATE2-OPEN

           perform until COLLATE1-STATUS not = '00'
               perform COLLATE1-READ
               if  COLLATE1-STATUS = '00'
                   add 1 to COLLATE1-LOC
                   move SPACES to COLLATE2-RECORD
                   move 'Character is ' to COLLATE2-RECORD
                   move COLLATE1-FIRST-BYTE to COLLATE2-RECORD(14:1)

      *            The following logic will produce different results
      *            when in an EBCDIC-encoded or ASCII-encoded
      *            environment. This is because of the difference in
      *            the collating sequences of the two environments.
                   if  COLLATE1-FIRST-BYTE < SPACE
                   or  COLLATE1-FIRST-BYTE > 9
                       move 'NOT Printable'  to COLLATE2-RECORD(16:13)
                   else
                       move 'Printable AOK'  to COLLATE2-RECORD(16:13)
                   end-if
                   move COLLATE1-2-80(1:40) to COLLATE2-RECORD(29:40)
                   if  COLLATE2-RECORD not = SPACES
                       move COLLATE2-RECORD to MESSAGE-TEXT
                       perform Z-DISPLAY-CONSOLE-MESSAGE
                       perform COLLATE2-WRITE
                   end-if
      *            End of example for logic differences

               end-if
           end-perform

           move COLLATE1-TOTAL to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE

           if  COLLATE1-EOF = 'Y'
               move 'is Finished...' to MESSAGE-TEXT
           else
               move 'is ABENDING...' to MESSAGE-TEXT
           end-if
           perform Z-DISPLAY-CONSOLE-MESSAGE

           perform COLLATE2-CLOSE
           perform COLLATE1-CLOSE
           perform Z-THANK-YOU.
           GOBACK.

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

      *****************************************************************
      * I/O ROUTINES FOR COLLATE2...                                  *
      *****************************************************************
       COLLATE2-WRITE.
           if  COLLATE2-OPEN-FLAG = 'C'
               perform COLLATE2-OPEN
           end-if
           write COLLATE2-RECORD
           if  COLLATE2-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  COLLATE2-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 'COLLATE2-Failure-WRITE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move COLLATE2-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       COLLATE2-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open output COLLATE2-FILE
           if  COLLATE2-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to COLLATE2-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'COLLATE2-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move COLLATE2-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       COLLATE2-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close COLLATE2-FILE
           if  COLLATE2-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'C' to COLLATE2-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'COLLATE2-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move COLLATE2-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)
           else
               display MESSAGE-BUFFER
           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 '* CBLCLTC1 File-Status-' IO-STAT1 '/'
                       TWO-BYTES-BINARY upon console
           else
               display '* CBLCLTC1 File-Status-' IO-STATUS
           end-if
           exit.

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

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

Table of Contents Previous Section Next Section The SORT Program

The following (CBLS80C1.cbl) is the source code listing for the sorting program. This program will produce a different sorting sequence for the EBCDIC and ASCII environments.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLS80C1.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      * Copyright (C) 1987-2015 SimoTime Technologies.                *
      *                                                               *
      * 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 Technologies. 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           *
      * Technologies.                                                 *
      *                                                               *
      * 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           *
      * Technologies.                                                 *
      *                                                               *
      * SimoTime Technologies 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       *
      * Technologies 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 Technologies                                         *
      * 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 Technologies, *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      *****************************************************************
      *
      *****************************************************************
      * Source Member: CBLS80C1.CBL
      *****************************************************************
      * CBLS80C1 - Sort a File.
      *
      * CALLING PROTOCOL
      * ----------------
      * Use standard procedure to RUN or ANIMATE.
      *
      * DESCRIPTION
      * -----------
      * This program will sort a file by Postal Code sequence.
      *
      *  ************     ************     ************
      *  * SORTGET1 *-----* CBLS80C1 *-----* SORTPUT1 *
      *  ************     ********cbl*     ******dsply*
      *                        *
      *                        *
      *                   ************
      *                   *   EOJ    *
      *                   ************
      *
      *****************************************************************
      * MAINTENANCE
      * -----------
      * 1989/02/27 Simmons, Created program.
      * 1997/03/17 Simmons, Updated for OPEN to test existance of
      *                     the input file.
      *
      *****************************************************************
      *
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT SORT-WORK   ASSIGN       TO SORTWORK.
           SELECT SORT-INPUT  ASSIGN       TO SORTGET1
                              ORGANIZATION IS SEQUENTIAL
                              FILE STATUS  IS SORT-INPUT-STATUS.
           SELECT SORT-OUTPUT ASSIGN       TO SORTPUT1
                              ORGANIZATION IS SEQUENTIAL.

      *****************************************************************
       DATA DIVISION.
       FILE SECTION.
       SD  SORT-WORK.
       01  SORT-WORK-RECORD.
           05  COLLATE-CHARACTER       pic X.
           05  FILLER                  pic X.
           05  CHARACTER-DESCRIPTION   pic X(78).
       FD  SORT-INPUT.
       01  SORT-INPUT-RECORD.
           05  COLLATE-CHARACTER       pic X.
           05  FILLER                  pic X.
           05  CHARACTER-DESCRIPTION   pic X(78).
       FD  SORT-OUTPUT.
       01  SORT-OUTPUT-RECORD.
           05  COLLATE-CHARACTER       pic X.
           05  FILLER                  pic X.
           05  CHARACTER-DESCRIPTION   pic X(78).

      *****************************************************************
       WORKING-STORAGE SECTION.
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLS80C1 '.
           05  T2 pic X(34) value 'Sort a File with 80-Byte Records  '.
           05  T3 pic X(10) value ' v07.07.30'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLS80C1 '.
           05  C2 pic X(20) value 'Copyright 1987-2015 '.
           05  C3 pic X(28) value '   SimoTime Technologies    '.
           05  C4 pic X(20) value ' All Rights Reserved'.

       01  SORT-INPUT-STATUS.
           05 SORT-INPUT-STATUS-L  pic X.
           05 SORT-INPUT-STATUS-R  pic X.

      *****************************************************************
      * The following buffers are used to create a four-byte numeric  *
      * file status code that may be displayed.                       *
      *****************************************************************
       01  IO-STATUS.
           05  IO-STAT1            pic X.
           05  IO-STAT2            pic X.
       01  TWO-BYTES-BINARY        pic 9(4) BINARY.
       01  TWO-BYTES-ALPHA         redefines TWO-BYTES-BINARY.
           05  TWO-BYTES-LEFT      pic X.
           05  TWO-BYTES-RIGHT     pic X.
       01  IO-STATUS-04.
           05  IO-STATUS-0401      pic 9   value 0.
           05  IO-STATUS-0403      pic 999 value 0.

      *****************************************************************
      *    Buffer used for posting messages to the console.
      *****************************************************************
       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* CBLS80C1 '.
           05  MESSAGE-TEXT.
               10  MESSAGE-TEXT-1  pic X(68)   value SPACES.
               10  MESSAGE-TEXT-2  pic X(188)  value SPACES.

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

       01  END-OF-FILE             pic X(3)    value 'NO '.

      *****************************************************************
       PROCEDURE DIVISION.
       MAINLINE.
           perform Z-POST-COPYRIGHT
           perform CHECK-SORTIN-FILE-EXIST
           perform SORT-THE-FILE
           GOBACK.

      *****************************************************************
       CHECK-SORTIN-FILE-EXIST.
           open input SORT-INPUT.
           if  SORT-INPUT-STATUS = '00'
               close SORT-INPUT
               move 'Sort-Input-File-Exist...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
           else
               move 'SORT-INPUT-FAILURE-OPEN-!!!' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move SORT-INPUT-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.

      *****************************************************************
       SORT-THE-FILE.
           SORT SORT-WORK
           on ascending COLLATE-CHARACTER in SORT-WORK-RECORD
                  using SORT-INPUT
                 giving SORT-OUTPUT
           exit.

      *****************************************************************
      * The following Z-Routines perform administrative functions
      * for this program.
      *****************************************************************
       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 16 to ZERO giving RETURN-CODE
           GOBACK.
      *    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'
               move IO-STAT1 to IO-STATUS-04(1:1)
               subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
               move IO-STAT2 to TWO-BYTES-RIGHT
               add TWO-BYTES-BINARY to ZERO giving IO-STATUS-0403
               move 'File Status is: nnnn' to MESSAGE-TEXT
               move IO-STATUS-04 to MESSAGE-TEXT(17:4)
               perform Z-DISPLAY-MESSAGE-TEXT
           else
               move '0000' to IO-STATUS-04
               move IO-STATUS to IO-STATUS-04(3:2)
               move 'File Status is: nnnn' to MESSAGE-TEXT
               move IO-STATUS-04 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
               display MESSAGE-BUFFER(1:79) upon console
           else
               display MESSAGE-BUFFER upon console
           end-if
           move all SPACES to MESSAGE-TEXT
           exit.

      *****************************************************************
       Z-POST-COPYRIGHT.
           display SIM-TITLE     upon console
           display SIM-COPYRIGHT upon console
           exit.
      *****************************************************************
      *      This example is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

Table of Contents Previous Section Next Section The File Create Program

The following (CBLCLTC2.cbl) is the source code listing for the program that creates a file containing the printable character set.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLCLTC2.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      * Copyright (C) 1987-2015 SimoTime Technologies.                *
      *                                                               *
      * 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 Technologies. 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           *
      * Technologies.                                                 *
      *                                                               *
      * 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           *
      * Technologies.                                                 *
      *                                                               *
      * SimoTime Technologies 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       *
      * Technologies 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 Technologies                                         *
      * 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 Technologies, *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      * Source Member: CBLCLTC2.CBL
      * Copy Files:    PASSRA12.CPY
      * Calls to:      SIMORA12
      *****************************************************************
      *
      *                   ************
      *                   * CBLCLTJ2 *
      *                   ********jcl*
      *                        *
      *                   ************
      *                   * IEFBR14  *
      *                   ********utl*
      *                        *
      *                   ************     ************
      *                   * CBLCLTC2 *-----* COLLATE1 *
      *                   ********cbl*     ********dat*
      *                        *
      *                   ************
      *                   *   EOJ    *
      *                   ************
      *
      *****************************************************************
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT COLLATE1-FILE  ASSIGN to     COLLATE1
                  ORGANIZATION is SEQUENTIAL
                  ACCESS MODE  is SEQUENTIAL
                  FILE STATUS  is COLLATE1-STATUS.

      *****************************************************************
       DATA DIVISION.
       FILE SECTION.
       FD  COLLATE1-FILE
           BLOCK CONTAINS 00800 CHARACTERS
           DATA RECORD    is COLLATE1-RECORD
           .
       01  COLLATE1-RECORD.
           05  COLLATE1-CHARACTER    pic X.
           05  FILLER                pic X.
           05  COLLATE1-DESCRIPTION  pic X(78).

       WORKING-STORAGE SECTION.
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLCLTC2 '.
           05  T2 pic X(34) value 'Create Input for Collating        '.
           05  T3 pic X(10) value ' v12.05.09'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLCLTC2 '.
           05  C2 pic X(20) value 'Copyright 1987-2015 '.
           05  C3 pic X(28) value '   SimoTime Technologies    '.
           05  C4 pic X(20) value ' All Rights Reserved'.

       01  SIM-THANKS-01.
           05  C1 pic X(11) value '* CBLCLTC2 '.
           05  C2 pic X(32) value 'Thank you for using this program'.
           05  C3 pic X(32) value ' provided from SimoTime Technolo'.
           05  C4 pic X(04) value 'gies'.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* CBLCLTC2 '.
           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  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* CBLCLTC2 '.
           05  MESSAGE-TEXT.
               10  MESSAGE-TEXT-1  pic X(68)   value SPACES.
               10  MESSAGE-TEXT-2  pic X(188)  value SPACES.

       01  COLLATE1-STATUS.
           05  COLLATE1-STATUS-L     pic X.
           05  COLLATE1-STATUS-R     pic X.
       01  COLLATE1-EOF              pic X       value 'N'.
       01  COLLATE1-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  APPL-RESULT             pic S9(9)   comp.
           88  APPL-AOK            value 0.
           88  APPL-EOF            value 16.

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

       01  ONE-BYTE                pic X.
       01  ONE-DIGIT               pic 9       value 0.
       01  WORK-20                 pic X(20).
       01  PTR-01                  pic 9(3)    value 0.
       01  UPPER-CASE  pic X(26)   value 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
       01  LOWER-CASE  pic X(26)   value 'abcdefghijklmnopqrstuvwxyz'.
      *
       01  DIGITS-DATA.
           05  FILLER pic X(18) value '0 e=F0 a=30, Digit'.
           05  FILLER pic X(18) value '1 e=F1 a=31, Digit'.
           05  FILLER pic X(18) value '2 e=F2 a=32, Digit'.
           05  FILLER pic X(18) value '3 e=F3 a=33, Digit'.
           05  FILLER pic X(18) value '4 e=F4 a=34, Digit'.
           05  FILLER pic X(18) value '5 e=F5 a=35, Digit'.
           05  FILLER pic X(18) value '6 e=F6 a=36, Digit'.
           05  FILLER pic X(18) value '7 e=F7 a=37, Digit'.
           05  FILLER pic X(18) value '8 e=F8 a=38, Digit'.
           05  FILLER pic X(18) value '9 e=F9 a=39, Digit'.
       01  DIGITS-INFO redefines DIGITS-DATA.
           05  DIGITS-TABLE    pic X(18) occurs 10 times.
      *
       01  UPPER-DATA.
           05  FILLER pic X(23) value 'A e=C1 a=41, Upper-Case'.
           05  FILLER pic X(23) value 'B e=C2 a=42, Upper-Case'.
           05  FILLER pic X(23) value 'C e=C3 a=43, Upper-Case'.
           05  FILLER pic X(23) value 'D e=C4 a=44, Upper-Case'.
           05  FILLER pic X(23) value 'E e=C5 a=45, Upper-Case'.
           05  FILLER pic X(23) value 'F e=C6 a=46, Upper-Case'.
           05  FILLER pic X(23) value 'G e=C7 a=47, Upper-Case'.
           05  FILLER pic X(23) value 'H e=C8 a=48, Upper-Case'.
           05  FILLER pic X(23) value 'I e=C9 a=49, Upper-Case'.
           05  FILLER pic X(23) value 'J e=D1 a=4A, Upper-Case'.
           05  FILLER pic X(23) value 'K e=D2 a=4B, Upper-Case'.
           05  FILLER pic X(23) value 'L e=D3 a=4C, Upper-Case'.
           05  FILLER pic X(23) value 'M e=D4 a=4D, Upper-Case'.
           05  FILLER pic X(23) value 'N e=D5 a=4E, Upper-Case'.
           05  FILLER pic X(23) value 'O e=D6 a=4F, Upper-Case'.
           05  FILLER pic X(23) value 'P e=D7 a=50, Upper-Case'.
           05  FILLER pic X(23) value 'Q e=D8 a=51, Upper-Case'.
           05  FILLER pic X(23) value 'R e=D9 a=52, Upper-Case'.
           05  FILLER pic X(23) value 'S e=E2 a=53, Upper-Case'.
           05  FILLER pic X(23) value 'T e=E3 a=54, Upper-Case'.
           05  FILLER pic X(23) value 'U e=E4 a=55, Upper-Case'.
           05  FILLER pic X(23) value 'V e=E5 a=56, Upper-Case'.
           05  FILLER pic X(23) value 'W e=E6 a=57, Upper-Case'.
           05  FILLER pic X(23) value 'X e=E7 a=58, Upper-Case'.
           05  FILLER pic X(23) value 'Y e=E8 a=59, Upper-Case'.
           05  FILLER pic X(23) value 'Z e=E9 a=5A, Upper-Case'.
       01  UPPER-INFO redefines UPPER-DATA.
           05  UPPER-TABLE    pic X(23) occurs 26 times.
      *
       01  LOWER-DATA.
           05  FILLER pic X(23) value 'a e=81 a=61, Lower-Case'.
           05  FILLER pic X(23) value 'b e=82 a=62, Lower-Case'.
           05  FILLER pic X(23) value 'c e=83 a=63, Lower-Case'.
           05  FILLER pic X(23) value 'd e=84 a=64, Lower-Case'.
           05  FILLER pic X(23) value 'e e=85 a=65, Lower-Case'.
           05  FILLER pic X(23) value 'f e=86 a=66, Lower-Case'.
           05  FILLER pic X(23) value 'g e=87 a=67, Lower-Case'.
           05  FILLER pic X(23) value 'h e=88 a=68, Lower-Case'.
           05  FILLER pic X(23) value 'i e=89 a=69, Lower-Case'.
           05  FILLER pic X(23) value 'j e=91 a=6A, Lower-Case'.
           05  FILLER pic X(23) value 'k e=92 a=6B, Lower-Case'.
           05  FILLER pic X(23) value 'l e=93 a=6C, Lower-Case'.
           05  FILLER pic X(23) value 'm e=94 a=6D, Lower-Case'.
           05  FILLER pic X(23) value 'n e=95 a=6E, Lower-Case'.
           05  FILLER pic X(23) value 'o e=96 a=6F, Lower-Case'.
           05  FILLER pic X(23) value 'p e=97 a=70, Lower-Case'.
           05  FILLER pic X(23) value 'q e=98 a=71, Lower-Case'.
           05  FILLER pic X(23) value 'r e=99 a=72, Lower-Case'.
           05  FILLER pic X(23) value 's e=A2 a=73, Lower-Case'.
           05  FILLER pic X(23) value 't e=A3 a=74, Lower-Case'.
           05  FILLER pic X(23) value 'u e=A4 a=75, Lower-Case'.
           05  FILLER pic X(23) value 'v e=A5 a=76, Lower-Case'.
           05  FILLER pic X(23) value 'w e=A6 a=77, Lower-Case'.
           05  FILLER pic X(23) value 'x e=A7 a=78, Lower-Case'.
           05  FILLER pic X(23) value 'y e=A8 a=79, Lower-Case'.
           05  FILLER pic X(23) value 'z e=A9 a=7A, Lower-Case'.
       01  LOWER-INFO redefines LOWER-DATA.
           05  LOWER-TABLE    pic X(23) occurs 26 times.
      *
       01  SPECIAL-DATA.
           05  FILLER pic X(30) value '  e=40 a=20, Space Character  '.
           05  FILLER pic X(30) value '" e=7F a=22, Double Quote     '.
           05  FILLER pic X(30) value "' e=7D a=27, Apostrophe       ".
           05  FILLER pic X(30) value '~ e=A1 a=7E, Tilde            '.
           05  FILLER pic X(30) value '! e=5A a=21, Exclamation Point'.
           05  FILLER pic X(30) value '@ e=7C a=40, At Sign          '.
           05  FILLER pic X(30) value '# e=7B a=23, Square Symbol    '.
           05  FILLER pic X(30) value '$ e=5B a=24, Dollar Sign      '.
           05  FILLER pic X(30) value '% e=6C a=25, Per Cent Sign    '.
           05  FILLER pic X(30) value '^ e=B0 a=5E, Carat Symbol     '.
           05  FILLER pic X(30) value '& e=50 a=26, Ampersand        '.
           05  FILLER pic X(30) value '* e=5C a=2A, Asterisk         '.
           05  FILLER pic X(30) value '( e=4D a=28, Left Parenthesis '.
           05  FILLER pic X(30) value ') e=5D a=29, Right Parenthesis'.
           05  FILLER pic X(30) value '_ e=6D a=5F, Underscore       '.
           05  FILLER pic X(30) value '+ e=4E a=2B, Plus Sign        '.
           05  FILLER pic X(30) value '{ e=C0 a=7B, Left Brace       '.
           05  FILLER pic X(30) value '} e=D0 a=7D, Right Brace      '.
           05  FILLER pic X(30) value '| e=4F a=7C, Vertical Bar     '.
           05  FILLER pic X(30) value ': e=7A a=3A, Colon            '.
           05  FILLER pic X(30) value '< e=4C a=3C, Less Than        '.
           05  FILLER pic X(30) value '> e=6E a=3E, Greater Than     '.
           05  FILLER pic X(30) value '? e=6F a=3F, Question Mark    '.
           05  FILLER pic X(30) value '` e=79 a=60, Back Apostrophe  '.
           05  FILLER pic X(30) value '- e=60 a=2D, Minus Sign       '.
           05  FILLER pic X(30) value '= e=7E a=3D, Equal Sign       '.
           05  FILLER pic X(30) value '[ e=AD a=5B, Left Bracket     '.
           05  FILLER pic X(30) value '] e=BD a=5D, Right Bracket    '.
           05  FILLER pic X(30) value '\ e=E0 a=5C, Back Slash       '.
           05  FILLER pic X(30) value '; e=5E a=3B, Semicolon        '.
           05  FILLER pic X(30) value ', e=6B a=2C, Comma            '.
           05  FILLER pic X(30) value '. e=4B a=2E, Period Full Stop '.
           05  FILLER pic X(30) value '/ e=61 a=2F, Forward Slash    '.
       01  SPECIAL-INFO redefines SPECIAL-DATA.
           05  SPECIAL-TABLE    pic X(30) occurs 33 times.
      *****************************************************************
       PROCEDURE DIVISION.
           perform Z-POST-COPYRIGHT
           perform COLLATE1-OPEN

           move SPACES to COLLATE1-RECORD

           perform WRITE-RECORDS-WITH-DIGITS
           perform WRITE-RECORDS-WITH-UPPER-CASE
           perform WRITE-RECORDS-WITH-LOWER-CASE
           perform WRITE-RECORDS-WITH-SPECIAL

           move COLLATE1-TOTAL to MESSAGE-TEXT
           perform Z-DISPLAY-CONSOLE-MESSAGE

           if  COLLATE-LOC > 0
               move 'is Finished...' to MESSAGE-TEXT
           else
               move 'is ABENDING...' to MESSAGE-TEXT
           end-if
           perform Z-DISPLAY-CONSOLE-MESSAGE

           perform COLLATE1-CLOSE
           perform Z-THANK-YOU.
           GOBACK.

      *****************************************************************
       WRITE-RECORDS-WITH-DIGITS.
           add 1 to ZERO giving PTR-01
           move SPACES to COLLATE1-RECORD
           perform 10 times
               move DIGITS-TABLE(PTR-01) to COLLATE1-RECORD
               perform COLLATE1-WRITE
               add 1 to PTR-01
           end-perform
           exit.

      *****************************************************************
       WRITE-RECORDS-WITH-LOWER-CASE.
           add 1 to ZERO giving PTR-01
           move SPACES to COLLATE1-RECORD
           perform 26 times
               move LOWER-TABLE(PTR-01) to COLLATE1-RECORD
               perform COLLATE1-WRITE
               add 1 to PTR-01
           end-perform
           exit.

      *****************************************************************
       WRITE-RECORDS-WITH-UPPER-CASE.
           add 1 to ZERO giving PTR-01
           move SPACES to COLLATE1-RECORD
           perform 26 times
               move UPPER-TABLE(PTR-01) to COLLATE1-RECORD
               perform COLLATE1-WRITE
               add 1 to PTR-01
           end-perform
           exit.

      *****************************************************************
       WRITE-RECORDS-WITH-SPECIAL.
           add 1 to ZERO giving PTR-01
           move SPACES to COLLATE1-RECORD
           perform 33 times
               move SPECIAL-TABLE(PTR-01) to COLLATE1-RECORD
               perform COLLATE1-WRITE
               add 1 to PTR-01
           end-perform
           exit.

      *****************************************************************
      * I/O ROUTINES FOR COLLATE1...                                  *
      *****************************************************************
       COLLATE1-WRITE.
           if  COLLATE1-OPEN-FLAG = 'C'
               perform COLLATE1-OPEN
           end-if
           write COLLATE1-RECORD
           if  COLLATE1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               add 1 to COLLATE-LOC
           else
               if  COLLATE1-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 'COLLATE1-Failure-WRITE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move COLLATE1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       COLLATE1-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open output COLLATE1-FILE
           if  COLLATE1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to COLLATE1-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'COLLATE1-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move COLLATE1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       COLLATE1-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close COLLATE1-FILE
           if  COLLATE1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'C' to COLLATE1-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'COLLATE1-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-CONSOLE-MESSAGE
               move COLLATE1-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)
           else
               display MESSAGE-BUFFER
           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 '* CBLCLTC2 File-Status-' IO-STAT1 '/'
                       TWO-BYTES-BINARY upon console
           else
               display '* CBLCLTC2 File-Status-' IO-STATUS
           end-if
           exit.

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

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

Table of Contents Previous Section Next Section Summary

This suite of sample programs describes the ASCII and EBCDIC sorting or collating sequences and provides an example of programming logic that will work in an EBCDIC environment (i.e. mainframe) but fail in an ASCII environment (i.e. PC with Windows or Unix). The COBOL programs were written using the COBOL/390 dialect and will execute on an IBM Mainframe or the platforms supported by Micro Focus COBOL (i.e. Windows and UNIX).

The purpose of this document is to assist 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.

Table of Contents Previous Section Next Section Software Agreement and Disclaimer

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.

Table of Contents Previous Section Next Section Downloads and Links to Similar Pages

This section includes links to documents with additional information that are beyond the scope and purpose of this document. The first group of documents may be available from a local system or via an internet connection, the second group of documents will require an internet connection.

Note:  A SimoTime License is required for the items to be made available on a local system or server.

Table of Contents Previous Section Next Section Current Server or Internet Access

The following links may be to the current server or to the Internet.

Note: The latest versions of the SimoTime Documents and Program Suites are available on the Internet and may be accessed using the Link to Internet icon. If a user has a SimoTime Enterprise License the Documents and Program Suites may be available on a local server and accessed using the Link to Server icon.

Link to Internet   Link to Server   Explore how to sort ASCII-encoded Files into an EBCDIC collating sequence or EBCDIC-encoded files into an ASCII collating sequence using the ALTSEQ function of the Mainframe SORT or the ALTSEQ function of the Micro Focus SORT.

Link to Internet   Link to Server   Explore the JCL Connection for more examples of JCL functionality with programming techniques and sample code.

Link to Internet   Link to Server   Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.

Link to Internet   Link to Server   Explore An Enterprise System Model that describes and demonstrates how Applications that were running on a Mainframe System and non-relational data that was located on the Mainframe System were copied and deployed in a Microsoft Windows environment with Micro Focus Enterprise Server.

Link to Internet   Link to Server   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.

Link to Internet   Link to Server   Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and/or QSAM files.

Table of Contents Previous Section Next Section Internet Access Required

The following links will require an internet connection.

This suite of programs and documentation is available for download. Link to an Evaluation zPAK Option that includes the program members, documentation and control files.

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

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

Table of Contents Previous Section Next Section Glossary of Terms

Link to Internet   Link to Server   Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.

Table of Contents Previous Section Next Section Comments or Feedback

This document was created and is copyrighted and maintained by SimoTime Technologies.

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.

Table of Contents Previous Section Next Section Company Overview

Founded in 1987, SimoTime Technologies 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
Collating Sequence, the EBCDIC and ASCII Environments
Copyright © 1987-2015
SimoTime Technologies
All Rights Reserved
When technology complements business
http://www.simotime.com