|
|
Text
Justify within a Field Center, Right or Left Justification http://www.simotime.com |
| When technology complements business | Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
This suite of programs provides an example of a routine that will center a text string within a character field. It also shows how to left or right justify a text string within a character field. Two sample COBOL programs are provided. The first program is a demonstration program that reads a file containing the JUSTIFY information records and calls the second COBOL program that actually does the text justification.
The objective of the text-justification routine is to right-justify, left-justify or center a text string within a field with the appropriate leading and/or trailing space characters. If the requirement is to right-adjust, zero-fill a numeric field that will contain all digits and be properly aligned to the units position then refer to the right-adjust routine (or cblraz01.htm).
The source code for both COBOL programs is 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 is provided in the Downloads and Links to Similar Pages section of this document.
The following is a list of the functions provided in this example.
| 1. | Demonstrate how to Center a text string within a character field. |
| 2. | Demonstrate how to Left or Right justify a text string within a character field. |
| 3. | Demonstrate the use of the COBOL Reference Modification function. |
The first task performed by the SimoJUST routine is to scan the source field from left to right and determine the first and last non-space character and the length of the test stging within the source field. The next task is to do the requested justification (center, right or left) by copying the text string from the source field to the appropriate position in target field. IF a request other than CENTER, RIGHT or LEFT is requested the return code (or JUST-RESPOND) is set to 0008.
The following is an example of the contents of the input or JUSTIFY-info file (JUSTGET1).
CENTER ********************************************* CENTER CENTER THE FOLLOWING CENTER PLEASE CENTER THIS LEFT-JUSTIFIED STRING CENTER PLEASE CENTER A RIGHT-JUSTIFIED STRING CENTER CENTER WITH LEADING SPACES TO CONSIDER CENTER THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING CENTER CENTER THIS CENTER 1 CENTER 12 CENTER 123 CENTER 1234 CENTER 12345 CENTER 123456 CENTER End of centering request LEFT ********************************************* LEFT LEFT-JUSTIFY THE FOLLOWING LEFT PLEASE LEFT THIS LEFT-JUSTIFIED STRING LEFT PLEASE LEFT A RIGHT-JUSTIFIED STRING LEFT LEFT WITH LEADING SPACES TO CONSIDER LEFT THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING LEFT LEFT THIS LEFT 1 LEFT 12 LEFT 123 LEFT 1234 LEFT 12345 LEFT 123456 LEFT End of Left-Justify request RIGHT ********************************************* RIGHT RIGHT-JUSTIFY THE FOLLOWING RIGHT PLEASE RIGHT THIS LEFT-JUSTIFIED STRING RIGHT PLEASE RIGHT A RIGHT-JUSTIFIED STRING RIGHT RIGHT WITH LEADING SPACES TO CONSIDER RIGHT THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING RIGHT RIGHT THIS RIGHT 1 RIGHT 12 RIGHT 123 RIGHT 1234 RIGHT 12345 RIGHT 123456 RIGHT End of Right-Justify request
The following is an example of the output file (JUSTPUT1) based on the preceding JUSTIFY-info file.
Justify a Text String in a Field v04.03.17 http://www.simotime.com
Copyright 1987-2010 SimoTime Enterprises, LLC All Rights Reserved
....:....1....:....2....:....3....:....4....:....5....:....6
*********************************************
CENTER THE FOLLOWING
PLEASE CENTER THIS LEFT-JUSTIFIED STRING
PLEASE CENTER A RIGHT-JUSTIFIED STRING
CENTER WITH LEADING SPACES TO CONSIDER
THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING
CENTER THIS
1
12
123
1234
12345
123456
End of centering request
*********************************************
LEFT-JUSTIFY THE FOLLOWING
PLEASE LEFT THIS LEFT-JUSTIFIED STRING
PLEASE LEFT A RIGHT-JUSTIFIED STRING
LEFT WITH LEADING SPACES TO CONSIDER
THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING
LEFT THIS
1
12
123
1234
12345
123456
End of Left-Justify request
*********************************************
RIGHT-JUSTIFY THE FOLLOWING
PLEASE RIGHT THIS LEFT-JUSTIFIED STRING
PLEASE RIGHT A RIGHT-JUSTIFIED STRING
RIGHT WITH LEADING SPACES TO CONSIDER
THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING
RIGHT THIS
1
12
123
1234
12345
123456
End of Right-Justify request
....:....1....:....2....:....3....:....4....:....5....:....6
JUSTGET1 line count is 0000042
Thank you for using this sample by SimoTime Enterprises, LLC
Please send comments or suggestions to helpdesk@simotime.com
This suite of samples programs will run on the following platforms.
| 1. | Executes on Windows/2000, Windows/NT and Windows/XP using Micro Focus Net Express and the CMD file provided. |
| 2. | May be ported to run on the UNIX platforms supported by Micro Focus COBOL. |
| 3. | Executes on a mainframe with MVS or Windows/2000, Windows/NT and Windows/XP using Micro Focus Mainframe Express and the JCL file provided. |
The following diagram is an overview of how the demonstration program fits into the example. The demonstration program will read the JUSTIFY info file (JUSTGET1), call the right-adjust routine and write the results to the output file (JUSTPUT1). The BLUE boxes are unique to the mainframe and Micro Focus Mainframe Express. The RED boxes are unique to the PC with Windows and Micro Focus Net Express. The GREEN boxes are platform independent and will execute on the mainframe or a PC with Windows. Also, the GREEN boxes may be ported to a UNIX platform that is supported by Micro Focus COBOL.
|
|
Entry Points | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Start the justification processing example | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Delete previously created justify output file | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
Read the justify info file (JUSTGET1), call the justify routine and write the results to the output file (JUSTPUT1). | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
Justify the text string within the field | |||||||||||||||||||||||||||||||||||||||||||||||||
|
End-of-Job | |||||||||||||||||||||||||||||||||||||||||||||||||||
The following is the syntax for calling the right-adjust routine (SIMOJUST.CBL).
call 'SIMOJUST' using JUST-PASS-AREA
The callable justify routine will accept a string of text up to forty-eight (48) characters. A data structure for calling the SIMOJUST routine is provided. A copy file (PASSJUST.CPY) is provided with the following fields defined.
*****************************************************************
* Data Structure or Pass Area used for calling SIMOJUST. *
*****************************************************************
* Copyright (C) 1987-2010 SimoTime Enterprises *
* All Rights Reserved *
*****************************************************************
* Provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
01 JUST-PASS-AREA.
05 JUST-REQUEST PIC X(8).
05 JUST-RESPOND PIC 9(4).
05 JUST-SOURCE PIC X(60).
05 JUST-TARGET PIC X(60).
*! PASSJUST - End-of-Copy File...
The following table is an overview of the data strings used in the pass area.
| Field Name | Description | ||||||
| JUST-REQUEST | This is an eight character data string and should contain the
following in upper case.
|
||||||
| JUST-RESPOND | This is a four byte binary data string and is used by the conversion routine to pass a return code. If the conversion request is successful the value in this data string will be zero. | ||||||
| JUST-SOURCE | This is the sixty (60) byte input for the SimoJUST routine. It is not modified by the justify routine. | ||||||
| JUST-TARGET | This is the sixty (60) byte output for the SimoJUST routine. The requested text string is copied to this field in a format that is centered, right-adjusted of left-adjusted based on the JUST-REQUEST. |
This sample suite of programs has two CMD members. The first CMD member will execute the demonstration program. The second CMD member will create a JUSTIFY info file (JUSTGET1.TXT) that is used by the first CMD member as input.
The following is the CMD required to run the demonstration program on a Personal Computer with Micro Focus Net Express.
@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 - Read a file of JUSTIFY info, do justify, write output.
rem * Author - SimoTime Enterprises
rem * Date - January 24, 1996
rem *
rem * The job will read an 80-byte file that contains JUSTIFY
rem * information. The job will also write a file containing the results
rem * of the justify functions..
rem *
rem * This set of programs will run on a mainframe under MVS or on a
rem * Personal Computer with Windows and Micro Focus Net Express.
rem *
rem * ************
rem * * CblJusE1 *
rem * ********cmd*
rem * *
rem * *
rem * ************ ************ ************
rem * * SimoEXEC ******* SIMOLOGS ******* CONSOLE *
rem * ********cbl* * ********cbl* * ************
rem * * * *
rem * * * * ************
rem * * * **** SYSLOG *
rem * * * ********txt*
rem * * *
rem * * **************************
rem * * *
rem * * ************ ************ ************
rem * * * JUSTGET1 ******* CblJusC1 ******* JUSTPUT1 *
rem * * ********txt* ********cbl* ********csv*
rem * * *
rem * * ************
rem * * * SIMOJUST *
rem * * ********txt*
rem * *
rem * ************
rem * * EOJ *
rem * ************
rem *
rem * *******************************************************************
rem * Step 1 Delete any previously created file...
rem *
set syslog=d:\simoNXE4\AN01\datawrk1\zxSysLog.LOG
rem *
SimoEXEC NOTE *******************************************************CblJusE1
SimoEXEC NOTE Starting JobName CblJusE1
:DeleteQSAM
SimoEXEC NOTE Identify JobStep DeleteQSAM
set JUSTGET1=d:\SimoNXE4\AN01\DataAsc1\JUSTGET1.TXT
set JUSTPUT1=d:\SimoNXE4\AN01\DataWrk1\JUSTPUT1.TXT
if exist %JUSTPUT1% del %JUSTPUT1%
rem *
rem * *******************************************************************
rem * Step 2 Edit input, create a new output file...
rem *
:ExecuteJustifyRoutine
SimoEXEC NOTE Identify JobStep ExecuteJustifyRoutine
SimoEXEC EXEC CBLJUSC1
if exist %RA12PUT1% SimoEXEC NOTE Produced DataSet %RA12PUT1%
SimoEXEC NOTE Finished JobName CblJusE1
if not "%1" == "nopause" pause
The following is the CMD that may be used to create a JUSTIFY-Info file(JUSTGET1.TXT) .
@echo OFF
rem * *******************************************************************
rem * This program is provided by: *
rem * SimoTime Enterprises, LLC *
rem * (C) Copyright 1987-2010 All Rights Reserved *
rem * Web Site URL: http://www.simotime.com *
rem * e-mail: helpdesk@simotime.com *
rem * *******************************************************************
rem *
rem * Text - Create a Sequential Data Set on disk using IEBGENER.
rem * Author - SimoTime Enterprises
rem * Date = January 24, 1996
rem *
rem * The first job step (DeleteQSAM) will delete any previously created
rem * file. The second job step (CreateQSAM) will create a new file.
rem *
rem * This set of programs will run on a Personal Computer with Windows
rem * and Micro Focus Net Express.
rem *
set JobStatus=0000
set syslog=d:\simoNXE4\AN01\datawrk1\zxSysLog.LOG
rem *
SimoEXEC NOTE *******************************************************CblJusE2
SimoEXEC NOTE Starting JobName CblJusE2
SimoEXEC NOTE Identify JobStep DeleteQSAM
set JUSTGET1=d:\SimoNXE4\AN01\DataAsc1\JUSTGET1.TXT
if exist %JUSTGET1% del %JUSTGET1%
rem *
rem * *******************************************************************
rem * Step 2 of 2 Create and populate a new QSAM file...
rem *
:CreateQSAM
SimoEXEC NOTE Identify JobStep CreateQSAM
rem * ..1....:....2....:....3....:....4....:....5....:....6....:....7.
echo CENTER ********************************************* >>%JUSTGET1%
echo CENTER CENTER THE FOLLOWING >>%JUSTGET1%
echo CENTER PLEASE CENTER THIS LEFT-JUSTIFIED STRING >>%JUSTGET1%
echo CENTER PLEASE CENTER A RIGHT-JUSTIFIED STRING >>%JUSTGET1%
echo CENTER CENTER WITH LEADING SPACES TO CONSIDER >>%JUSTGET1%
echo CENTER CENTER THIS >>%JUSTGET1%
echo CENTER 1 >>%JUSTGET1%
echo CENTER 12 >>%JUSTGET1%
echo CENTER 123 >>%JUSTGET1%
echo CENTER 1234 >>%JUSTGET1%
echo CENTER 12345 >>%JUSTGET1%
echo CENTER 123456 >>%JUSTGET1%
echo RIGHT ********************************************* >>%JUSTGET1%
echo RIGHT RIGHT-JUSTIFY THE FOLLOWING >>%JUSTGET1%
echo RIGHT PLEASE RIGHT THIS LEFT-JUSTIFIED STRING >>%JUSTGET1%
echo RIGHT PLEASE RIGHT A RIGHT-JUSTIFIED STRING >>%JUSTGET1%
echo RIGHT RIGHT WITH LEADING SPACES TO CONSIDER >>%JUSTGET1%
echo RIGHT RIGHT THIS >>%JUSTGET1%
echo RIGHT 1 >>%JUSTGET1%
echo RIGHT 12 >>%JUSTGET1%
echo RIGHT 123 >>%JUSTGET1%
echo RIGHT 1234 >>%JUSTGET1%
echo RIGHT 12345 >>%JUSTGET1%
echo RIGHT 123456 >>%JUSTGET1%
echo LEFT ********************************************* >>%JUSTGET1%
echo LEFT LEFT-JUSTIFY THE FOLLOWING >>%JUSTGET1%
echo LEFT PLEASE LEFT THIS LEFT-JUSTIFIED STRING >>%JUSTGET1%
echo LEFT PLEASE LEFT A RIGHT-JUSTIFIED STRING >>%JUSTGET1%
echo LEFT LEFT WITH LEADING SPACES TO CONSIDER >>%JUSTGET1%
echo LEFT LEFT THIS >>%JUSTGET1%
echo LEFT 1 >>%JUSTGET1%
echo LEFT 12 >>%JUSTGET1%
echo LEFT 123 >>%JUSTGET1%
echo LEFT 1234 >>%JUSTGET1%
echo LEFT 12345 >>%JUSTGET1%
echo LEFT 123456 >>%JUSTGET1%
if exist %JUSTGET1% SimoEXEC NOTE Produced DataSet %JUSTGET1%
if not exist %JUSTGET1% set JobStatus=0001
if "%JobStatus%" == "0001" goto :EojNok
:EojAok
SimoEXEC NOTE Finished JobName CblJusE2
goto :End
:EojNok
SimoEXEC NOTE ABENDING JobName CblJusE2
SimoEXEC NOTE ABENDING Message Job Status is %JobStatus%
:End
if not "%1" == "nopause" pause
This sample suite of programs has two JCL members. The first JCL member will execute the demonstration program. The second JCL member will create a JUSTIFY info file (DSN=SIMOTIME.DATA.JUSTGET1) that is used by the first JCL member as input.
The following is the JCL required to run the demonstration program on the mainframe or with Micro Focus Mainframe Express.
//CBLJUSJ1 JOB SIMOTIME,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 - Read a file of JUSTIFY Info, do justify, write output. //* Author - SimoTime Enterprises //* Date - January 24, 1996 //* //* The job will read an 80-byte file that contains JUSTIFY //* information. The job will also write a file containing the results //* of the justify request. //* //* This set of programs will run on a mainframe under MVS or on a //* Personal Computer with Windows and Micro Focus Mainframe Express. //* //* ************ //* * CBLJUSJ1 * //* ********jcl* //* * //* ************ //* * IEFBR14 * //* ********utl* //* * //* ************ ************ ************ //* * JUSTGET1 *-----* CBLJUSC1 *-----* JUSTPUT1 * //* ********dat* ********cbl* ********dat* //* * * //* * * ************ //* * *-call--* SIMOJUST * //* * ********cbl* //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //* Step 1 Delete any previously created file... //* //QSAMDELT EXEC PGM=IEFBR14 //JUSTPUT1 DD DSN=SIMOTIME.DATA.JUSTPUT1,DISP=(MOD,DELETE,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS) //* //* ******************************************************************* //* Step 2 Right adjust input, create a new output file... //* //EXECDAT1 EXEC PGM=CBLJUSC1 //STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //JUSTGET1 DD DSN=SIMOTIME.DATA.JUSTGET1,DISP=SHR //JUSTPUT1 DD DSN=SIMOTIME.DATA.JUSTPUT1, // DISP=(NEW,CATLG,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS) //SYSOUT DD SYSOUT=* //
The following is the JCL that may be used to create a JUSTIFY-info file.
//CBLJUSJ2 JOB SIMOTIME,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 - Create a Sequential Data Set on disk using IEBGENER. //* Author - SimoTime Enterprises //* Date - January 24, 1996 //* //* The first job step (QSAMDELT) will delete any previously created //* file. The second job step (QCRTDIN1) will create a new file. //* //* This set of programs will run on a mainframe under MVS or on a //* Personal Computer with Windows and Micro Focus Mainframe Express. //* //* ******************************************************************* //* Step 1 Delete any previously created file... //* //QSAMDELT EXEC PGM=IEFBR14 //SYSUT2 DD DSN=SIMOTIME.DATA.JUSTGET1,DISP=(MOD,DELETE,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS) //* //* ******************************************************************* //* Step 2 Create and populate a new QSAM file... //* //QCRTDIN1 EXEC PGM=IEBGENER //SYSPRINT DD SYSOUT=* //SYSIN DD DUMMY //* :....1....:....2....:....3....:....4....:....5....:....6....:....7. //SYSUT1 DD * CENTER ********************************************* CENTER CENTER THE FOLLOWING CENTER PLEASE CENTER THIS LEFT-JUSTIFIED STRING CENTER PLEASE CENTER A RIGHT-JUSTIFIED STRING CENTER CENTER WITH LEADING SPACES TO CONSIDER CENTER CENTER THIS CENTER 1 CENTER 12 CENTER 123 CENTER 1234 CENTER 12345 CENTER 123456 RIGHT ********************************************* RIGHT RIGHT-JUSTIFY THE FOLLOWING RIGHT PLEASE RIGHT THIS LEFT-JUSTIFIED STRING RIGHT PLEASE RIGHT A RIGHT-JUSTIFIED STRING RIGHT RIGHT WITH LEADING SPACES TO CONSIDER RIGHT RIGHT THIS RIGHT 1 RIGHT 12 RIGHT 123 RIGHT 1234 RIGHT 12345 RIGHT 123456 LEFT ********************************************* LEFT LEFT-JUSTIFY THE FOLLOWING LEFT PLEASE LEFT THIS LEFT-JUSTIFIED STRING LEFT PLEASE LEFT A RIGHT-JUSTIFIED STRING LEFT LEFT WITH LEADING SPACES TO CONSIDER LEFT LEFT THIS LEFT 1 LEFT 12 LEFT 123 LEFT 1234 LEFT 12345 LEFT 123456 /* //SYSUT2 DD DSN=SIMOTIME.DATA.JUSTGET1, // DISP=(NEW,CATLG,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS) //
The following is the source code listing for the demonstration program.
IDENTIFICATION DIVISION.
PROGRAM-ID. CBLJUSC1.
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: CBLJUSC1.CBL
* Copy Files: PASSJUST.CPY
* Calls to: SIMOJUST
*****************************************************************
*
* ************
* * CBLJUSJ1 *
* ********jcl*
* *
* ************
* * IEFBR14 *
* ********utl*
* *
* ************ ************ ************
* * JUSTGET1 *-----* CBLJUSC1 *-----* JUSTPUT1 *
* ********dat* ********cbl* ********dat*
* * *
* * * ************
* * *-call--* SIMOJUST *
* * ********cbl*
* *
* ************
* * EOJ *
* ************
*
*****************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT JUSTGET1-FILE ASSIGN to JUSTGET1
ORGANIZATION is SEQUENTIAL
ACCESS MODE is SEQUENTIAL
FILE STATUS is JUSTGET1-STATUS.
SELECT JUSTPUT1-FILE ASSIGN to JUSTPUT1
ORGANIZATION is SEQUENTIAL
ACCESS MODE is SEQUENTIAL
FILE STATUS is JUSTPUT1-STATUS.
*****************************************************************
DATA DIVISION.
FILE SECTION.
FD JUSTGET1-FILE
BLOCK CONTAINS 00800 CHARACTERS
DATA RECORD is JUSTGET1-RECORD
.
01 JUSTGET1-RECORD.
05 JUSTGET1-DATA-01.
10 JUSTGET1-KEYWORD pic X(10).
10 JUSTGET1-INFO pic X(70).
FD JUSTPUT1-FILE
BLOCK CONTAINS 00800 CHARACTERS
DATA RECORD is JUSTPUT1-RECORD
.
01 JUSTPUT1-RECORD.
05 JUSTPUT1-DATA-01 pic X(00080).
WORKING-STORAGE SECTION.
01 SIM-TITLE.
05 T1 pic X(11) value '* CBLJUSC1 '.
05 T2 pic X(34) value 'Justify a Text String in a Field '.
05 T3 pic X(10) value ' v04.03.17'.
05 T4 pic X(24) value ' http://www.simotime.com'.
01 SIM-COPYRIGHT.
05 C1 pic X(11) value '* CBLJUSC1 '.
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 '* CBLJUSC1 '.
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 '* CBLJUSC1 '.
05 C2 pic X(32) value 'Please send comments or suggesti'.
05 C3 pic X(32) value 'ons to helpdesk@simotime.com '.
05 C4 pic X(04) value ' '.
01 MESSAGE-BUFFER.
05 MESSAGE-HEADER pic X(11) value '* CBLJUSC1 '.
05 MESSAGE-TEXT.
10 MESSAGE-TEXT-1 pic X(68) value SPACES.
10 MESSAGE-TEXT-2 pic X(188) value SPACES.
01 JUSTGET1-STATUS.
05 JUSTGET1-STATUS-L pic X.
05 JUSTGET1-STATUS-R pic X.
01 JUSTGET1-EOF pic X value 'N'.
01 JUSTGET1-OPEN-FLAG pic X value 'C'.
01 JUSTPUT1-STATUS.
05 JUSTPUT1-STATUS-L pic X.
05 JUSTPUT1-STATUS-R pic X.
01 JUSTPUT1-EOF pic X value 'N'.
01 JUSTPUT1-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 JUSTGET1-TOTAL.
05 filler pic X(23) value 'JUSTGET1 line count is '.
05 JUSTGET1-LOC pic 9(7) value 0.
01 JUSTIFY-HEADER.
05 FILLER pic X(10) value '....:....1'.
05 FILLER pic X(10) value '....:....2'.
05 FILLER pic X(10) value '....:....3'.
05 FILLER pic X(10) value '....:....4'.
05 FILLER pic X(10) value '....:....5'.
05 FILLER pic X(10) value '....:....6'.
05 FILLER pic X(10) value '....:....7'.
05 FILLER pic X(10) value '....:....8'.
*****************************************************************
* The following copy file of the pass area for calling SIMOJUST,
* the date editing routine.
*****************************************************************
*
COPY PASSJUST.
*
*****************************************************************
PROCEDURE DIVISION.
perform Z-POST-COPYRIGHT
perform JUSTGET1-OPEN
perform JUSTPUT1-OPEN
perform POST-HEADER-LINE
perform until JUSTGET1-STATUS not = '00'
perform JUSTGET1-READ
if JUSTGET1-STATUS = '00'
add 1 to JUSTGET1-LOC
perform JUSTIFY-FUNCTION-DOIT
perform JUSTIFY-FUNCTION-DISPLAY
end-if
end-perform
move JUSTGET1-TOTAL to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
if APPL-EOF
move 'is Complete...' to MESSAGE-TEXT
else
move 'is ABENDING...' to MESSAGE-TEXT
end-if
perform Z-DISPLAY-CONSOLE-MESSAGE
perform JUSTPUT1-CLOSE
perform JUSTGET1-CLOSE
perform Z-THANK-YOU.
GOBACK.
*****************************************************************
* The following routines are in alphabetical sequence.. *
*****************************************************************
JUSTIFY-FUNCTION-DISPLAY.
move JUST-TARGET to MESSAGE-TEXT
move MESSAGE-TEXT to JUSTPUT1-DATA-01
perform Z-DISPLAY-CONSOLE-MESSAGE
perform JUSTPUT1-WRITE
exit.
*
*****************************************************************
JUSTIFY-FUNCTION-DOIT.
move JUSTGET1-KEYWORD to JUST-REQUEST
move JUSTGET1-INFO to JUST-SOURCE
call 'SIMOJUST' using JUST-PASS-AREA
exit.
*
*****************************************************************
POST-HEADER-LINE.
move JUSTIFY-HEADER(1:LENGTH of JUST-TARGET)
to MESSAGE-TEXT-1(1:LENGTH of JUST-TARGET)
perform Z-DISPLAY-CONSOLE-MESSAGE
move SPACES to JUSTPUT1-DATA-01
move JUSTIFY-HEADER(1:LENGTH of JUST-TARGET)
to JUSTPUT1-DATA-01(1:LENGTH of JUST-TARGET)
perform JUSTPUT1-WRITE
exit.
*****************************************************************
* I/O ROUTINES FOR JUSTGET1... *
*****************************************************************
JUSTGET1-CLOSE.
add 8 to ZERO giving APPL-RESULT.
close JUSTGET1-FILE
if JUSTGET1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'JUSTGET1-Failure-CLOSE...' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
move JUSTGET1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*---------------------------------------------------------------*
JUSTGET1-READ.
read JUSTGET1-FILE
if JUSTGET1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
if JUSTGET1-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 JUSTGET1-EOF
else
move 'JUSTGET1-Failure-GET...' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
move JUSTGET1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
end-if
exit.
*---------------------------------------------------------------*
JUSTGET1-OPEN.
add 8 to ZERO giving APPL-RESULT.
open input JUSTGET1-FILE
if JUSTGET1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
move 'O' to JUSTGET1-OPEN-FLAG
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'JUSTGET1-Failure-OPEN...' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
move JUSTGET1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*****************************************************************
* I/O ROUTINES FOR JUSTPUT1... *
*****************************************************************
JUSTPUT1-WRITE.
if JUSTPUT1-OPEN-FLAG = 'C'
perform JUSTPUT1-OPEN
end-if
write JUSTPUT1-RECORD
if JUSTPUT1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
if JUSTPUT1-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 'JUSTPUT1-Failure-WRITE...' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
move JUSTPUT1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*---------------------------------------------------------------*
JUSTPUT1-OPEN.
add 8 to ZERO giving APPL-RESULT.
open output JUSTPUT1-FILE
if JUSTPUT1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
move 'O' to JUSTPUT1-OPEN-FLAG
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'JUSTPUT1-Failure-OPEN...' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
move JUSTPUT1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*---------------------------------------------------------------*
JUSTPUT1-CLOSE.
add 8 to ZERO giving APPL-RESULT.
close JUSTPUT1-FILE
if JUSTPUT1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
move 'C' to JUSTPUT1-OPEN-FLAG
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'JUSTPUT1-Failure-CLOSE...' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
move JUSTPUT1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*****************************************************************
* The following Z-Routines perform administrative tasks *
* for this program. *
*****************************************************************
* ABEND the program, post a message to the console and issue *
* a STOP RUN. *
*****************************************************************
Z-ABEND-PROGRAM.
if MESSAGE-TEXT not = SPACES
perform Z-DISPLAY-CONSOLE-MESSAGE
end-if
move 'PROGRAM-IS-ABENDING...' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add 12 to ZERO giving RETURN-CODE
STOP RUN
exit.
*****************************************************************
* Display CONSOLE messages... *
*****************************************************************
Z-DISPLAY-CONSOLE-MESSAGE.
if MESSAGE-TEXT-2 = SPACES
display MESSAGE-BUFFER(1:79) upon console
else
display MESSAGE-BUFFER upon console
end-if
move all SPACES to MESSAGE-TEXT
exit.
*****************************************************************
* Display the file status bytes. This routine will display as *
* two digits if the full two byte file status is numeric. If *
* second byte is non-numeric then it will be treated as a *
* binary number. *
*****************************************************************
Z-DISPLAY-IO-STATUS.
if IO-STATUS not NUMERIC
or IO-STAT1 = '9'
subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
move IO-STAT2 to TWO-BYTES-RIGHT
display '* CBLJUSC1 File-Status-' IO-STAT1 '/'
TWO-BYTES-BINARY upon console
else
display '* CBLJUSC1 File-Status-' IO-STATUS upon console
end-if
exit.
*****************************************************************
Z-POST-COPYRIGHT.
display SIM-TITLE upon console
display SIM-COPYRIGHT upon console
exit.
*****************************************************************
Z-THANK-YOU.
display SIM-THANKS-01 upon console
display SIM-THANKS-02 upon console
exit.
*****************************************************************
* This example is provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
The following is the source code listing for the Centering, Right or Left Justify routine.
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMOJUST.
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: SIMOJUST.CBL
* Copy Files: PASSJUST.CPY
*****************************************************************
*
* SIMOJUST - Justify (or position) a text string within a field
* based on the caller's request to center, left or right justify.
*
* EXECUTION or CALLING PROTOCOL
* -----------------------------
* CALL 'SIMOJUST' USING JUST-PASS-AREA.
*
*****************************************************************
*
* MAINTENANCE
* -----------
* 1988/02/27 Simmons, Created program.
* 1988/02/27 Simmons, No changes to date.
*
*****************************************************************
*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Z-PTR-1 pic 9(3) value 0.
01 Z-PTR-2 pic 9(3) value 0.
01 Z-MAX-1 pic 9(3) value 0.
01 Z-MAX-2 pic 9(3) value 0.
01 FIRST-BYTE pic 9(3) value 0.
01 FINAL-BYTE pic 9(3) value 0.
01 LENGTH-OF-STRING pic 9(3) value 0.
*****************************************************************
LINKAGE SECTION.
COPY PASSJUST.
*****************************************************************
PROCEDURE DIVISION using JUST-PASS-AREA.
perform INITIALIZE-FIELDS
perform until Z-PTR-1 > Z-MAX-1
if JUST-SOURCE(Z-PTR-1:1) not = SPACE
if FIRST-BYTE = 0
add Z-PTR-1 to ZERO giving FIRST-BYTE
end-if
add Z-PTR-1 to ZERO giving FINAL-BYTE
end-if
add 1 to Z-PTR-1
end-perform
compute LENGTH-OF-STRING = FINAL-BYTE - FIRST-BYTE + 1
evaluate JUST-REQUEST
when 'CENTER ' perform REQUEST-CENTER
when 'LEFT ' perform REQUEST-LEFT
when 'RIGHT ' perform REQUEST-RIGHT
when other add 8 to ZERO giving JUST-RESPOND
end-evaluate
GOBACK.
*****************************************************************
INITIALIZE-FIELDS.
add 16 to ZERO giving JUST-RESPOND
move ZERO to Z-PTR-1
move ZERO to Z-PTR-2
move ZERO to FIRST-BYTE
move ZERO to FINAL-BYTE
move ZERO to LENGTH-OF-STRING
move SPACES to JUST-TARGET
add length of JUST-SOURCE to ZERO giving Z-MAX-1
add length of JUST-TARGET to ZERO giving Z-MAX-2
exit.
*****************************************************************
REQUEST-CENTER.
compute Z-PTR-2 = (Z-MAX-2 - LENGTH-OF-STRING)/2 + 1
move JUST-SOURCE(FIRST-BYTE:LENGTH-OF-STRING)
to JUST-TARGET(Z-PTR-2:LENGTH-OF-STRING)
move ZERO to JUST-RESPOND
exit.
*****************************************************************
REQUEST-LEFT.
add 1 to ZERO giving Z-PTR-2
move JUST-SOURCE(FIRST-BYTE:LENGTH-OF-STRING)
to JUST-TARGET(Z-PTR-2:LENGTH-OF-STRING)
move ZERO to JUST-RESPOND
exit.
*****************************************************************
REQUEST-RIGHT.
compute Z-PTR-2 = (Z-MAX-2 - LENGTH-OF-STRING) + 1
move JUST-SOURCE(FIRST-BYTE:LENGTH-OF-STRING)
to JUST-TARGET( Z-PTR-2:LENGTH-OF-STRING)
move ZERO to JUST-RESPOND
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 document is to assist as a tutorial for new programmers or as a quick reference for experienced programmers. This suite of programs provides an example of a routine that does centering and left or right justification of a text string within a field.
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.
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
You may download this example at http://www.simotime.com/sim4dzip.htm#COBOLZipJustifyText 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.
Check out The Right-Adjust, Zero-Fill for right-adjusting a numeric value within a field. This routine also fills the left-most (or high-order) bytes with leading zeroes.
Check out The COBOL Connection in the SimoTime Library for more examples of mainframe COBOL techniques and sample code.
Check out The JCL Connection in the SimoTime Library for more mainframe JCL examples.
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 the SimoTIme Web Site start at http://www.SimoTime.com .
For more information about Micro Focus Mainframe Express refer to http://www.microfocus.com .
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
| Return-to-Top |
| Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |