|
Text Justify within a Field Center, Right or Left Justification |
![]() |
| The SimoTime Home Page |
When using COBOL the ability to position a text string within a fixed field requires a few lines of code. Rather than have every application programmer "cut and paste" or write the lines of code to do the adjustment or alignment task the following approach creates a routine that may be called from other programs. 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 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.
Refer to the callable routine that will right-adjust and zero-fill a numeric field and test the final content for a valid numeric value.
A JCL member is provided to run the job as an MVS batch job on an IBM Mainframe System or as a project with Micro Focus Mainframe Express (MFE) running on a Windows System. A CMD member is provided to run the job with Micro Focus Net Express (MFE) running on a Windows System. A Bash Script File is provided to run the job on a Linux or UNIX System and GnuCOBOL (formerly known as Open COBOL) is used to compile the COBOL Programs.
The source code for both COBOL programs was originally created, compiled and executed using the VS COBOL II. Also, the programs have been tested with COBOL for MVS and COBOL/370. This set of programs and documentation 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.
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-2025
SimoTime Technologies and Services
All Rights Reserved
The following is a list of the functions provided in this example.
| ||||||
| Objectives for the Text Justification Programs |
The first task performed by the SimoJUST routine is to scan the source field from left to right and determine the positions of the first and last non-space character and the length of the text string 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 file that contains records with randomly positioned text strings within a field.
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 a sample output file with the formatted justification based on the keyword that starts in position 1 of the input record.
Justify a Text String in a Field v04.03.17 http://www.simotime.com
Copyright 1987-2011 SimoTime Enterprises 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 software provided from SimoTime Enterprises
Please send all inquires or suggestions to the helpdesk@simotime.com
This suite of samples programs will run on the following platforms.
| ||||||
| Supported Operating Systems and COBOL Technologies |
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).
Color Associations: The
|
| ||||||||||||||||
| Parameters that are Passed to the Text Justification Routine |
A job script may be defined as a text file containing job setup information followed by job steps that identify programs to be executed along with parameters unique to the job step. A job script may be created using a text editor. The naming of a job script is determined by the Operating System. A simple job script may contain a single job step that performs a single function. A typical job script will contain multiple job steps executed in a predefined sequence. The status of each job step may be tested at the end of each job step.
This set of job scripts for a Windows System has two CMD members. The first CMD member will execute the demonstration program. The second CMD member will create the test files used by the first CMD member as input.
The following is the command (CBLJUSE1.cmd) required to run the demonstration program on a Windows System with Micro Focus COBOL technologies.
@echo OFF
set CmdName=CBLJUSE1
rem * *******************************************************************
rem * Job Script - a Windows Command File *
rem * Provided by SimoTime Technologies *
rem * (C) Copyright 1987-2019 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 Technologies
rem * Date - January 24, 1996
rem *
rem * The job will read a file if 80-byte records that contains randomly
rem * positioned text strings within a field within the records.
rem * The program will justify the randomly positioned text strings to
rem * be Center, Right or Left justified based on the keyword starting
rem * in position 1 of each input record.
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 * * run *****************************
rem * ************ *
rem * * ************ ************ ************
rem * * * JUSTGET1 ******* CBLJUSC1 ******* JUSTPUT1 *
rem * * *******rseq* ********cbl* *******rseq*
rem * *
rem * ************
rem * * EOJ *
rem * ************
rem *
rem * *******************************************************************
rem * Step 1 Delete any previously created file...
rem *
call ..\ENV1BASE %CmdName%
if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
rem *
call SimoNOTE "*******************************************************%CmdName%"
call SimoNOTE "Starting CmdName %CmdName%"
:DeleteQSAM
call SimoNOTE "StepInfo Delete previously created file"
set JUSTGET1=%BaseLib1%\DATA\Asc1\JUSTRS80.DAT
set JUSTPUT1=%BaseLib1%\DATA\Wrk1\JUSTPUT1.DAT
if exist %JUSTPUT1% del %JUSTPUT1%
rem *
rem * *******************************************************************
rem * Step 2 Edit input, create a new output file...
rem *
:ExecuteJustifyRoutine
call SimoNOTE "StepInfo Execute the Justify Program"
run CBLJUSC1
if not ERRORLEVEL = 0 set JobStatus=0010
if not %JobStatus% == 0000 goto :EojNok
call SimoNOTE "DataTake %JUSTGet1%"
call SimoNOTE "DataMake %JUSTPUT1%"
rem *
if exist %JUSTPUT1% goto :EojAok
set JobStatus=0020
goto :EojNok
:EojAok
call SimoNOTE "Finished JobName %CmdName%, Job Status is %JobStatus%"
goto :End
:EojNok
call SimoNOTE "ABENDING JobName %CmdName%, Job Status is %JobStatus%"
:End
if not "%SIMOMODE%" == "BATCH" pause
The following is the command (CBLJUSE2.cmd) that may be used to create the test files.
@echo OFF
set CmdName=CBLJUSE2
rem * *******************************************************************
rem * Job Script - a Windows Command File *
rem * Provided by SimoTime Technologies *
rem * (C) Copyright 1987-2019 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 ECHO command.
rem * Author - SimoTime Technologies
rem * Date = January 24, 1996
rem *
rem * The 1ST step will delete a previously created file and then
rem * create a new ASCII/Text file.
rem * The 2ND step will convert the Line Sequential file to a Record
rem * Sequential file and keep the ASCII encoding.
rem * The 3RD step will convert the Line Sequential file to a Record
rem * Sequential file and convert the record content from ASCII to EBCDIC
rem *
rem * This set of programs will run on a Personal Computer with Windows
rem * and Micro Focus Net Express.
rem *
call ..\Env1BASE %CmdName%
if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
rem *
call SimoNOTE "*******************************************************%CmdName%"
call SimoNOTE "Starting CmdName %CmdName%, User is %USERNAME%"
call SimoNOTE "StepInfo Delete previously created files"
set JUSTTXT1=%BaseLib1%\DATA\TXT1\JUSTTXT1.TXT
rem *
rem * *******************************************************************
rem * Step 1 of 3 Create and populate a new ASCII/TEXT file...
rem *
call SimoNOTE "StepInfo Create an ASCII/Text File"
if exist %JUSTTXT1% del %JUSTTXT1%
rem * ..1....:....2....:....3....:....4....:....5....:....6....:....7.
echo CENTER ********************************************* >>%JUSTTXT1%
echo CENTER CENTER THE FOLLOWING >>%JUSTTXT1%
echo CENTER PLEASE CENTER THIS LEFT-JUSTIFIED STRING >>%JUSTTXT1%
echo CENTER PLEASE CENTER A RIGHT-JUSTIFIED STRING >>%JUSTTXT1%
echo CENTER CENTER WITH LEADING SPACES TO CONSIDER >>%JUSTTXT1%
echo CENTER THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING >>%JUSTTXT1%
echo CENTER CENTER THIS >>%JUSTTXT1%
echo CENTER 1 >>%JUSTTXT1%
echo CENTER 12 >>%JUSTTXT1%
echo CENTER 123 >>%JUSTTXT1%
echo CENTER 1234 >>%JUSTTXT1%
echo CENTER 12345 >>%JUSTTXT1%
echo CENTER 123456 >>%JUSTTXT1%
echo CENTER End of centering request >>%JUSTTXT1%
echo LEFT ********************************************* >>%JUSTTXT1%
echo LEFT LEFT-JUSTIFY THE FOLLOWING >>%JUSTTXT1%
echo LEFT PLEASE LEFT THIS LEFT-JUSTIFIED STRING >>%JUSTTXT1%
echo LEFT PLEASE LEFT A RIGHT-JUSTIFIED STRING >>%JUSTTXT1%
echo LEFT LEFT WITH LEADING SPACES TO CONSIDER >>%JUSTTXT1%
echo LEFT THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING >>%JUSTTXT1%
echo LEFT LEFT THIS >>%JUSTTXT1%
echo LEFT 1 >>%JUSTTXT1%
echo LEFT 12 >>%JUSTTXT1%
echo LEFT 123 >>%JUSTTXT1%
echo LEFT 1234 >>%JUSTTXT1%
echo LEFT 12345 >>%JUSTTXT1%
echo LEFT 123456 >>%JUSTTXT1%
echo LEFT End of Left-Justify request >>%JUSTTXT1%
echo RIGHT ********************************************* >>%JUSTTXT1%
echo RIGHT RIGHT-JUSTIFY THE FOLLOWING >>%JUSTTXT1%
echo RIGHT PLEASE RIGHT THIS LEFT-JUSTIFIED STRING >>%JUSTTXT1%
echo RIGHT PLEASE RIGHT A RIGHT-JUSTIFIED STRING >>%JUSTTXT1%
echo RIGHT RIGHT WITH LEADING SPACES TO CONSIDER >>%JUSTTXT1%
echo RIGHT THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING >>%JUSTTXT1%
echo RIGHT RIGHT THIS >>%JUSTTXT1%
echo RIGHT 1 >>%JUSTTXT1%
echo RIGHT 12 >>%JUSTTXT1%
echo RIGHT 123 >>%JUSTTXT1%
echo RIGHT 1234 >>%JUSTTXT1%
echo RIGHT 12345 >>%JUSTTXT1%
echo RIGHT 123456 >>%JUSTTXT1%
echo RIGHT End of Right-Justify request >>%JUSTTXT1%
if exist %JUSTTXT1% call SimoNOTE "DataMake %JUSTTXT1%"
if not exist %JUSTTXT1% set JobStatus=9001
if not %JobStatus% == 0000 goto :EojNok
rem *
rem * *******************************************************************
rem * Step 2 of 3 Convert ASCII/TEXT file to ASCII RSEQ File...
rem *
call SimoNOTE "StepInfo Convert Line Sequential to Record Sequential"
set GETLS080=%JUSTTXT1%
set PUTRS080=%BaseLib1%\DATA\Asc1\JUSTRS80.DAT
if exist %PUTRS080% del %PUTRS080%
run CV80ALAR
if not ERRORLEVEL = 0 set JobStatus=0030
if not %JobStatus% == 0000 goto :EojNok
call SimoNOTE "DataTake %GETLS080%"
call SimoNOTE "DataMake %PUTRS080%"
rem *
rem * *******************************************************************
rem * Step 3 of 3 Convert ASCII/TEXT file to EBCDIC RSEQ File...
rem *
call SimoNOTE "StepInfo Convert Line Sequential to Record Sequential"
set GETLS080=%JUSTTXT1%
set PUTRS080=%BaseLib1%\DATA\Ebc1\JUSTRS80.DAT
if exist %PUTRS080% del %PUTRS080%
run CV80ALER
if not ERRORLEVEL = 0 set JobStatus=0030
if not %JobStatus% == 0000 goto :EojNok
call SimoNOTE "DataTake %GETLS080%"
call SimoNOTE "DataMake %PUTRS080%"
rem *
:EojAok
call SimoNOTE "Finished CmdName %CmdName%, Job Status is %JobStatus% "
goto :End
:EojNok
call SimoNOTE "NOTE ABENDING CmdName %CmdName%, Job Status is %JobStatus% "
:End
if not "%SIMOMODE%" == "BATCH" pause
This set of job scripts has two JCL members. The first JCL member will execute the demonstration program. The second JCL member will create the test files used by the first JCL member as input.
The following is the JCL member (CBLJUSJ1.jcl) required to run the demonstration program on an IBM Mainframe or with Micro Focus Mainframe Express.
//CBLJUSJ1 JOB (SIMOTIME),'COBOL TEXT JUSTIFY',CLASS=1,MSGCLASS=0, // NOTIFY=CSIP1 //* ******************************************************************* //* CBLJUSJ1.JCL - a JCL Member for Batch Job Processing * //* This JCL Member is provided by SimoTime Technologies * //* (C) Copyright 1987-2019 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 Technologies //* Date - January 24, 1996 //* //* This job will read a file of 80-byte records that contain randomly //* positioned text strings within a field within the records. //* The program will justify the randomly positioned text strings to //* be Center, Right or Left justified based on the keyword starting //* in position 1 of each input record. //* //* This set of programs may be compiled and executed on a Mainframe //* System with ZOS or a Linux, UNIX or Windows System with Micro Focus //* Enterprise Server. //* //* ************ //* * CBLJUSJ1 * //* ********jcl* //* * //* ************ //* * IEFBR14 * //* ********utl* //* * //* ************ ************ ************ //* * JUSTGET1 *-----* CBLJUSC1 *-----* JUSTPUT1 * //* ********dat* ********cbl* ********dat* //* * * //* * * ************ //* * *-call--* SIMOJUST * //* * ********cbl* //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //* Step 1 of 2, Delete any previously created file... //* //JOBSETUP 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 of 2, Right, left and center adjust a text string in a field //* Create a new output file... //* //JUSTIFY1 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 member (CBLJUSJ2.jcl) that may be used to create a data file with randomly positioned text strings within a field within the records.
//CBLJUSJ2 JOB SIMOTIME,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1 //* ******************************************************************* //* CBLJUSJ2.JCL - a JCL Member for Batch Job Processing * //* This JCL Member is provided by SimoTime Technologies * //* (C) Copyright 1987-2019 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 Technologies //* Date - January 24, 1996 //* //* The first job step (JOBSETUP) will delete any previously created //* file. The second job step (BUILDNEW) will create a new file of //* randomly positioned text strings within a field within the records. //* //* This set of programs may be compiled and executed on a Mainframe //* System with ZOS or a Linux, UNIX or Windows System with Micro Focus //* Enterprise Server. //* //* ******************************************************************* //* Step 1 of 2, Delete any previously created file... //* //JOBSETUP 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 of 2, Create and populate a new QSAM file... //* //BUILDNEW 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 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 /* //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 JCL member (CBLJUSJ9.jcl) that may be used to delete the data files created during the execution of the Justification programs.
//CBLJUSJ9 JOB SIMOTIME,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1 //* ******************************************************************* //* CBLJUSJ9.JCL - a JCL Member for Batch Job Processing * //* This JCL Member is provided by SimoTime Technologies * //* (C) Copyright 1987-2019 All Rights Reserved * //* Web Site URL: http://www.simotime.com * //* e-mail: helpdesk@simotime.com * //* ******************************************************************* //* //* Text - Delete files created by the Text Justification programs. //* Author - SimoTime Technologies //* Date - January 24, 1996 //* //* This is a single step job that will delete the files created by //* the sample Text Justification programs //* //* This set of programs may be compiled and executed on a Mainframe //* System with ZOS or a Linux, UNIX or Windows System with Micro Focus //* Enterprise Server. //* //* ******************************************************************* //* Step 1 of 1, Delete files created by Text Justification programs. //* //JOBSETUP EXEC PGM=IEFBR14 //CLEANOUT DD DSN=SIMOTIME.DATA.JUSTGET1,DISP=(MOD,DELETE,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS) //SYSUT2 DD DSN=SIMOTIME.DATA.JUSTPUT1,DISP=(MOD,DELETE,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS) //*
This set of job scripts for a Linux or UNIX System has two Bash Scripts. The first Bash Script will execute the demonstration program. The second Bash Script will create the test files used by the first Bash Script as input.
The following is the Bash Shell Script (cbljuss1.sh) that is required to run as a job on a Linux or UNIX System. For this test case the COBOL programs were compiled and executed on a Linux (Ubuntu) System using GnuCOBOL.
#!/bin/bash
JOBNAME=cbljuss1
# * *******************************************************************
# * Bash Script File - provided by SimoTime Technologies *
# * (C) Copyright 1987-2018 All Rights Reserved *
# * Web Site URL: http://www.simotime.com *
# * e-mail: helpdesk@simotime.com *
# * *******************************************************************
# *
# * Text - Execute program, Justify Text String within a Field
# * Author - SimoTime Technologies
# * Date - November 11, 2003
# * Version - 06.07.16
# *
# * Prepare the environment by mapping the file names.
# * Execute the 80/80 copy file program.
# *
# * ********************************************************************
# * Step 1 of 3, Prepare the System Environment.
# *
JOBSTATUS=0
for textstring in $(cat ENV4SYS1.txt);
do
# # * The following statement will replace all occurences
# # * of DL_BASESYS1 with the value of the BASESYS1
# # * environment variable.
textstring=${textstring//DL_BASESYS1/$BASESYS1}
# # * The following statement will replace all occurences
# # * of BASHUSER_JOBNAME with the value of the JOBNAME
# # * environment variable.
textstring=${textstring/DL_JOBNAME/$JOBNAME}
export $textstring
rc=$?
if [ $rc != 0 ]
then
simonote.sh "# $textstring - Return Code is $rc"
JOBSTATUS=$rc
fi
done
# *
simonote.sh "************************************************************$JOBNAME"
simonote.sh "# Starting Job Name $JOBNAME"
simonote.sh "# SIMOSYS1........... $BASESYS1"
simonote.sh "# SIMONOTE........... $SIMONOTE"
simonote.sh "# COB_LIBS........... $COB_LIBS"
simonote.sh "# COB_LIBRARY_PATH... $COB_LIBRARY_PATH"
# *
# * Prepare the environment, map the file names...
export JUSTGET1=$BASESYS1/SIMOSAM1/DEVL/DATA/APPL/SIMOTIME.DATA.JUSTRS80.dat
export JUSTPUT1=$BASESYS1/SIMOSAM1/DEVL/DATA/APPL/SIMOTIME.DATA.JUSTPUT1.dat
simonote.sh "# DATATAKE is $JUSTGET1"
simonote.sh "# DATAMAKE is $JUSTPUT1"
# *
# * ********************************************************************
# * Step 2 of 3, Run the program.
# *
if [ -f "$JUSTPUT1" ]
then
rm $JUSTPUT1
fi
cobcrun CBLJUSC1 | tee $BASESYS1/SIMOSAM1/DEVL/LOGS/SYSOUT_USERPROG_CBLJUSC1.txt
rc=$?
if [ $rc != 0 ]
then
simonote.sh "# ABENDING $name - Return Code is $rc"
JOBSTATUS=$rc
else
((AOK_Count++))
fi
# *
# * ********************************************************************
# * Step 3 of 3, End of Job Processing.
# *
if [ "$JOBSTATUS" = "0" ]
then
simonote.sh "# Finished Job Name $JOBNAME"
else
simonote.sh "# ABENDING Job Name $JOBNAME"
fi
The following is the Bash Shell Script (cbljuss2.sh) that may be used to create the test files.
#!/bin/bash
JOBNAME=cbljuss2
# *********************************************************************
# * Bash Script File - provided by SimoTime Technologies *
# * (C) Copyright 1987-2018 All Rights Reserved *
# * Web Site URL: http://www.simotime.com *
# * e-mail: helpdesk@simotime.com *
# *********************************************************************
# *
# * Text - Create a Sequential Data.
# * Author - SimoTime Technologies
# * Date = January 24, 1996
# *
# * The 1ST step will delete a previously created file and then
# * create a new ASCII/Text file.
# * The 2ND step will convert the Line Sequential file to a Record
# * Sequential file and keep the ASCII encoding.
# * The 3RD step will convert the Line Sequential file to a Record
# * Sequential file and convert the record content from ASCII to EBCDIC
# *
# * This set of programs will run on a Linux System with GnuCOBOL.
# *
# * ********************************************************************
# * Step 1 of 3, Prepare the System Environment.
# *
JOBSTATUS=0
for textstring in $(cat ENV4SYS1.txt);
do
# # * The following statement will replace all occurences
# # * of DL_BASESYS1 with the value of the BASESYS1
# # * environment variable.
textstring=${textstring//DL_BASESYS1/$BASESYS1}
# # * The following statement will replace all occurences
# # * of BASHUSER_JOBNAME with the value of the JOBNAME
# # * environment variable.
textstring=${textstring/DL_JOBNAME/$JOBNAME}
export $textstring
rc=$?
if [ $rc != 0 ]
then
simonote.sh "# $textstring - Return Code is $rc"
JOBSTATUS=$rc
fi
done
# *
simonote.sh "************************************************************$JOBNAME"
echo "# BASESYS1........... $BASESYS1"
echo "# SIMONOTE........... $SIMONOTE"
echo "# COB_LIBS........... $COB_LIBS"
echo "# COB_LIBRARY_PATH... $COB_LIBRARY_PATH"
simonote.sh "StepInfo Delete previously created files"
export JUSTTXT1=$BASESYS1/SIMOSAM1/DEVL/DATA/TXT1/JUSTTXT1.txt
# *
# * *******************************************************************
# * Step 2 of 3 Create and populate a new ASCII/TEXT file...
# *
simonote.sh "StepInfo Create an ASCII/Text File"
if [ -f "$JUSTTXT1" ]
then
rm $JUSTTXT1
fi
# * ..1....:....2....:....3....:....4....:....5....:....6....:....7.
echo "CENTER ********************************************* ">>$JUSTTXT1
echo "CENTER CENTER THE FOLLOWING ">>$JUSTTXT1
echo "CENTER PLEASE CENTER THIS LEFT-JUSTIFIED STRING ">>$JUSTTXT1
echo "CENTER PLEASE CENTER A RIGHT-JUSTIFIED STRING ">>$JUSTTXT1
echo "CENTER CENTER WITH LEADING SPACES TO CONSIDER ">>$JUSTTXT1
echo "CENTER THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING ">>$JUSTTXT1
echo "CENTER CENTER THIS ">>$JUSTTXT1
echo "CENTER 1 ">>$JUSTTXT1
echo "CENTER 12 ">>$JUSTTXT1
echo "CENTER 123 ">>$JUSTTXT1
echo "CENTER 1234 ">>$JUSTTXT1
echo "CENTER 12345 ">>$JUSTTXT1
echo "CENTER 123456 ">>$JUSTTXT1
echo "CENTER End of centering request ">>$JUSTTXT1
echo "LEFT ********************************************* ">>$JUSTTXT1
echo "LEFT LEFT-JUSTIFY THE FOLLOWING ">>$JUSTTXT1
echo "LEFT PLEASE LEFT THIS LEFT-JUSTIFIED STRING ">>$JUSTTXT1
echo "LEFT PLEASE LEFT A RIGHT-JUSTIFIED STRING ">>$JUSTTXT1
echo "LEFT LEFT WITH LEADING SPACES TO CONSIDER ">>$JUSTTXT1
echo "LEFT THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING ">>$JUSTTXT1
echo "LEFT LEFT THIS ">>$JUSTTXT1
echo "LEFT 1 ">>$JUSTTXT1
echo "LEFT 12 ">>$JUSTTXT1
echo "LEFT 123 ">>$JUSTTXT1
echo "LEFT 1234 ">>$JUSTTXT1
echo "LEFT 12345 ">>$JUSTTXT1
echo "LEFT 123456 ">>$JUSTTXT1
echo "LEFT End of Left-Justify request ">>$JUSTTXT1
echo "RIGHT ********************************************* ">>$JUSTTXT1
echo "RIGHT RIGHT-JUSTIFY THE FOLLOWING ">>$JUSTTXT1
echo "RIGHT PLEASE RIGHT THIS LEFT-JUSTIFIED STRING ">>$JUSTTXT1
echo "RIGHT PLEASE RIGHT A RIGHT-JUSTIFIED STRING ">>$JUSTTXT1
echo "RIGHT RIGHT WITH LEADING SPACES TO CONSIDER ">>$JUSTTXT1
echo "RIGHT THIS IS A FULL SIXTY (060) CHARACTER STRING USED FOR TESTING ">>$JUSTTXT1
echo "RIGHT RIGHT THIS ">>$JUSTTXT1
echo "RIGHT 1 ">>$JUSTTXT1
echo "RIGHT 12 ">>$JUSTTXT1
echo "RIGHT 123 ">>$JUSTTXT1
echo "RIGHT 1234 ">>$JUSTTXT1
echo "RIGHT 12345 ">>$JUSTTXT1
echo "RIGHT 123456 ">>$JUSTTXT1
echo "RIGHT End of Right-Justify request ">>$JUSTTXT1
if [ -f "$JUSTTXT1" ]
then
simonote.sh "JUSTTXT1 is $JUSTTXT1"
else
simonote.sh "ABENDING File not created, $JUSTTXT1"
exit 9001
fi
# *
# * *******************************************************************
# * Step 2 of 3, Convert ASCII/TEXT file to ASCII RSEQ File...
# *
simonote.sh "StepInfo Convert Line Sequential to ASC Record Sequential"
export GETLS080=$JUSTTXT1
export PUTRS080=$BASESYS1/SIMOSAM1/DEVL/DATA/APPL/SIMOTIME.DATA.JUSTRS80.dat
if [ -f "$PUTRS080" ]
then
rm $PUTRS080
fi
cobcrun CV80ALAR
rc=$?
if [ $rc != 0 ]
then
simonote.sh "+ $name - Return Code is $rc"
JOBSTATUS=$rc
simonote.sh "ABENDING Job Name is $JOBNAME, Job Status is $JOBSTATUS"
exit $JOBSTATUS
else
simonote.sh "DataTake $GETLS080"
simonote.sh "DataMake $PUTRS080"
fi
# *
# * *******************************************************************
# * Step 3 of 3 Convert ASCII/TEXT file to EBCDIC RSEQ File...
# *
simonote.sh "StepInfo Convert Line Sequential to EBC Record Sequential"
export GETLS080=$JUSTTXT1
export PUTRS080=$BASESYS1/SIMOSAM1/DEVL/DATA/EBC1/SIMOTIME.DATA.JUSTRS80.dat
if [ -f "$PUTRS080" ]
then
rm $PUTRS080
fi
cobcrun CV80ALER
rc=$?
if [ $rc != 0 ]
then
simonote.sh "+ $name - Return Code is $rc"
JOBSTATUS=$rc
simonote.sh "ABENDING Job Name is $JOBNAME, Job Status is $JOBSTATUS"
exit $JOBSTATUS
else
simonote.sh "DataTake $GETLS080"
simonote.sh "DataMake $PUTRS080"
fi
# *
if [ "$JOBSTATUS" = "0" ]
then
simonote.sh "Finished Job Name $JOBNAME"
else
simonote.sh "ABENDING Job Name $JOBNAME"
fi
This section describes the COBOL programs that demonstrate the justification of a text string (left, right or center) within a larger data structure.
The following is the source code (CBLJUSC1.cbl) for the primary program that is executed. This program will read the input file containing the randomly positioned text strings, do the requested justification and write the formatted results to an output file.
IDENTIFICATION DIVISION.
PROGRAM-ID. CBLJUSC1.
AUTHOR. SIMOTIME TECHNOLOGIES.
*****************************************************************
* Copyright (C) 1987-2019 SimoTime Technologies. *
* *
* All rights reserved. Unpublished, all rights reserved under *
* copyright law and international treaty. Use of a copyright *
* notice is precautionary only and does not imply publication *
* or disclosure. *
* *
* Permission to use, copy, modify and distribute this software *
* for any non-commercial purpose and without fee is hereby *
* granted, provided the SimoTime copyright notice appear on all *
* copies of the software. The SimoTime name or Logo may not be *
* used in any advertising or publicity pertaining to the use *
* of the software without the written permission of SimoTime *
* Technologies. *
* *
* Permission to use, copy, modify and distribute this software *
* for any commercial purpose requires a fee to be paid to *
* SimoTime Technologies. Once the fee is received by SimoTime *
* the latest version of the software will be delivered and a *
* license will be granted for use within an enterprise, *
* provided the SimoTime copyright notice appear on all copies *
* of the software. The SimoTime name or Logo may not be used *
* in any advertising or publicity pertaining to the use of the *
* software without the written permission of SimoTime *
* Technologies. *
* *
* SimoTime Technologies makes no warranty or representations *
* about the suitability of the software for any purpose. It is *
* provided "AS IS" without any expressed or implied warranty, *
* including the implied warranties of merchantability, fitness *
* for a particular purpose and non-infringement. SimoTime *
* Technologies shall not be liable for any direct, indirect, *
* special or consequential damages resulting from the loss of *
* use, data or projects, whether in an action of contract or *
* tort, arising out of or in connection with the use or *
* performance of this software *
* *
* SimoTime Technologies *
* 15 Carnoustie Drive *
* Novato, CA 94949-5849 *
* 415.883.6565 *
* *
* RESTRICTED RIGHTS LEGEND *
* Use, duplication, or disclosure by the Government is subject *
* to restrictions as set forth in subparagraph (c)(1)(ii) of *
* the Rights in Technical Data and Computer Software clause at *
* DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of *
* Commercial Computer Software - Restricted Rights at 48 *
* CFR 52.227-19, as applicable. Contact SimoTime Technologies, *
* 15 Carnoustie Drive, Novato, CA 94949-5849. *
* *
*****************************************************************
* This program is provided by SimoTime Technologies *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
* Source Member: 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 ' v08.06.04'.
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-2019 '.
05 C3 pic X(28) value ' SimoTime Technologies '.
05 C4 pic X(20) value ' All Rights Reserved'.
01 SIM-THANKS-01.
05 C1 pic X(11) value '* CBLJUSC1 '.
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 '* CBLJUSC1 '.
05 C2 pic X(32) value 'Please send all inquires or sugg'.
05 C3 pic X(32) value 'estions to the helpdesk@simotime'.
05 C4 pic X(04) value '.com'.
01 MESSAGE-BUFFER.
05 MESSAGE-HEADER pic X(11) value '* 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 SHOW-HEADER-LINE
* The following perform loop will execute until all the
* records are read from the JUSTIFY-Info File or an error
* (non-zero status code) occurs while reading the file.
perform until JUSTGET1-STATUS not = '00'
perform JUSTGET1-READ
if JUSTGET1-STATUS = '00'
add 1 to JUSTGET1-LOC
perform JUSTIFY-FUNCTION-DO-IT
perform JUSTIFY-FUNCTION-SHOW-RESULT
end-if
end-perform
perform SHOW-HEADER-LINE
move JUSTGET1-TOTAL to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
if JUSTGET1-EOF = 'Y'
move 'is Finished...' 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-DO-IT.
move JUSTGET1-KEYWORD to JUST-REQUEST
move JUSTGET1-INFO to JUST-SOURCE
call 'SIMOJUST' using JUST-PASS-AREA
exit.
*
*****************************************************************
JUSTIFY-FUNCTION-SHOW-RESULT.
move JUST-TARGET to MESSAGE-TEXT
move MESSAGE-TEXT to JUSTPUT1-DATA-01
perform Z-DISPLAY-CONSOLE-MESSAGE
perform JUSTPUT1-WRITE
exit.
*
*****************************************************************
SHOW-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.
*****************************************************************
* ABEND the program, post a message to the console and issue *
* a STOP RUN. *
*****************************************************************
Z-ABEND-PROGRAM.
if MESSAGE-TEXT not = SPACES
perform Z-DISPLAY-CONSOLE-MESSAGE
end-if
move 'PROGRAM-IS-ABENDING...' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add 12 to ZERO giving RETURN-CODE
STOP RUN.
* exit.
*****************************************************************
* Display CONSOLE messages... *
*****************************************************************
Z-DISPLAY-CONSOLE-MESSAGE.
if MESSAGE-TEXT-2 = SPACES
display MESSAGE-BUFFER(1:79)
else
display MESSAGE-BUFFER
end-if
move all SPACES to MESSAGE-TEXT
exit.
*****************************************************************
* Display the file status bytes. This routine will display as *
* two digits if the full two byte file status is numeric. If *
* second byte is non-numeric then it will be treated as a *
* binary number. *
*****************************************************************
Z-DISPLAY-IO-STATUS.
if IO-STATUS not NUMERIC
or IO-STAT1 = '9'
subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
move IO-STAT2 to TWO-BYTES-RIGHT
display '* CBLJUSC1 File-Status-' IO-STAT1 '/'
TWO-BYTES-BINARY upon console
display '* CBLJUSC1 File-Status-' IO-STAT1 '/'
TWO-BYTES-BINARY
else
display '* CBLJUSC1 File-Status-' IO-STATUS upon console
display '* CBLJUSC1 File-Status-' IO-STATUS
end-if
exit.
*****************************************************************
Z-POST-COPYRIGHT.
display SIM-TITLE
display SIM-COPYRIGHT
exit.
*****************************************************************
Z-THANK-YOU.
display SIM-THANKS-01
display SIM-THANKS-02
exit.
*****************************************************************
* This example is provided by SimoTime Technologies *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
The following is the source code (SIMOJUST.cbl) for the callable routine that does the Center, Right or Left Justification.
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMOJUST.
AUTHOR. SIMOTIME TECHNOLOGIES.
*****************************************************************
* Copyright (C) 1987-2019 SimoTime Technologies. *
* *
* All rights reserved. Unpublished, all rights reserved under *
* copyright law and international treaty. Use of a copyright *
* notice is precautionary only and does not imply publication *
* or disclosure. *
* *
* Permission to use, copy, modify and distribute this software *
* for any non-commercial purpose and without fee is hereby *
* granted, provided the SimoTime copyright notice appear on all *
* copies of the software. The SimoTime name or Logo may not be *
* used in any advertising or publicity pertaining to the use *
* of the software without the written permission of SimoTime *
* Technologies. *
* *
* Permission to use, copy, modify and distribute this software *
* for any commercial purpose requires a fee to be paid to *
* SimoTime Technologies. Once the fee is received by SimoTime *
* the latest version of the software will be delivered and a *
* license will be granted for use within an enterprise, *
* provided the SimoTime copyright notice appear on all copies *
* of the software. The SimoTime name or Logo may not be used *
* in any advertising or publicity pertaining to the use of the *
* software without the written permission of SimoTime *
* Technologies. *
* *
* SimoTime Technologies makes no warranty or representations *
* about the suitability of the software for any purpose. It is *
* provided "AS IS" without any expressed or implied warranty, *
* including the implied warranties of merchantability, fitness *
* for a particular purpose and non-infringement. SimoTime *
* Technologies shall not be liable for any direct, indirect, *
* special or consequential damages resulting from the loss of *
* use, data or projects, whether in an action of contract or *
* tort, arising out of or in connection with the use or *
* performance of this software *
* *
* SimoTime Technologies *
* 15 Carnoustie Drive *
* Novato, CA 94949-5849 *
* 415.883.6565 *
* *
* RESTRICTED RIGHTS LEGEND *
* Use, duplication, or disclosure by the Government is subject *
* to restrictions as set forth in subparagraph (c)(1)(ii) of *
* the Rights in Technical Data and Computer Software clause at *
* DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of *
* Commercial Computer Software - Restricted Rights at 48 *
* CFR 52.227-19, as applicable. Contact SimoTime Technologies, *
* 15 Carnoustie Drive, Novato, CA 94949-5849. *
* *
*****************************************************************
* This program is provided by SimoTime Technologies *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
* *
*****************************************************************
*
*****************************************************************
* Source Member: 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 Technologies *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
This suite of programs provides an example of a routine that does centering and left or right justification of a variable length text string within a field of fixed length. The purpose of this document is to assist as a tutorial for new programmers or as a quick reference for experienced programmers.
In the world of programming there are many ways to solve a problem. This 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 contact us using the information in the Contact or Feedback section of this document.
Software Agreement and Disclaimer
Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Technologies. Once the fee is received by SimoTime the latest version of the software, documentation or training material will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Technologies.
SimoTime Technologies makes no warranty or representations about the suitability of the software, documentation or learning material for any purpose. It is provided "AS IS" without any expressed or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Technologies shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software, documentation or training material.
This section includes links to documents with additional information that are beyond the scope and purpose of this document. The first group of documents may be available from a local system or via an Internet connection, the second group of documents will require an Internet connection.
Note: A SimoTime License is required for the items to be made available on a local system or server.
The following links may be to the current server or to the Internet.
Note: The latest versions of the SimoTime Documents and Program Suites are available on the Internet and may be accessed using the
icon. If a user has a SimoTime Enterprise License the Documents and Program Suites may be available on a local server and accessed using the
icon.
Explore How to Right Justify with Zero Fill for a string of digits within a numeric field using a COBOL program.
Explore the JCL Connection for more examples of JCL functionality with programming techniques and sample code.
Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.
Explore An Enterprise System Model that describes and demonstrates how Applications that were running on a Mainframe System and non-relational data that was located on the Mainframe System were copied and deployed in a Microsoft Windows environment with Micro Focus Enterprise Server.
Explore The ASCII and EBCDIC Translation Tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats.
Explore The File Status Return Codes that are used to interpret the results of accessing VSAM data sets and/or QSAM files.
The following links will require an Internet connection.
This suite of programs and documentation is available to download for review and evaluation purposes. Other uses will require a SimoTime Software License. Link to an Evaluation zPAK Option that includes the program members, documentation and control files.
A good place to start is The SimoTime Home Page for access to white papers, program examples and product information. This link requires an Internet Connection
Explore The Micro Focus Web Site for more information about products (including Micro Focus COBOL) and services available from Micro Focus. This link requires an Internet Connection.
Explore the GnuCOBOL Technologies available from SourceForge. SourceForge is an Open Source community resource dedicated to helping open source projects be as successful as possible. GnuCOBOL (formerly OpenCOBOL) is a COBOL compiler with run time support. The compiler (cobc) translates COBOL source to executable using intermediate C, designated C compiler and linker. This link will require an Internet Connection.
Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.
This document was created and is maintained by SimoTime Technologies. If you have any questions, suggestions, comments or feedback please use the following contact information.
| 1. | Send an e-mail to our helpdesk. |
| 1.1. | helpdesk@simotime.com. |
| 2. | Our telephone numbers are as follows. |
| 2.1. | 1 415 763-9430 office-helpdesk |
| 2.2. | 1 415 827-7045 mobile |
We appreciate hearing from you.
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 or check the web site at http://www.simotime.com
| Return-to-Top |
| Justify to the Center, Right or Left a Text String within a Field |
| Copyright © 1987-2025 SimoTime Technologies and Services All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |