![]() |
COBOL Coding Tricks The Common and the Esoteric |
| When technology complements business | Copyright © 1987-2012 SimoTime Enterprises All Rights Reserved |
| The SimoTime Home Page |
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.
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.
This process uses two subroutines. The first sub-routine will call the second sub-routine to get the data and time and then post the information to SYSOUT. The second sub-routine will get the system data and time using the COBOL ACCEPT statement.
The date and time will be posted to SYSOUT in a variety of formats.
Click on this link to view the sub-routine in the program that does the Get System Date and Post to SYSOUT. This will be displayed in a separate window.
Click on this link to view the sub-routine in the program that does the Get System Date and Time. This will be displayed in a separate window.
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.
WORKING-STORAGE SECTION.
01 UPPER-CASE pic X(26) value 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
01 LOWER-CASE pic X(26) value 'abcdefghijklmnopqrstuvwxyz'.
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. This will be displayed in a separate window.
WIP...
This sub-routine shows how to access a single position within a field. This approach (using REDEFINES) works well for small fields. If larger fields are being scanned or parsed it may be a better approach to use reference modification that is descrbed in the next section.
Click on this link to view the code in the program that does the Cobol Redefines Example. This will be displayed in a separate window.
This sub-routine will show two (2) examples of accessing individual bytes with a field or text string. The first example is similar to the preceding section that uses the REDEFINES capability of COBOL but uses explicit coding and Reference Modificaiton.
The second example uses Reference Modification with a variable pointer to the byte to be accessed. This provides for a very efficient text scanning or parsing capability.
Click on this link to view the code in the program that does the Cobol Reference Modification. This will be displayed in a separate window.
WIP...
WIP...
Click on this link to view the code in the program that does the Right Adjust with Zero Fill. This will be displayed in a separate window.
This sub-routine will do two conversions. The first conversion will add the value of a packed-decimal field to a zoned-decimal field with a sign-leading-separate. This will produce a new field that is a display-text field with an implied decimal point. The second conversion will add the value of a packed-decimal field to an edited-numeric field. This will produce a new field that is a display-text field with an explicit decimal point.
The approach of using the "add current-field to zero giving new-field" is used instead of a move. This will do proper rounding and correct decimal alignment if the source and target fields have different decimal positions.
The content of each of the fields will be displayed in a hexadecimal format to SYSOUT and SYSLOG.
Click on this link to view the code in the program that does the Numeric Conversion, Packed to Display. This will be displayed in a separate window.
A separate program is called for this example.
Click on this link to view the called program that does the Table Processing & Bubble Sort. This will be displayed in a separate window.
WIP...
Click on this link to view the code in the program that does the Calculate Elapsed Time. This will be displayed in a separate window.
The following (CBLTRXJ1.JCL) is a sample of the Mainframe JCL needed to run this job.
//CBLTRXJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1 //* ******************************************************************* //* This program is provided by: * //* SimoTime Enterprises, LLC * //* (C) Copyright 1987-2010 All Rights Reserved * //* Web Site URL: http://www.simotime.com * //* e-mail: helpdesk@simotime.com * //* ******************************************************************* //* //* Text - COBOL code for commonly used processing tasks. //* Author - SimoTime Enterprises //* Date - January 01, 1989 //* //* This set of programs illustrate the use of COBOL programs that //* perform commonly used processing tasks. The tasks may be used to //* solve a business requirement or for debugging purposes. //* //* This set of programs will run on a mainframe under MVS or on //* a Personal Computer running Windows and Mainframe Express by //* Micro Focus. //* //* ************ ************ //* * Entry * * Entry * //* * MVS * * Windows * //* ************ ************ //* * * //* ************ ************ //* * CBLTRXJ1 * * CBLTRXE1 * //* ********jcl* ********cmd* //* * * //* ************ * //* * IEFBR14 * * //* ********utl* * //* * * //* ********************************* //* * //* * //* ************ ************ //* * CBLTRXC1 *----* SYSOUT * //* ********cbl* ************ //* * * //* * * //* * * //* ************** *------CALL-----* //* * * * //* * * ************ ************ //* * * * SIMODUMP *----* SYSLOG * //* * * ************ ************ //* * * //* ************ * //* * EOJ * *------CALL-----* //* ************ * //* * //* * //* * //* ************ ************ ************ //* * CURS0080 *----* CBLTBLC1 *----* LABEL1X6 * //* *******rseq* ********cbl* *******rseq* ///* //* ******************************************************************* //* Step 1 of 2 This job step will delete a previously created //* Mailing Label file. //* //BLOWAWAY EXEC PGM=IEFBR14 //LABEL1X6 DD DSN=SIMOTIME.DATA.LABEL1X6,DISP=(MOD,DELETE,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=48,BLKSIZE=480,DSORG=PS) //* ******************************************************************* //* Step 2 of 2 Execute the Sample programs.... //* //CBLTRXS1 EXEC PGM=CBLTRXC1 //STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //CURS0080 DD DSN=SIMOTIME.DATA.CUST0080,DISP=SHR //LABEL1X6 DD DSN=SIMOTIME.DATA.LABEL1X6,DISP=(NEW,CATLG,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=48,BLKSIZE=480,DSORG=PS) //SYSOUT DD SYSOUT=* //*
The following (CBLTRXE1.CMD) is a sample of the Windows CMD needed to run this job.
@echo OFF
rem * *******************************************************************
rem * This program is provided by: *
rem * SimoTime Enterprises, LLC *
rem * (C) Copyright 1987-2010 All Rights Reserved *
rem * Web Site URL: http://www.simotime.com *
rem * e-mail: helpdesk@simotime.com *
rem * *******************************************************************
rem *
rem * Text - COBOL code for commonly used processing tasks.
rem * Author - SimoTime Enterprises
rem * Date - January 01, 1989
rem *
rem * This set of programs illustrate the use of COBOL programs that
rem * perform commonly used processing tasks. The tasks may be used to
rem * solve a business requirement or for debugging purposes.
rem *
rem * This set of programs will run on a mainframe under MVS or on
rem * a Personal Computer running Windows and Mainframe Express by
rem * Micro Focus.
rem *
rem * ************ ************
rem * * Entry * * Entry *
rem * * MVS * * Windows *
rem * ************ ************
rem * * *
rem * ************ ************
rem * * CBLTRXJ1 * * CBLTRXE1 *
rem * ********jcl* ********cmd*
rem * * *
rem * ************ *
rem * * IEFBR14 * *
rem * ********utl* *
rem * * *
rem * *********************************
rem * *
rem * *
rem * ************ ************
rem * * CBLTRXC1 *----* SYSOUT *
rem * ********cbl* ************
rem * * *
rem * * *
rem * * *
rem * ************** *------CALL-----*
rem * * * *
rem * * * ************ ************
rem * * * * SIMODUMP *----* SYSLOG *
rem * * * ************ ************
rem * * *
rem * ************ *
rem * * EOJ * *------CALL-----*
rem * ************ *
rem * *
rem * *
rem * *
rem * ************ ************ ************
rem * * CURS0080 *----* CBLTBLC1 *----* LABEL1X6 *
rem * *******rseq* ********cbl* *******rseq*
rem *
rem * ********************************************************************
rem * Step 1 of 2 Set the global environment variables...
rem *
setlocal
set CmdName=CblTrxE1
call Env1PROD
set path
set JobStatus=0000
if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
rem *
call SimoNOTE "*******************************************************%CmdName%"
call SimoNOTE "Starting JobName %CmdName%"
rem * ********************************************************************
rem * Step 2 of 2 Execute the sample program...
rem *
set CURS0080=%BaseLib1%\DataLibA\Asc1\SIMOTIME.DATA.CURA0080.DAT
set LABEL1X6=%BaseLib1%\DataLibA\Wrk1\SIMOTIME.DATA.LABEL1X6.DAT
if exist %LABEL1X6% erase %LABEL1X6%
run CblTrxC1
if not "%ERRORLEVEL%" == "0" set JobStatus=0010
if not "%JobStatus%" == "0000" goto :EojNOK
:EojAOK
call SimoNOTE "Produced %LABEL1X6%"
call SimoNOTE "MSG_0001 Please review %SYSOUT%"
call SimoNOTE "MSG_0002 Please review %SYSLOG%"
start notepad %SYSOUT%
start notepad %SYSLOG%
call SimoNOTE "Finished JobName %CmdName%, Job Status is %JobStatus%"
goto :End
:EojNOK
call SimoNOTE "ABENDING JobName %CmdName%, Job Status is %JobStatus%"
echo %CmdName% is ABENDING>>%BaseLib1%\LOGS\ABENDLOG.TXT
goto :End
:End
call SimoNOTE "Conclude SysLog is %SYSLOG%"
if not "%1" == "nopause" pause
endlocal
The following (CBLTRXC1.CBL) is a sample of the Micro Focus COBOL demonstration program. This program will not compile or execute on an IBM Mainframe because of the ORGANIZATION IS LINE SEQUENTIAL on the SELECT statement. If the statement was changed to read ORGANIZATION IS SEQUENTIAL it would run on an IBM Mainframe and "read from" and "write to" a sequential file. The program was tested using Micro Focus Net Express, version 5.0 running on Windows/XP.
IDENTIFICATION DIVISION.
PROGRAM-ID. CBLTRXC1.
AUTHOR. SIMOTIME ENTERPRISES.
*****************************************************************
* Copyright (C) 1987-2010 SimoTime Enterprises, LLC. *
* *
* All rights reserved. Unpublished, all rights reserved under *
* copyright law and international treaty. Use of a copyright *
* notice is precautionary only and does not imply publication *
* or disclosure. *
* *
* Permission to use, copy, modify and distribute this software *
* for any non-commercial purpose and without fee is hereby *
* granted, provided the SimoTime copyright notice appear on all *
* copies of the software. The SimoTime name or Logo may not be *
* used in any advertising or publicity pertaining to the use *
* of the software without the written permission of SimoTime *
* Enterprises. *
* *
* Permission to use, copy, modify and distribute this software *
* for any commercial purpose requires a fee to be paid to *
* SimoTime Enterprises. Once the fee is received by SimoTime *
* the latest version of the software will be delivered and a *
* license will be granted for use within an enterprise, *
* provided the SimoTime copyright notice appear on all copies *
* of the software. The SimoTime name or Logo may not be used *
* in any advertising or publicity pertaining to the use of the *
* software without the written permission of SimoTime *
* Enterprises. *
* *
* SimoTime Enterprises makes no warranty or representations *
* about the suitability of the software for any purpose. It is *
* provided "AS IS" without any express or implied warranty, *
* including the implied warranties of merchantability, fitness *
* for a particular purpose and non-infringement. SimoTime *
* Enterprises shall not be liable for any direct, indirect, *
* special or consequential damages resulting from the loss of *
* use, data or projects, whether in an action of contract or *
* tort, arising out of or in connection with the use or *
* performance of this software *
* *
* SimoTime Enterprises *
* 15 Carnoustie Drive *
* Novato, CA 94949-5849 *
* 415.883.6565 *
* *
* RESTRICTED RIGHTS LEGEND *
* Use, duplication, or disclosure by the Government is subject *
* to restrictions as set forth in subparagraph (c)(1)(ii) of *
* the Rights in Technical Data and Computer Software clause at *
* DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of *
* Commercial Computer Software - Restricted Rights at 48 *
* CFR 52.227-19, as applicable. Contact SimoTime Enterprises, *
* 15 Carnoustie Drive, Novato, CA 94949-5849. *
* *
*****************************************************************
* This program is provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
* *
*****************************************************************
*
*****************************************************************
* Source Member: CBLTRXC1.CBL
* Copy Files: PASSBITS.CPY
* Calls to: SIMOBITS
*****************************************************************
*
* CBLTRXC1 - COBOL code for commonly used processing tasks.
*
* CALLING PROTOCOL
* ----------------
* Use standard procedure to RUN or ANIMATE.
*
* DESCRIPTION
* -----------
* This program shows how to to some common business or system
* tasks. This program will also call a COBOL routine to access
* and sort a table..
*
* ************ ************
* * Entry * * Entry *
* * MVS * * Windows *
* ************ ************
* * *
* ************ ************
* * CBLTRXJ1 * * CBLTRXE1 *
* ********jcl* ********cmd*
* * *
* ************ *
* * IEFBR14 * *
* ********utl* *
* * *
* *********************************
* *
* *
* ************ ************
* * CBLTRXC1 *----* DISPLAY *
* ********cbl* ************
* * *
* * *
* * *
* ************** *---CALL----*
* * *
* * *
* ************ *
* * EOJ * *
* ************ *
* *
* *
* *
* ************ ************ ************
* * TXTA0512 *----* CBLTBLC1 *----* LABEL1X6 *
* ********txt* ********cbl* ********txt*
*
*
* This program calls CBLTBLC1 to process a table.
*
*****************************************************************
*
* MAINTENANCE
* -----------
* 1989/02/27 Simmons, Created program.
* 1997/03/17 Simmons, Updated for call to SIMOBITS.
*
*****************************************************************
*
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
*****************************************************************
* Data-structure for Title and Copyright...
* -----------------------------------------------------------*
01 SIM-TITLE.
05 T1 pic X(11) value '* CBLTRXC1 '.
05 T2 pic X(34) value 'Techniques and Common Routines' .
05 T3 pic X(10) value ' v08.02.28'.
05 T4 pic X(24) value ' http://www.simotime.com'.
01 SIM-COPYRIGHT.
05 C1 pic X(11) value '* CBLTRXC1 '.
05 C2 pic X(20) value 'Copyright 1987-2010 '.
05 C3 pic X(28) value ' SimoTime Enterprises, LLC '.
05 C4 pic X(20) value ' All Rights Reserved'.
01 SIM-THANKS-01.
05 C1 pic X(11) value '* CBLTRXC1 '.
05 C2 pic X(32) value 'Thank you for using this sample '.
05 C3 pic X(32) value 'by SimoTime Enterprises, LLC '.
05 C4 pic X(04) value ' '.
01 SIM-THANKS-02.
05 C1 pic X(11) value '* CBLTRXC1 '.
05 C2 pic X(32) value 'Please send comments or suggesti'.
05 C3 pic X(32) value 'ons to helpdesk@simotime.com '.
05 C4 pic X(04) value ' '.
*****************************************************************
* 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 WORK-50 pic X(50) value SPACES.
01 IX-1 pic 9(3) value 0.
01 BASE-FIELD pic X(3) value 'ABC'.
01 BASE-FIELD-X redefines BASE-FIELD.
05 BASE-FIELD-X1 pic X.
05 BASE-FIELD-X2 pic X.
05 BASE-FIELD-X3 pic X.
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.
05 NBR-05-SIGN-LEAD-S pic S9(5) value 456
SIGN LEADING SEPARATE.
05 NBR-05-SIGN-LEAD-S-X redefines NBR-05-SIGN-LEAD-S
pic X(6).
05 FILLER pic X(10) value SPACES.
05 NBR-05-EDIT-SIGN pic +ZZZ.99.
05 FILLER pic X(09) value SPACES.
01 NBR-12-X pic X(12) value '123'.
01 NBR-12 redefines NBR-12-X
pic 9(12).
01 ROUTINE-NAME pic X(31).
01 WORK-80 pic X(80).
01 UPPER-CASE pic X(26) value 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
01 LOWER-CASE pic X(26) value 'abcdefghijklmnopqrstuvwxyz'.
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 Z-WORK-12 pic X(12) value SPACES.
01 Z-X12 pic 9(3) 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
* Show an example of accessing the system date and time.
perform GET-SYSTEM-DATE
* Show how to use the INSPECT statement to do case conversion.
perform CASE-CONVERSION
* Show how to convert between ASCII and EBCDIC using the
* INSPECT statement.
perform ASCII-EBCDIC-CONVERSION
* Show an example of a COBOL REDEFINES
perform COBOL-REDEFINES-EXAMPLE
perform COBOL-REFERENCE-MODIFICATION
* Show how to test for a numeric value within a field.
perform NUMERIC-TESTING
* Show a Right-Adjust and Zero-fill.
perform RIGHT-ADJUST-ZERO-FILL
* Show how to convert from a NUMERIC, PACKED field to a
* display, numeric field.
perform NUMERIC-PACKED-TO-DISPLAY
* Show an example of table processing
perform TABLE-PROCESSING-BUBBLE-SORT
perform Z-GET-DATE-AND-TIME
if TASK-FLAG-THANKS = 'Y'
perform Z-THANK-YOU
end-if
GOBACK.
*****************************************************************
*
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
move 'Before - Please make this all upper case'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
move 'After - Please make this all upper case'
to MESSAGE-TEXT
* Do the case conversion . . .
inspect MESSAGE-TEXT converting LOWER-CASE to UPPER-CASE
perform Z-POST-MESSAGE
move 'BEFORE - PLEASE MAKE THIS ALL LOWER CASE'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
move 'AFTER - PLEASE MAKE THIS ALL LOWER CASE'
to MESSAGE-TEXT
* Do the case conversion . . .
inspect MESSAGE-TEXT converting UPPER-CASE to LOWER-CASE
perform Z-POST-MESSAGE
perform Z-ROUTINE-FINISHED
exit.
*****************************************************************
*
COBOL-REDEFINES-EXAMPLE.
move 'COBOL-REDEFINES-EXAMPLE' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
* Display the full three (3) byte field
move 'Base-Field ' to MESSAGE-TEXT
move BASE-FIELD to MESSAGE-TEXT(17:3)
perform Z-POST-MESSAGE
* Display the 1st byte of the field using the REDEFINE
move 'Base-Field-X1 ' to MESSAGE-TEXT
move BASE-FIELD-X1 to MESSAGE-TEXT(17:1)
perform Z-POST-MESSAGE
* Display the 2nd byte of the field using the REDEFINE
move 'Base-Field-X2 ' to MESSAGE-TEXT
move BASE-FIELD-X2 to MESSAGE-TEXT(17:1)
perform Z-POST-MESSAGE
* Display the 3rd byte of the field using the REDEFINE
move 'Base-Field-X3 ' to MESSAGE-TEXT
move BASE-FIELD-X3 to MESSAGE-TEXT(17:1)
perform Z-POST-MESSAGE
perform Z-ROUTINE-FINISHED
exit.
*****************************************************************
*
COBOL-REFERENCE-MODIFICATION.
move 'COBOL-REFERENCE-MODIFICATION' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
move 'Access each byte in a text string, Explicit Code'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
* Display the full three (3) byte field
move 'Base-Field ' to MESSAGE-TEXT
move BASE-FIELD to MESSAGE-TEXT(17:3)
perform Z-POST-MESSAGE
* Reference and display the 1st byte of the field
move 'Base-Field(1:1) ' to MESSAGE-TEXT
move BASE-FIELD(1:1) to MESSAGE-TEXT(17:1)
perform Z-POST-MESSAGE
* Reference and display the 2nd byte of the field
move 'Base-Field(2:1) ' to MESSAGE-TEXT
move BASE-FIELD(2:1) to MESSAGE-TEXT(17:1)
perform Z-POST-MESSAGE
* Reference and display the 3rd byte of the field
move 'Base-Field(3:1) ' to MESSAGE-TEXT
move BASE-FIELD(3:1) to MESSAGE-TEXT(17:1)
perform Z-POST-MESSAGE
move 'Access each byte in a text string, Perform loop'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
* Display the full three (3) byte field
move 'Text String ' to MESSAGE-TEXT
move UPPER-CASE to MESSAGE-TEXT(17:26)
perform Z-POST-MESSAGE
* Reference and display each byte of the field
perform varying IX-1 from 1 by 1 until IX-1 > 26
move 'Byte nnn is the character ' to MESSAGE-TEXT
inspect MESSAGE-TEXT replacing first 'nnn' by IX-1
move UPPER-CASE(IX-1:1) to MESSAGE-TEXT(27:1)
perform Z-POST-MESSAGE
end-perform
perform Z-ROUTINE-FINISHED
exit.
*****************************************************************
*
GET-SYSTEM-DATE.
move 'GET-SYSTEM-DATE' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
perform Z-GET-DATE-AND-TIME
move Z-DATE-01 to MESSAGE-TEXT
move 'System Date ' to MESSAGE-TEXT(14:14)
perform Z-POST-MESSAGE
move Z-TIME-01 to MESSAGE-TEXT
move 'System Time ' to MESSAGE-TEXT(14:14)
perform Z-POST-MESSAGE
move Z-DATE-02 to MESSAGE-TEXT
move 'Formatted Date' to MESSAGE-TEXT(14:14)
perform Z-POST-MESSAGE
move Z-TIME-02 to MESSAGE-TEXT
move 'Formatted Time' to MESSAGE-TEXT(14:14)
perform Z-POST-MESSAGE
if Z-DATE-01-MM GREATER THAN 0
and LESS THAN 13
move MONTH-TEXT(Z-DATE-01-MM) to TODAY-WORD
inspect TODAY-WORD replacing all SPACES by '*'
inspect TODAY-WORD replacing first '**' by ' *'
inspect TODAY-WORD replacing first '**' by Z-DATE-01-DD
inspect TODAY-WORD replacing first '**' by ', '
inspect TODAY-WORD replacing first '**' by Z-DATE-01-CC
inspect TODAY-WORD replacing first '**' by Z-DATE-01-YY
inspect TODAY-WORD replacing all '*' by SPACES
move TODAY-IN-TEXT to MESSAGE-TEXT
perform Z-POST-MESSAGE
else
move 'INVALID Month requested...' to MESSAGE-TEXT
perform Z-POST-MESSAGE
end-if
perform Z-ROUTINE-FINISHED
exit.
*****************************************************************
*
NUMERIC-PACKED-TO-DISPLAY.
move 'NUMERIC-PACKED-TO-DISPLAY' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
* The following statement will place the arithmetic value of
* the packed-decimal field into the zone-decimal field with
* the SIGN LEADING SEPARATE.
* The actual value will be x'4EF0F0F1F2F3'. This results in
* converting the packed-decimal field. Both fields have an
* implied decimal point.
add NBR-05-PACK-SIGN to ZERO giving NBR-05-SIGN-LEAD-S
* The following statement will place the arithmetic value of
* the packed-decimal field into the edited print field. The
* actual value will be x'4E4040F14BF2F3'. This results in
* converting the packed-decimal field but has leading spaces.
add NBR-05-PACK-SIGN to ZERO giving NBR-05-EDIT-SIGN
* The preceding two (2) statements do the conversion of the
* packed-decimal field to a display-text field.
* The following will post a hexadecimal dump of the various
* fields with the possible ASCII or EBCDIC display.
* The hexadecimal dump information is posted to both the
* SYSOUT and SYSLOG files.
move 'DUMP' to SIMODUMP-REQUEST
move 'HIDE' to SIMODUMP-COPYRIGHT
if TASK-FLAG-SYSOUT = 'Y'
move 'FILE' to SIMODUMP-SYSOUT
else
move 'BOTH' to SIMODUMP-SYSOUT
end-if
move 'PACKED01' to SIMODUMP-DUMP-ID
add length of NUMBERS-GROUP-01
to ZERO
giving SIMODUMP-LENGTH
move NUMBERS-GROUP-01 to SIMODUMP-BUFFER
call 'SIMODUMP' using SIMODUMP-PASS-AREA
move 'Info_MSG Display Working Storage dump' to MESSAGE-TEXT
perform Z-POST-MESSAGE
move DUMP-HEADER to MESSAGE-TEXT
perform Z-POST-MESSAGE
move SIMODUMP-LINES(1) to MESSAGE-TEXT
perform Z-POST-MESSAGE
move SIMODUMP-LINES(2) to MESSAGE-TEXT
perform Z-POST-MESSAGE
move SIMODUMP-LINES(3) to MESSAGE-TEXT
perform Z-POST-MESSAGE
perform Z-ROUTINE-FINISHED
exit.
*****************************************************************
*
NUMERIC-TESTING.
move 'NUMERIC-TESTING' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
perform Z-ROUTINE-FINISHED
exit.
*****************************************************************
*
*
RIGHT-ADJUST-ZERO-FILL.
move 'RIGHT-ADJUST-ZERO-FILL' to ROUTINE-NAME
perform Z-ROUTINE-STARTING
move '123 ' to NBR-12-X
perform RIGHT-ADJUST-ZERO-FILL-02
move '12345 ' to NBR-12-X
perform RIGHT-ADJUST-ZERO-FILL-02
move '1234567 ' to NBR-12-X
perform RIGHT-ADJUST-ZERO-FILL-02
perform Z-ROUTINE-FINISHED
exit.
*---------------------------------------------------------------*
RIGHT-ADJUST-ZERO-FILL-02.
if NBR-12 NUMERIC
if TASK-FLAG-SYSOUT = 'Y'
display '* CBLTRXC1 NBR-12 AOK...' NBR-12
else
display '* CBLTRXC1 NBR-12 AOK...' NBR-12
upon console
end-if
else
if TASK-FLAG-SYSOUT = 'Y'
display '* CBLTRXC1 NBR-12 NOK...' NBR-12
else
display '* CBLTRXC1 NBR-12 NOK...' NBR-12
upon console
end-if
end-if
move NBR-12-X to Z-WORK-12
perform Z-RIGHT-ADJUST-Z-WORK-12
move Z-WORK-12 to NBR-12-X
if NBR-12 NUMERIC
if TASK-FLAG-SYSOUT = 'Y'
display '* CBLTRXC1 NBR-12 AOK...' NBR-12
else
display '* CBLTRXC1 NBR-12 AOK...' NBR-12
upon console
end-if
else
if TASK-FLAG-SYSOUT = 'Y'
display '* CBLTRXC1 NBR-12 NOK...' NBR-12
else
display '* CBLTRXC1 NBR-12 NOK...' NBR-12
upon console
end-if
end-if
exit.
*****************************************************************
*
*
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
move 'Elapsed Time ' to MESSAGE-TEXT
move ELAPSED-TIME to MESSAGE-TEXT(30:9)
move 'Seconds' to MESSAGE-TEXT(40:7)
perform Z-POST-MESSAGE
perform Z-ROUTINE-FINISHED
exit.
*****************************************************************
* The following Z-Routines perform administrative tasks *
* for this program. *
*****************************************************************
* HTML-TAG
* 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
move 'ccyy/mm/dd' to Z-DATE-02
move Z-DATE-01(1:4) to Z-DATE-02(1:4)
move Z-DATE-01(5:2) to Z-DATE-02(6:2)
move Z-DATE-01(7:2) to Z-DATE-02(9:2)
move 'hh:mm:ss.00' to Z-TIME-02
move Z-TIME-01(1:2) to Z-TIME-02(1:2)
move Z-TIME-01(3:2) to Z-TIME-02(4:2)
move Z-TIME-01(5:2) to Z-TIME-02(7:2)
move Z-TIME-01(7:2) to Z-TIME-02(10:2)
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 ' '
* The following IF logic is for performance. It quickly
* reduces the number of loops for the PERFORM logic.
if Z-WORK-12(7:6) = SPACES
if Z-WORK-12(4:3) = SPACES
move Z-WORK-12(1:3) to Z-WORK-12(10:3)
move all ZEROES to Z-WORK-12(1:9)
else
move Z-WORK-12(1:6) to Z-WORK-12(7:6)
move all ZEROES to Z-WORK-12(1:6)
end-if
else
if Z-WORK-12(10:3) = SPACES
* The following three MOVE statements are used to
* avoid a potential problem with an overlapping MOVE.
move Z-WORK-12(7:3) to Z-WORK-12(10:3)
move Z-WORK-12(4:3) to Z-WORK-12(7:3)
move Z-WORK-12(1:3) to Z-WORK-12(4:3)
move all ZEROES to Z-WORK-12(1:3)
end-if
end-if
perform until Z-WORK-12(12:1) not = SPACE
if Z-WORK-12(12:1) = SPACE
add 11 to ZERO giving Z-X12
perform 11 times
move Z-WORK-12(Z-X12:1) to Z-WORK-12(Z-X12 + 1:1)
subtract 1 from Z-X12
end-perform
move ZERO to Z-WORK-12(1:1)
end-if
end-perform
exit.
*****************************************************************
Z-ROUTINE-STARTING.
if TASK-FLAG-DISPLAY = 'Y'
move all '-' to MESSAGE-TEXT(1:64)
move '*' to MESSAGE-TEXT(1:1)
move '*' to MESSAGE-TEXT(64:1)
perform Z-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 Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
The purpose of this program is to provide examples of coding to perform technical and data manipulation tasks that are not part of the primary business requirements.
Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to SimoTime Enterprises. Once the fee is received by SimoTime the latest version of the software will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
Permission to use, copy, modify and distribute this software for a non-commercial purpose and without fee is hereby granted, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software.
You may download this example at http://www.simotime.com/sim4dzip.htm#zPackcbltrx01 or view the complete list of SimoTime Examples at http://www.simotime.com/sim4dzip.htm.
Note: You must be attached to the Internet to download a Z-Pack or view the list.
The hexadecimal dump of the parameter-buffer uses the same technique as describe in another SimoTime example that describes the dumping of a data string using COBOL. The name of the member that does the actual hexadecimal dump is called SimoDUMP. A copy file (PASSDUMP.CPY) is provided for defining the pass area.
The SimoZAPS Utility Program has the capability of generating a COBOL program that will do the conversion of sequential and VSAM (KSDS) files between EBCDIC and ASCII. SimoZAPS can also read a sequential file in EBCDIC format and create an ASCII/CRLF file or VSAM KSDS file in ASCII format. The conversion tables may be viewed or modified to meet unique requirements. The Hexcess/2 function provides the capability of viewing, finding or patching the contents of a file in hexadecimal.
This item will provide a link to an ASCII or EBCDIC translation table. A column for decimal, hexadecimal and binary is also included.
The following table is a list of white papers that provides more detailed information about the four common numeric formats used on an IBM Mainframe.
| Numeric Type | Description |
| Zoned Decimal | This document describes the zoned-decimal format. This is coded in COBOL as USAGE IS DISPLAY and is the default format if the USAGE clause is missing. |
| Packed Decimal | This document describes the packed-decimal format. This is coded in COBOL as USAGE IS COMPUTATIONAL-3 and is usually coded in its abbreviated form of COMP-3. |
| Binary | This document describes the binary format. This is coded in COBOL as USAGE IS COMPUTATIONAL and is usually coded in its abbreviated form of COMP. This may also be coded with the keyword BINARY. |
| Edited Numeric | This document describes the edited numeric format. This is coded in COBOL using an edit mask in the picture clause. An example would be PIC ZZZ.99+. |
Check out The VSAM - QSAM Connection for more examples of mainframe VSAM and QSAM accessing techniques and sample code.
This document provides a quick summary of the File Status Key for VSAM data sets and QSAM files.
Check out The SimoTime Library for a wide range of topics for Programmers, Project Managers and Software Developers.
To review all the information available on this site start at The SimoTime Home Page .
Check out The SimoTime Glossary for a list of terms and definitions used in the documents provided by SimoTime.
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
We appreciate your comments and feedback.
Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complimentary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
| Return-to-Top |
| Copyright © 1987-2012 SimoTime Enterprises All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |
| Version 07.07.30 |