Академический Документы
Профессиональный Документы
Культура Документы
Introduction
Sample Routines
Date and Time
Case Conversion
EBCDIC and ASCII Conversion
Redefine Data Structures
Scan a Field, Reference Modification
Numeric Testing & Initialization
Right Adjust with Zero Fill
Numeric Convert, Packed to Display
Table Processing & Bubble Sort
Swap the Content of Two Fields
Field Swap, COBOL calls HLASM
Field Swap, COBOL calls COBOL
Calculate Elapsed Time
JCL Member for Mainframe System
Command File for Windows System
COBOL Demonstration Program
Summary
Software Agreement and Disclaimer
Downloads and Links
Current Server or Internet Access
Internet Access Required
Glossary of Terms
Comments or Feedback
Company Overview
The SimoTime Home Page
Introduction
This suite of programs shows various COBOL coding techniques to perform tasks or provide function that may be considered
outside the primary business processing requirements. The structuring and validation of data prior to processing by business
logic is often required. In the world of programming there is usually more than one way to solve a programming challenge.
This suite of programs presents a few tips and techniques to some of these programming challenges.
The source code for the CMD file, the JCL member and the COBOL programs is provided and may be modified to fit your
environment.
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-2019
SimoTime Technologies and Services
All Rights Reserved
Sample Routines
The intent of this section is to provide a summary of the sub-routines by function and a quick link to the sub-routines within
the main program.
Case Conversion
This sub-routine will convert text strings of mixed case to all upper or lower case. A "before and after" snapshot of the text
strings will be posted to SYSOUT.
The following two items are created in the COBOL WORKING-STORAGE section.
In the PROCEDURE DIVISION the following statement will convert a text string of mixed-case content to all upper case.
inspect TEXT-STRING converting LOWER-CASE to UPPER-CASE
Click on this link to view the code in the program that does the Case Conversion. To return to this point use the browser's
"back" function.
01 INITIALIZE-GROUP.
05 INIT-TEXT-01 pic X(6) value 'PREFIX'.
05 INIT-ZDU1-01 pic 9(5) value 12345.
05 INIT-PDU1-01 pic 9(5) COMP-3 value 12345.
05 INIT-BNU1-01 pic 9(5) COMP value 12345.
05 INIT-TEXT-02 pic X(6) value 'SUFFIX'
In the PROCEDURE DIVISION the following statements are used to initialize the individual fields within a group.
initialize INITIALIZE-GROUP
or
or
move all SPACES to INITIALIZE-GROUP
Note: The use of a "MOVE" of all SPACES at the group level is not a good practice when the group contains
fields that are defined as numeric.
Click on this link to view the code in the program that does the Numeric Testing and Field Initialization To return to this point
use the browser's "back" function.
01 SIM-THANKS-01.
05 C1 pic X(11) value '* CBLTRXC1 '.
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 '* CBLTRXC1 '.
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'.
*****************************************************************
* Buffer used for posting messages to the console.
* -----------------------------------------------------------*
01 MESSAGE-BUFFER.
05 MESSAGE-HEADER pic X(11) value '* CBLTRXC1 '.
05 MESSAGE-TEXT.
10 MESSAGE-TEXT-1 pic X(68) value SPACES.
10 MESSAGE-TEXT-2 pic X(41) value SPACES.
* End-of-Message-Buffer
01 TASK-FLAGS.
05 TASK-FLAG-BANNER pic X value 'Y'.
05 TASK-FLAG-THANKS pic X value 'Y'.
05 TASK-FLAG-DISPLAY pic X value 'Y'.
05 TASK-FLAG-SYSOUT pic X value 'Y'.
01 NUMBERS-GROUP-01.
05 NBR-05-PACK-SIGN pic S9(5) comp-3 value 123.
05 NBR-05-PACK-SIGN-X redefines NBR-05-PACK-SIGN
pic X(3).
05 FILLER pic X(13) value SPACES.
01 MONTH-DATA.
05 FILLER pic X(9) value 'January '.
05 FILLER pic X(9) value 'February '.
05 FILLER pic X(9) value 'March '.
05 FILLER pic X(9) value 'April '.
05 FILLER pic X(9) value 'May '.
05 FILLER pic X(9) value 'June '.
05 FILLER pic X(9) value 'July '.
05 FILLER pic X(9) value 'August '.
05 FILLER pic X(9) value 'September'.
05 FILLER pic X(9) value 'October '.
05 FILLER pic X(9) value 'November '.
05 FILLER pic X(9) value 'December '.
01 MONTH-TABLE redefines MONTH-DATA.
05 MONTH-TEXT pic X(9) occurs 12 times.
01 MM-IDX pic 99 value 0.
01
TODAY-IN-TEXT.
05 FILLER pic X(9) value 'Today is '.
05 TODAY-WORD pic X(18) value SPACES.
*****************************************************************
* Working Storage items for the Z-ROUTINES...
* -----------------------------------------------------------*
01 Z-DATE-01.
05 Z-DATE-01-CC pic 9(02).
05 Z-DATE-01-YY pic 9(02).
05 Z-DATE-01-MM pic 9(02).
05 Z-DATE-01-DD pic 9(02).
01 Z-TIME-01.
05 Z-TIME-01-HH pic X(02).
05 Z-TIME-01-NN pic X(02).
05 Z-TIME-01-SS pic X(02).
05 Z-TIME-01-TT pic X(02).
01 Z-DATE-TIME-02.
05 Z-DATE-02.
10 Z-DATE-02-CC pic 9(02).
10 Z-DATE-02-YY pic 9(02).
10 FILLER pic X value '/'.
10 Z-DATE-02-MM pic 9(02).
10 FILLER pic X value '/'.
10 Z-DATE-02-DD pic 9(02).
05 filler pic x(3) value ' - '.
05 Z-TIME-02.
10 Z-TIME-02-HH pic 9(02).
10 FILLER pic X value ':'.
10 Z-TIME-02-MM pic 9(02).
10 FILLER pic X value ':'.
10 Z-TIME-02-SS pic 9(02).
10 FILLER pic X value '.'.
10 Z-TIME-02-TT pic 9(02).
01 Z-DATE-TIME-03.
05 Z-DATE-03.
10 Z-DATE-03-CC pic 9(02).
10 Z-DATE-03-YY pic 9(02).
10 FILLER pic X value '/'.
10 Z-DATE-03-MM pic 9(02).
10 FILLER pic X value '/'.
10 Z-DATE-03-DD pic 9(02).
05 filler pic x(3) value ' - '.
05 Z-TIME-03.
10 Z-TIME-03-HH pic 9(02).
10 FILLER pic X value ':'.
10 Z-TIME-03-MM pic 9(02).
10 FILLER pic X value ':'.
10 Z-TIME-03-SS pic 9(02).
10 FILLER pic X value '.'.
10 Z-TIME-03-TT pic 9(02).
01 ELASPED-TIME-X.
05 ELAPSED-TIME pic ZZ,ZZZ.99.
01 INITIALIZE-GROUP.
05 INIT-TEXT-01 pic X(6) value 'PREFIX'.
05 INIT-ZDU1-01 pic 9(5) value 12345.
05 INIT-PDU1-01 pic 9(5) COMP-3 value 12345.
05 INIT-BNU1-01 pic 9(5) COMP value 12345.
05 INIT-TEXT-02 pic X(6) value 'SUFFIX'.
01 INITIAL-TOTAL pic 9(7) value 0.
01 DUMP-HEADER.
05 filler pic X value '*'.
05 filler pic X value ' '.
05 H1 pic X(7) value ' Offset'.
05 filler pic X value ' '.
05 H2 pic X(35) value 'Hex..... ........ ........ ........'.
05 filler pic X value ' '.
05 H3 pic X(16) value 'ebcdic..........'.
05 filler pic X value ' '.
05 H4 pic X(16) value 'ascii...........'.
COPY PASSDUMP.
COPY ASCEBCB1.
*****************************************************************
PROCEDURE DIVISION.
if TASK-FLAG-BANNER = 'Y'
perform Z-POST-COPYRIGHT
end-if
perform COBOL-REFERENCE-MODIFICATION
perform Z-GET-DATE-AND-TIME
if TASK-FLAG-THANKS = 'Y'
perform Z-THANK-YOU
end-if
GOBACK.
* HTML-TAG
*****************************************************************
ASCII-EBCDIC-CONVERSION.
move 'ASCII-EBCDIC-CONVERSION' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
perform Z-ROUTINE-FINISHED
exit.
* HTML-TAG
*****************************************************************
* This routine requires the following items.
* Z-DATE-TIME-02 will contain the stop time
* Z-DATE-TIME-03 will contain the start time
* This routine will provide the follow item.
* ELAPSED-TIME will be calculated by the sub-routine.
*
CALCULATE-ELAPSED-TIME.
if Z-DATE-TIME-02 > Z-DATE-TIME-03
compute
ELAPSED-TIME = (Z-TIME-02-HH * 3600
+ Z-TIME-02-MM * 60
+ Z-TIME-02-SS
+ Z-TIME-02-TT / 100)
-
(Z-TIME-03-HH * 3600
+ Z-TIME-03-MM * 60
+ Z-TIME-03-SS
+ Z-TIME-03-TT / 100)
else
move ZEROES to ELAPSED-TIME
end-if
exit.
* HTML-TAG
*****************************************************************
* This routine will convert text strings of mixed case to all
* upper or lower case.
*
CASE-CONVERSION.
move 'CASE-CONVERSION' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
perform Z-ROUTINE-FINISHED
exit.
* HTML-TAG
*****************************************************************
COBOL-REDEFINES-EXAMPLE.
move 'COBOL-REDEFINES-EXAMPLE' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
perform Z-ROUTINE-FINISHED
exit.
* HTML-TAG
*****************************************************************
COBOL-REFERENCE-MODIFICATION.
move 'COBOL-REFERENCE-MODIFICATION' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
perform Z-ROUTINE-FINISHED
exit.
* HTML-TAG
*****************************************************************
GET-SYSTEM-DATE.
move 'GET-SYSTEM-DATE' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
perform Z-GET-DATE-AND-TIME
* HTML-TAG
*****************************************************************
NUMERIC-PACKED-TO-DISPLAY.
move 'NUMERIC-PACKED-TO-DISPLAY' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
perform Z-ROUTINE-FINISHED
exit.
* HTML-TAG
*****************************************************************
NUMERIC-TESTING.
* This segment of code will describe and demonstrate the
* COBOL techniques for checking the validity of a numeric
* field. The techniques for initializing both numeric and
* alphanumeric fields is included.
*
* Data Structure used for this example is as follows:
*
*01 INITIALIZE-GROUP.
* 05 INIT-TEXT-01 pic X(6) value 'PREFIX'.
* 05 INIT-ZDU1-01 pic 9(5) value 12345.
* 05 INIT-PDU1-01 pic 9(5) COMP-3 value 12345.
* 05 INIT-BNU1-01 pic 9(5) COMP value 12345.
* 05 INIT-TEXT-02 pic X(6) value 'SUFFIX'.
*01 INITIAL-TOTAL pic 9(7) value 0.
*
move 'NUMERIC-TESTING' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
*---------------------------------------------------------------*
* T1, Test the program default values of the group numerics
* for validity and display results.
*
if INIT-ZDU1-01 is NUMERIC
and INIT-PDU1-01 is NUMERIC
compute INITIAL-TOTAL = INIT-ZDU1-01
+ INIT-PDU1-01
+ INIT-BNU1-01
display '* CBLTRXC1 T1, INIT-TEXT-01 is ' INIT-TEXT-01
display '* CBLTRXC1 T1, INITIAL-TOTAL = ' INITIAL-TOTAL
display '* CBLTRXC1 T1, INIT-TEXT-02 is ' INIT-TEXT-02
else
move 'T1, A Numeric Field contains non-Numeric value...'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
end-if
*---------------------------------------------------------------*
* T2, Initialize the fields as a group. This should initialize
* the text strings to spaces and the numerics to Zeroes.
* Test the numerics for validity and display results.
*
initialize INITIALIZE-GROUP
if INIT-ZDU1-01 is NUMERIC
and INIT-PDU1-01 is NUMERIC
compute INITIAL-TOTAL = INIT-ZDU1-01
+ INIT-PDU1-01
+ INIT-BNU1-01
display '* CBLTRXC1 T2, INIT-TEXT-01 is ' INIT-TEXT-01
display '* CBLTRXC1 T2, INITIAL-TOTAL = ' INITIAL-TOTAL
display '* CBLTRXC1 T2, INIT-TEXT-02 is ' INIT-TEXT-02
else
move 'T2, A Numeric Field contains non-Numeric value...'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
end-if
*---------------------------------------------------------------*
* T3, Initialize the fields as a group using the "replacing"
* function of the INITIALIZE. The following segment of
* code should initialize the text strings to all X's and
* the numerics to 1.
* Test the numerics for validity and display results.
*
initialize INITIALIZE-GROUP replacing
NUMERIC DATA by 1
ALPHANUMERIC BY all 'X'
if INIT-ZDU1-01 is NUMERIC
and INIT-PDU1-01 is NUMERIC
compute INITIAL-TOTAL = INIT-ZDU1-01
+ INIT-PDU1-01
+ INIT-BNU1-01
display '* CBLTRXC1 T3, INIT-TEXT-01 is ' INIT-TEXT-01
display '* CBLTRXC1 T3, INITIAL-TOTAL = ' INITIAL-TOTAL
display '* CBLTRXC1 T3, INIT-TEXT-02 is ' INIT-TEXT-02
else
move 'T3, A Numeric Field contains non-Numeric value...'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
end-if
*---------------------------------------------------------------*
* T4, Move all spaces to the group item. The following
* segment of code should move all spaces to all the fields
* under the group item. This should produce an invalid
* result when the numeric fields are tested for validity.
*
* The use of a "MOVE" of all SPACES at the group level is
* not a good practice when the group contains fields that
* are defined as numeric.
*
move all SPACES to INITIALIZE-GROUP
if INIT-ZDU1-01 is NUMERIC
and INIT-PDU1-01 is NUMERIC
compute INITIAL-TOTAL = INIT-ZDU1-01
+ INIT-PDU1-01
+ INIT-BNU1-01
display '* CBLTRXC1 T4, INIT-TEXT-01 is ' INIT-TEXT-01
display '* CBLTRXC1 T4, INITIAL-TOTAL = ' INITIAL-TOTAL
display '* CBLTRXC1 T4, INIT-TEXT-02 is ' INIT-TEXT-02
else
move 'T4, A Numeric Field contains non-Numeric value...'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
end-if
perform Z-ROUTINE-FINISHED
exit.
* HTML-TAG
*****************************************************************
*
RIGHT-ADJUST-ZERO-FILL.
move 'RIGHT-ADJUST-ZERO-FILL' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
perform Z-ROUTINE-FINISHED
exit.
*---------------------------------------------------------------*
RIGHT-ADJUST-ZERO-FILL-02.
* Test for Numeric content before the Right-Adjust, leading,
* trailing or embedded space characters should cause a
* non-numeric condition to exist.
if NBR-12 NUMERIC
move 'NBR-12 AOK...' to MESSAGE-TEXT
move NBR-12 to MESSAGE-TEXT(14:12)
perform Z-POST-MESSAGE
else
move 'NBR-12 NOK...' to MESSAGE-TEXT
move NBR-12 to MESSAGE-TEXT(14:12)
perform Z-POST-MESSAGE
end-if
* HTML-TAG
*****************************************************************
*
TABLE-PROCESSING-BUBBLE-SORT.
move 'TABLE-PROCESSING-BUBBLE-SORT' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
* Get and Post the Starting Time
perform Z-GET-DATE-AND-TIME
move Z-DATE-TIME-02 to Z-DATE-TIME-03
move 'Starting Time ' to MESSAGE-TEXT
move Z-DATE-TIME-03 to MESSAGE-TEXT(15:24)
perform Z-POST-MESSAGE
call 'CBLTBLC1'
* Get and Post the Finished Time
perform Z-GET-DATE-AND-TIME
move 'Finished Time ' to MESSAGE-TEXT
move Z-DATE-TIME-02 to MESSAGE-TEXT(15:24)
perform Z-POST-MESSAGE
perform CALCULATE-ELAPSED-TIME
perform Z-ROUTINE-FINISHED
exit.
* HTML-TAG
*****************************************************************
* The following Z-Routines perform administrative tasks *
* for this program. *
*****************************************************************
* This routine requires COBOL for 390 dialect because of the
* use of the YYYYMMDD on the ACCEPT statement.
*
Z-GET-DATE-AND-TIME.
accept Z-DATE-01 from DATE YYYYMMDD
accept Z-TIME-01 from TIME
exit.
*****************************************************************
Z-POST-COPYRIGHT.
if TASK-FLAG-SYSOUT = 'Y'
display SIM-TITLE
display SIM-COPYRIGHT
else
display SIM-TITLE upon console
display SIM-COPYRIGHT upon console
end-if
exit.
*****************************************************************
Z-POST-MESSAGE.
if TASK-FLAG-SYSOUT = 'Y'
display MESSAGE-BUFFER
else
display MESSAGE-BUFFER upon console
end-if
move SPACES to MESSAGE-TEXT
exit.
*****************************************************************
Z-POST-MESSAGE-TEXT.
if MESSAGE-TEXT-2 = SPACES
if TASK-FLAG-SYSOUT = 'Y'
display MESSAGE-BUFFER(1:79)
else
display MESSAGE-BUFFER(1:79) upon console
end-if
else
if TASK-FLAG-SYSOUT = 'Y'
display MESSAGE-BUFFER
else
display MESSAGE-BUFFER upon console
end-if
end-if
move SPACES to MESSAGE-TEXT
exit.
*****************************************************************
* Delete all characters to the right of the first space then
* right-adjust with zero fill. This routine works with a single,
* twelve character field and does not require a work area.
*****************************************************************
Z-RIGHT-ADJUST-Z-WORK-12.
* The following INSPECT statement will erase to end-of-field
* any characters after the first space character.
inspect Z-WORK-12
replacing CHARACTERS by ' ' after initial ' '
*****************************************************************
Z-ROUTINE-STARTING.
if TASK-FLAG-DISPLAY = 'Y'
move all '-' to MESSAGE-TEXT(1:64)
move '*' to MESSAGE-TEXT(1:1)
move '*' to MESSAGE-TEXT(64:1)
perform Z-POST-MESSAGE-TEXT
move 'Starting ' to MESSAGE-TEXT
move ROUTINE-NAME to MESSAGE-TEXT(10:32)
perform Z-POST-MESSAGE-TEXT
end-if
exit.
*****************************************************************
Z-ROUTINE-FINISHED.
if TASK-FLAG-DISPLAY = 'Y'
move 'Finished ' to MESSAGE-TEXT
move ROUTINE-NAME to MESSAGE-TEXT(10:32)
perform Z-POST-MESSAGE-TEXT
move SPACES to ROUTINE-NAME
end-if
exit.
*****************************************************************
Z-THANK-YOU.
if TASK-FLAG-SYSOUT = 'Y'
display SIM-THANKS-01
display SIM-THANKS-02
else
display SIM-THANKS-01 upon console
display SIM-THANKS-02 upon console
end-if
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 *
*****************************************************************
Summary
This suite of programs shows various COBOL coding techniques to perform tasks or provide function that may be considered
outside the primary business processing requirements. This document may be used 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 greater awareness of the Data Management and Application Processing alternatives.
The documentation and software were developed and tested on systems that are configured for a SIMOTIME environment
based on the hardware, operating systems, user requirements and security requirements. Therefore, adjustments may be
needed to execute the jobs and programs when transferred to a system of a different architecture or configuration.
SIMOTIME Services has experience in moving or sharing data or application processing across a variety of systems. For
additional information about SIMOTIME Services or Technologies please send an e-mail to: helpdesk@simotime.com or call
415 883-6565. We appreciate hearing from you.
Glossary of Terms
Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.
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 at 1 415 827-7045 or send an e-mail
to: helpdesk@simotime.com
We appreciate hearing from you.
Company Overview
SimoTime Technologies was founded in 1987 and 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. Our customers include small businesses
using Internet technologies to corporations using very large mainframe systems.
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. We specialize in preparing
applications and the associated data that are currently residing on a single platform to be distributed across a variety of
platforms.
Preparing the application programs will require the transfer of source members that will be compiled and deployed on the
target platform.
The data will need to be transferred between the systems and may need to be converted and validated at various stages
within the process.
SimoTime has the technology, services and experience to assist in the application and data management tasks involved with
doing business in a multi-system environment.
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 at 1 415 827-7045 or send an e-mail to: helpdesk@simotime.com
Also, check the web site at http://www.simotime.com
Return-to-Top
COBOL Coding Tricks, the Common and the Esoteric
Copyright © 1987-2019
SimoTime Technologies and Services
All Rights Reserved
When technology complements business
http://www.simotime.com