|
COBOL Parsing Routine Reference Modification |
![]() |
| The SimoTime Home Page |
This suite of programs will describe how to parse a data string using COBOL. The parsing routine uses reference modification to identify the position of the first significant character after a delimiter character. This approach compensates for multiple leading or embedded delimiter characters. For example, if the delimiter character is a space then leading spaces will be ignored (or removed) and multiple, embedded spaces will be treated as a single space and truncate or trim will be used to remove trailing spaces. A new field (or string) is created with the leading spaces removed and all multiple embedded spaces reduced to a single space. The length of the actual text within the output field is also provided.
String manipulation or parsing is quite often considered something that cannot be done using COBOL. Prior to the introduction of Reference Modification in the ANSI/85 standard for COBOL the scanning or parsing of a field at the character-by-character level was very difficult and troublesome. Throughout the years I have been asked to provide clients with mainframe assembler routines to do various functions. When I ask why they want an assembler routine the answer is usually, "I have been told this cannot be done in COBOL."
I have heard this statement many times and in a number of instances it is simply not true. An assembler routine would probably be smaller and run faster. However, if the task could be accomplished in a reasonable manner using COBOL then the cost, effort, frustration and ongoing support of an assembler routine in a COBOL programming shop may not be worth these advantages. This is especially true if assembler expertise is not readily available.
The COBOL language does have a STRING and UNSTRING function. The STRING statement provides for the concatenation of the partial or complete contents of two or more data items into a single data item. The UNSTRING statement causes contiguous data in a sending field to be separated and placed into multiple receiving fields. The STRING and UNSTRING capability works quite well for combining and separating keywords delimited by spaces (or some other delimiting character). For more complex scanning and parsing of a field at the character level it may be best to take an alternative approach similar to what is presented in this example.
This example provides a demonstration program and a callable program to parse a field or data string. Both COBOL programs were written and tested using the COBOL/2 dialect. Also, both COBOL programs will work with COBOL for MVS and COBOL/370. A JCL member is provided to run the job as an MVS (or OS/390) batch job on an IBM mainframe. Please refer to the Micro Focus Web Site for information about running this suite of programs on a Windows, Linux or UNIX System using Micro Focus Enterprise Server.
This technique could also be used to do character (or byte) access and manipulation. The DISPLAY function of COBOL is used by the demonstration program to display the results of the parsing routine.
In the world of programming there are many ways to solve a problem. This suite of programs is provided as a COBOL example of one of the possible solutions to the problem of parsing a data field.
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 callable interface is as follows. The following data structure needs to be defined in Working Storage. A copy file (PASSPARS.cpy) is provided with this suite of sample programs.
01 PRS-PARAMETERS.
05 PRS-REQUEST PIC X VALUE '0'.
05 PRS-STATUS PIC 9(4).
* Provided by the calling program…
05 PRS-DELIMITER PIC X VALUE SPACE.
05 PRS-KEEP-NULL-FIELDS PIC X VALUE 'N'.
05 PRS-SUSPEND PIC X VALUE 'N'.
05 PRS-SUSPEND-BYTE PIC X VALUE SPACE.
05 PRS-TERMINATOR PIC X VALUE 'N'.
05 PRS-TERMINATOR-BYTE PIC X VALUE SPACE.
05 PRS-BUFFER-SIZE PIC 9(4) VALUE 1024.
05 PRS-BUFFER PIC X(1024).
05 PRS-TABLE-MAX PIC 9(4) VALUE 64.
* Updated by the parsing routine…
05 PRS-NUMBER-OF-ITEMS PIC 9(4) VALUE 0.
05 PRS-LAST-SIG-BYTE PIC 9(4) VALUE 0.
05 PRS-OFFSET OCCURS 64 TIMES
PIC 9(4) VALUE 0.
05 PRS-LENGTH OCCURS 64 TIMES
PIC 9(4) VALUE 0.
To call the parsing routine (SIMOPARS) the fields for the pass area need to be initialized. The following shows an example of initializing the pass area fields and making the call to the parsing routine.
* Prepare control items for parsing.
MOVE '0' TO PRS-REQUEST
MOVE ' ' TO PRS-DELIMITER
MOVE 'N' TO PRS-TERMINATOR
MOVE ' ' TO PRS-TERMINATOR-BYTE
ADD 32 TO ZERO GIVING PRS-TABLE-MAX
ADD 128 TO ZERO GIVING PRS-BUFFER-SIZE
* Move the data string to the parsing buffer and call
* the parsing routine.
MOVE TASK-01-DATA TO PRS-BUFFER
CALL 'SIMOPARS' USING PRS-PARAMETERS
The following is a brief description of each of the fields used within the pass area (PRS-PARAMETERS).
| ||||||||||||||||||||||||||||||||
| Field Descriptions for PASSPARS.CPY (Pass Area for SIMOPARS) |
The following is the Windows Command file (CBLRMPE1.cmd) that is required to run as a job on a Windows System using Micro Focus Enterprise Server.
@echo OFF
rem * *******************************************************************
rem * CBLRMPE1.cmd - a Windows Command File *
rem * This program is 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 - COBOL doing text parsing with reference modification
rem * Author - SimoTime Technologies
rem * Date - November 11, 2003
rem * Version - 06.07.16
rem *
rem * This set of programs illustrate the use a COBOL program to use
rem * reference modification to parse a string of text by keyword.
rem *
rem * When running with Net Express the IBMCOMP an NOTRUNC directives
rem * will be required to maintain compatability with the mainframe
rem * format and field sizes for binary fields.
rem *
rem * This technique provides for the use of a single COBOL source
rem * program that will run on OS/390, Windows or Unix.
rem *
rem * This set of programs will run on a Personal Computer with Windows
rem * and Micro Focus Net Express.
rem *
rem * ************
rem * * CBLRMPE1 *
rem * ********cmd*
rem * *
rem * ************ ************ ************
rem * * call ******* SIMONOTE ******* CONSOLE *
rem * ********exe* ********cmd* * ************
rem * * *
rem * * * ************
rem * * **** SYSLOG *
rem * * *******data*
rem * *
rem * *
rem * ************ ************ ************
rem * * run ******* CBLRMPC1 ******* CONSOLE *
rem * ************ ********cbl* ************
rem * * *
rem * * *
rem * * ************
rem * * * SIMOPARS *
rem * * ********cbl*
rem * ************
rem * * EOJ *
rem * ************
rem *
rem * ********************************************************************
rem * Step 1 of 2 Set the global environment variables...
rem *
setlocal
call ..\Env1BASE
if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
set CmdName=CblRmpE1
rem *
call SimoNOTE "*******************************************************%CmdName%"
call SimoNOTE "Starting JobName %CmdName%"
rem * ********************************************************************
rem * Step 2 of 2 Execute the sample program...
rem *
run CblRmpC1
if ERRORLEVEL = 0 goto :EojAOK
set JobStatus=0010
goto :EojNOK
:EojAOK
call SimoNOTE "Finished JobName %CmdName%, Job Status is %JobStatus%"
goto :End
:EojNOK
call SimoNOTE "ABENDING JobName %CmdName%, Job Status is %JobStatus%"
goto :End
:End
call SimoNOTE "Conclude SysLog is %SYSLOG%"
if not "%1" == "nopause" pause
endlocal
The following is the JCL member (CBLRMPJ1.jcl) required to run this batch job on an IBM Mainframe System with ZOS or a Windows System with Micro Focus Enterprise Server. The JOB and DD statements will need to be modified for unique mainframe requirements.
//CBLRMPJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1, // COND=(0,LT) //* ******************************************************************* //* CBLRMPJ1.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 - COBOL calls COBOL for parsing of a data buffer. //* Author - SimoTime Technologies //* Date - January 01, 1989 //* //* This set of programs illustrates the use of COBOL for parsing //* a data string or field. //* //* This routine uses reference modification to identify the //* position of the first significant character after the //* delimiter character. This approach compensates for multiple //* leading or embedded delimiter characters. //* //* For example, if the delimiter character is a space then //* leading spaces will be ignored and multiple, embedded spaces //* will be treated as a single space. //* //* This set of programs will run on a mainframe under MVS or on a //* Personal Computer with Windows and Micro Focus Mainframe Express. //* //* ************ //* * CBLRMPJ1 * //* ********jcl* //* * //* * //* ************ ************ //* * CBLRMPC1 *-----* DISPLAY * //* ********cbl* ************ //* * * //* * * ************ //* * *-CALL--* SIMOPARS * //* * ********cbl* //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //* Step 1 of 1, This is a single step job. //* //CBLRMPX1 EXEC PGM=CBLRMPC1 //STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //SYSOUT DD SYSOUT=* //*
This program (CBLRMPC1.cbl) was written to test and demonstrate the calling of a COBOL program (SIMOPARS.cbl) that does the parsing of a field or data string.
IDENTIFICATION DIVISION.
PROGRAM-ID. CBLRMPC1.
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: CBLRMPC1.CBL
* Copy Files PASSPARS.CPY
* Calls to: SIMOPARS
*****************************************************************
*
* CBLRMPC1 - Call SIMOPARS to parse the buffer.
*
* CALLING PROTOCOL
* ----------------
* Use standard procedure to EXECUTE, RUN or ANIMATE.
*
* DESCRIPTION
* -----------
* This is a demonstration program to show how to call the
* COBOL Parsing Routine Routine.
*
* ************
* * CBLRMPJ1 *
* ********jcl*
* *
* *
* ************ ************
* * CBLRMPC1 *-----* CONSOLE *
* ********cbl* ******dsply*
* *
* *
* ************
* * SIMOPARS *
* ********cbl*
*
*****************************************************************
*
* MAINTENANCE
* -----------
* 1989/02/27 Simmons, Created program.
* 1997/03/17 Simmons, Updated for COBOL/2.
* 2002/09/23 Simmons, Added function to create a new field with
* leading spaces removed and embedded, multiple spaces
* reduced to a single space. The length of the output
* text string is also calculated.
*
*****************************************************************
*
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
*****************************************************************
* Data-structure for Title and Copyright...
* ------------------------------------------------------------
01 SIM-TITLE.
05 T1 pic X(11) value '* CBLRMPC1 '.
05 T2 pic X(34) value 'COBOL Parse a Data String '.
05 T3 pic X(10) value ' v03.12.02'.
05 T4 pic X(24) value ' http://www.simotime.com'.
01 SIM-COPYRIGHT.
05 C1 pic X(11) value '* CBLRMPC1 '.
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 '* CBLRMPC1 '.
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 '* CBLRMPC1 '.
05 C2 pic X(32) value 'Please send all inquires or sugg'.
05 C3 pic X(32) value 'estions to the helpdesk@simotime'.
05 C4 pic X(04) value '.com'.
*****************************************************************
* Buffer used for posting messages to the console.
* ------------------------------------------------------------
01 MESSAGE-BUFFER.
05 MESSAGE-HEADER pic X(11) value '* CBLRMPC1 '.
05 MESSAGE-TEXT pic X(245).
*****************************************************************
* Work fields used for testing call to SIMOPARS.
* ------------------------------------------------------------
01 IX-1 pic 9999 value 0.
01 IX-2 pic 9999 value 0.
* Simple parsing task...
01 TASK-01-DATA.
05 filler pic X(30) value 'This is a simple text string '.
* Used to parse using a slash (/) as the delimiter...
01 TASK-02-DATA.
05 filler pic X(10) value '01/24/2001'.
05 filler pic X(5) value is SPACES.
* Used to parse and handle the leading and/or embedded
* SPACE or multiple SPACES...
01 TASK-03-DATA.
05 filler pic X(07) value is SPACES.
05 filler pic X(30) value 'Text String with leading '.
05 filler pic X(30) value 'and multiple embedded '.
05 filler pic X(05) value is SPACES.
05 filler pic X(20) value 'SPACE characters '.
* Parse a larger data string...
01 TASK-04-DATA.
05 filler pic X(30) value ' The quick brown fox jumped '.
05 filler pic X(30) value 'over the lazy dogs back. Now '.
05 filler pic X(30) value 'is the time for all good men '.
05 filler pic X(30) value 'and women to come to the aid '.
05 filler pic X(30) value 'of the party. '.
05 filler pic X(30) value 'We have crossed the bridge and'.
05 filler pic X(30) value ' we are pushing the envelope'.
05 filler pic X(30) value ' to the top of the hill. '.
01 DATA-256 pic X(256) value SPACES.
01 WORK-256 pic X(256) value SPACES.
01 DATA-256-MESSAGE.
05 filler pic X(29) value 'Length of the output text is '.
05 DATA-256-LENGTH pic 9(4) value 0.
01 LAST-BYTE-BUFFER.
05 filler pic X(25) value 'Last significant byte is '.
05 LAST-BYTE pic 9(4) value 0.
COPY PASSPARS.
*****************************************************************
PROCEDURE DIVISION.
perform Z-POST-COPYRIGHT.
*! Do a simple parsing to identify the position and size
*! of words within an alphameric field.
perform SAMPLE-TASK-01.
*! Do a simple parsing to identify the position and size
*! of the mm, dd and ccyy within a date field.
perform SAMPLE-TASK-02.
*! Do the parsing to identify the position and size of the
*! words within an alphameric field. Also, create a new
*! field with the leading spaces removed and the embedded,
*! multiple spaces reduced to a single space.
perform SAMPLE-TASK-03.
*! Do the parsing to identify the position and size of the
*! words within an alphameric field. Also, create a new
*! field with the leading spaces removed and the embedded,
*! multiple spaces reduced to a single space. This is similar
*! to the preceding sample but parses a larger field.
perform SAMPLE-TASK-04.
perform Z-THANK-YOU.
GOBACK.
*****************************************************************
* Scan a data string and identify the starting position and
* length of each keyword in the string, The delimiter used for
* this task is a space character.
*****************************************************************
SAMPLE-TASK-01.
*! Display the start-of-task message.
move 'SAMPLE-TASK-01 is STARTING...' to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Display the input buffer.
move TASK-01-DATA to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Prepare control items for parsing.
move '0' to PRS-REQUEST
add 9 to ZERO giving PRS-STATUS
move ' ' to PRS-DELIMITER
* move 'N' to PRS-TERMINATOR-FLAG
move ' ' to PRS-TERMINATOR-BYTE
add 32 to ZERO giving PRS-TABLE-MAX
add 128 to ZERO giving PRS-BUFFER-SIZE
*! Move the data string to the parsing buffer and call
*! the parsing routine.
move TASK-01-DATA to PRS-BUFFER
call 'SIMOPARS' using PRS-PARAMETERS
*! Display the contents of the parsing tables.
add 1 to ZERO giving IX-1
perform until PRS-SIZE(IX-1) = 0
or PRS-POSITION(IX-1) = 0
or IX-1 > PRS-TABLE-MAX
perform Z-POST-TABLE-ITEM
add 1 to IX-1
end-perform
perform Z-POST-LAST-SIGNIFICANT-BYTE
*! Display the end-of-task message.
move 'SAMPLE-TASK-01 is COMPLETE...' to MESSAGE-TEXT
perform Z-POST-MESSAGE
exit.
*****************************************************************
* Scan a data string and identify the starting position and
* length of each keyword in the string, The delimiter used for
* this task is a slash (/) character.
* This example also uses a space character to terminate the
* parsing if the string.
*****************************************************************
SAMPLE-TASK-02.
*! Display the start-of-task message.
move 'SAMPLE-TASK-02 is STARTING...' to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Display the input buffer.
move TASK-02-DATA to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Prepare control items for parsing.
move '0' to PRS-REQUEST
add 9 to ZERO giving PRS-STATUS
move '/' to PRS-DELIMITER
* move 'Y' to PRS-TERMINATOR-FLAG
move ' ' to PRS-TERMINATOR-BYTE
add 32 to ZERO giving PRS-TABLE-MAX
add 128 to ZERO giving PRS-BUFFER-SIZE
*! Move the data string to the parsing buffer and call
*! the parsing routine.
move TASK-02-DATA to PRS-BUFFER
call 'SIMOPARS' using PRS-PARAMETERS
*! Display the contents of the parsing tables.
add 1 to ZERO giving IX-1
perform until PRS-SIZE(IX-1) = 0
or PRS-POSITION(IX-1) = 0
or IX-1 > PRS-TABLE-MAX
perform Z-POST-TABLE-ITEM
add 1 to IX-1
end-perform
perform Z-POST-LAST-SIGNIFICANT-BYTE
*! Display the end-of-task message.
move 'SAMPLE-TASK-02 is COMPLETE...' to MESSAGE-TEXT
perform Z-POST-MESSAGE
exit.
*****************************************************************
* Scan a data string and identify the starting position and
* length of each keyword in the string, The delimiter used for
* this task is a space character.
* The input data string in this task has leading and multiple,
* embedded spaces.
* The output data string has the leading spaces removed and the
* embedded multiple spaces are replaced with a single space.
*****************************************************************
SAMPLE-TASK-03.
*! Display the start-of-task message.
move 'SAMPLE-TASK-03 is STARTING...' to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Display the input buffer.
move 'Input with leading and embedded, multiple spaces...'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Display the input buffer.
move TASK-03-DATA to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Prepare control items for parsing.
move '0' to PRS-REQUEST
add 9 to ZERO giving PRS-STATUS
move ' ' to PRS-DELIMITER
* move 'N' to PRS-TERMINATOR-FLAG
move ' ' to PRS-TERMINATOR-BYTE
add 32 to ZERO giving PRS-TABLE-MAX
add 128 to ZERO giving PRS-BUFFER-SIZE
*! Move the data string to the parsing buffer and call
*! the parsing routine.
move TASK-03-DATA to PRS-BUFFER
call 'SIMOPARS' using PRS-PARAMETERS
*! Display the contents of the parsing tables.
add 1 to ZERO giving IX-1
perform until PRS-SIZE(IX-1) = 0
or PRS-POSITION(IX-1) = 0
or IX-1 > PRS-TABLE-MAX
perform Z-POST-TABLE-ITEM
add 1 to IX-1
end-perform
perform Z-POST-LAST-SIGNIFICANT-BYTE
*! Create and display the output buffer.
move 'Output w/o leading and embedded, multiple spaces...'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
move TASK-03-DATA to WORK-256
perform SAMPLE-TASK-99
move DATA-256-MESSAGE to MESSAGE-TEXT
perform Z-POST-MESSAGE
move DATA-256 to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Display the end-of-task message.
move 'SAMPLE-TASK-03 is COMPLETE...' to MESSAGE-TEXT
perform Z-POST-MESSAGE
exit.
*****************************************************************
* Scan a data string and identify the starting position and
* length of each keyword in the string, The delimiter used for
* this task is a space character.
* The input data string in this task has leading and multiple,
* embedded spaces.
* The output data string has the leading spaces removed and the
* embedded multiple spaces are replaced with a single space.
*****************************************************************
SAMPLE-TASK-04.
*! Display the start-of-task message.
move 'SAMPLE-TASK-04 is STARTING...' to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Display the input buffer.
move 'Input with leading and embedded, multiple spaces...'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Display the input buffer.
move TASK-04-DATA to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Prepare control items for parsing.
move '0' to PRS-REQUEST
add 9 to ZERO giving PRS-STATUS
move ' ' to PRS-DELIMITER
* move 'N' to PRS-TERMINATOR-FLAG
move ' ' to PRS-TERMINATOR-BYTE
add 64 to ZERO giving PRS-TABLE-MAX
add 240 to ZERO giving PRS-BUFFER-SIZE
*! Move the data string to the parsing buffer and call
*! the parsing routine.
move TASK-04-DATA to PRS-BUFFER
call 'SIMOPARS' using PRS-PARAMETERS
*! Display the contents of the parsing tables.
add 1 to ZERO giving IX-1
perform until PRS-SIZE(IX-1) = 0
or PRS-POSITION(IX-1) = 0
or IX-1 > PRS-TABLE-MAX
perform Z-POST-TABLE-ITEM
add 1 to IX-1
end-perform
perform Z-POST-LAST-SIGNIFICANT-BYTE
move TASK-04-DATA to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Create and display the output buffer.
move 'Output w/o leading and embedded, multiple spaces...'
to MESSAGE-TEXT
perform Z-POST-MESSAGE
move SPACES to WORK-256
move TASK-04-DATA to WORK-256
perform SAMPLE-TASK-99
move DATA-256-MESSAGE to MESSAGE-TEXT
perform Z-POST-MESSAGE
move DATA-256-MESSAGE to MESSAGE-TEXT
move DATA-256 to MESSAGE-TEXT
perform Z-POST-MESSAGE
*! Display the end-of-task message.
move 'SAMPLE-TASK-04 is COMPLETE...' to MESSAGE-TEXT
perform Z-POST-MESSAGE
exit.
*****************************************************************
* Build a new string with a single space between words and
* remove the leading spaces.
*****************************************************************
SAMPLE-TASK-99.
add 1 to ZERO giving IX-1
add 1 to ZERO giving IX-2
move SPACES to DATA-256
perform until PRS-SIZE(IX-1) = 0
or PRS-POSITION(IX-1) = 0
or IX-1 > PRS-TABLE-MAX
move WORK-256(PRS-POSITION(IX-1):PRS-SIZE(IX-1))
to DATA-256(IX-2:PRS-SIZE(IX-1))
add PRS-SIZE(IX-1) to IX-2
add 1 to IX-2
add 1 to IX-1
end-perform
if IX-2 > 1
subtract 2 from IX-2 giving DATA-256-LENGTH
else
add 1 to ZERO giving DATA-256-LENGTH
end-if
exit.
*****************************************************************
Z-POST-COPYRIGHT.
display SIM-TITLE
display SIM-COPYRIGHT
exit.
Z-POST-LAST-SIGNIFICANT-BYTE.
add PRS-LAST-SIG-BYTE to ZERO giving LAST-BYTE
move LAST-BYTE-BUFFER to MESSAGE-TEXT
perform Z-POST-MESSAGE
exit.
Z-POST-MESSAGE.
if MESSAGE-BUFFER(80:177) = SPACES
display MESSAGE-BUFFER(1:79)
move SPACES to MESSAGE-TEXT
else
display MESSAGE-BUFFER
move SPACES to MESSAGE-TEXT
end-if
exit.
Z-POST-TABLE-ITEM.
move 'Item-nnnn, Position-nnnn, Size-nnnn, Parameter - '
to MESSAGE-TEXT(1:49)
move IX-1 to MESSAGE-TEXT(6:4)
move PRS-POSITION(IX-1) to MESSAGE-TEXT(21:4)
move PRS-SIZE(IX-1) to MESSAGE-TEXT(32:4)
if PRS-SIZE(IX-1) < 20
move PRS-BUFFER(PRS-POSITION(IX-1):PRS-SIZE(IX-1))
to MESSAGE-TEXT(50:PRS-SIZE(IX-1))
else
move PRS-BUFFER(PRS-POSITION(IX-1):19)
to MESSAGE-TEXT(50:19)
end-if
perform Z-POST-MESSAGE
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 *
*****************************************************************
This program (SIMOPARS.cbl) was written to provide parsing capability of a data string. It uses "Reference Modification" to scan the data string.
This program provide very little visual information when it is executed on the mainframe. The real value of this program is observed when it is animated using Mainframe Express provided by Micro Focus. It is possible to watch the actual execution of each individual instruction and to immediately see the results.
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMOPARS.
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: SIMOPARS.CBL
* Copy Files PASSPARS.CPY
*****************************************************************
*
* SIMOPARS - Parse Buffer defined in pass area.
*
* CALLING PROTOCOL
* ----------------
* call 'SIMOPARS' using PRS-PARAMETERS
*
* 01 PRS-PARAMETERS.
* 05 PRS-REQUEST PIC X VALUE '0'.
* 05 PRS-STATUS PIC 9(4).
* 05 PRS-DELIMITER PIC X VALUE SPACE.
* 05 PRS-KEEP-NULL-FIELDS PIC X VALUE 'N'.
* 05 PRS-SUSPEND PIC X VALUE 'N'.
* 05 PRS-SUSPEND-BYTE PIC X VALUE SPACE.
* 05 PRS-TERMINATOR PIC X VALUE 'N'.
* 05 PRS-TERMINATOR-BYTE PIC X VALUE SPACE.
* 05 PRS-BUFFER-SIZE PIC 9(4) VALUE 2048.
* 05 PRS-BUFFER PIC X(2048).
* 05 PRS-TABLE-MAX PIC 9(4) VALUE 128.
* 05 PRS-NUMBER-OF-ITEMS PIC 9(4) VALUE 0.
* 05 PRS-LAST-SIG-BYTE PIC 9(4) VALUE 0.
* 05 PRS-POSITION OCCURS 128 TIMES
* PIC 9(4) VALUE 0.
* 05 PRS-SIZE OCCURS 128 TIMES
*
* This routine uses reference modification to identify the
* position of the first significant character after the
* delimiter character. This approach compensates for multiple
* leading or embedded delimiter characters. The string function
* of COBOL does not handle leading spaces.
*
* For example, if the delimiter character is a space then
* leading spaces will be ignored and multiple, embedded spaces
* will be treated as a single space.
*
* MAINTENANCE
* -----------
* 1998/01/02 Simmons, CREATED PROGRAM.
* 1998/01/02 Simmons, No changes to date...
*
*****************************************************************
*
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
*****************************************************************
* Data-structure for Program use... *
*****************************************************************
01 I-PTR pic 9(4) value 0.
01 O-PTR pic 9(4) value 0.
01 B-COUNT pic 9(4) value 0.
*****************************************************************
* Message Buffer used by the Z-DISPLAY-MESSAGE-TEXT routine. *
*****************************************************************
01 MESSAGE-BUFFER.
05 MESSAGE-HEADER pic X(11) value '* SIMOPARS '.
05 MESSAGE-TEXT.
10 MESSAGE-TEXT-1 pic X(68) value SPACES.
10 MESSAGE-TEXT-2 pic X(188) value SPACES.
*****************************************************************
LINKAGE SECTION.
COPY PASSPARS.
*****************************************************************
PROCEDURE DIVISION using PRS-PARAMETERS.
if PRS-REQUEST not = '2'
perform EDIT-LINKAGE-ITEMS
end-if
add 8 to ZERO giving RETURN-CODE
add 9 to ZERO giving PRS-STATUS
move ZERO to PRS-NUMBER-OF-ITEMS
evaluate PRS-REQUEST
when '0' perform PARSE-BUFFER
when '1' perform INITIALIZE-TABLE-ELEMENTS
when '2' perform INITIALIZE-DEFAULT-VALUES
when OTHER add 12 to ZERO giving PRS-STATUS
end-evaluate
if PRS-STATUS = 9
subtract PRS-STATUS from PRS-STATUS
end-if
GOBACK.
*****************************************************************
EDIT-LINKAGE-ITEMS.
if PRS-TABLE-MAX not numeric
add 128 to ZERO giving PRS-TABLE-MAX
move 'PRS-TABLE-MAX set to 128' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
end-if
if PRS-TABLE-MAX > 128
add 128 to ZERO giving PRS-TABLE-MAX
move 'PRS-TABLE-MAX set to 128' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
end-if
if PRS-BUFFER-SIZE not numeric
add 2048 to ZERO giving PRS-BUFFER-SIZE
move 'PRS-BUFFER-SIZE set to 2048' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
end-if
if PRS-BUFFER-SIZE > 2048
add 2048 to ZERO giving PRS-BUFFER-SIZE
move 'PRS-BUFFER-SIZE set to 2048' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
end-if
exit.
*****************************************************************
INITIALIZE-DEFAULT-VALUES.
move ',' to PRS-DELIMITER
move 'Y' to PRS-SPACE-TRUNCATION
move 'Y' to PRS-KEEP-NULL-FIELDS
add 128 to ZERO giving PRS-TABLE-MAX
add 2048 to ZERO giving PRS-BUFFER-SIZE
perform INITIALIZE-TABLE-ELEMENTS
move '0' to PRS-REQUEST
move ZERO to PRS-STATUS
move ZERO to PRS-NUMBER-OF-ITEMS
move ZERO to PRS-LAST-SIG-BYTE
exit.
*****************************************************************
INITIALIZE-TABLE-ELEMENTS.
move 1 to I-PTR
move 1 to O-PTR
perform until O-PTR > PRS-TABLE-MAX
move 0 to PRS-POSITION(O-PTR)
move 0 to PRS-SIZE(O-PTR)
add 1 to O-PTR
end-perform
subtract RETURN-CODE from RETURN-CODE
exit.
*****************************************************************
PARSE-BUFFER.
*! Initialize Position/Length tables to zero (0).
perform INITIALIZE-TABLE-ELEMENTS
move ZERO to PRS-LAST-SIG-BYTE
*! Parse the Buffer.
add 1 to ZERO giving O-PTR
perform until I-PTR > PRS-BUFFER-SIZE
perform PARSE-BUFFER-10
end-perform
* Wrap-up the parse of this buffer...
if PRS-LAST-SIG-BYTE > 0
and PRS-BUFFER(PRS-LAST-SIG-BYTE:1) not = PRS-DELIMITER
add 1 to PRS-NUMBER-OF-ITEMS
end-if
if PRS-POSITION(O-PTR) = 0
subtract 1 from O-PTR
end-if
subtract RETURN-CODE from RETURN-CODE
exit.
*---------------------------------------------------------------*
PARSE-BUFFER-10.
if PRS-BUFFER(I-PTR:1) not = SPACE
add I-PTR to ZERO giving PRS-LAST-SIG-BYTE
end-if
if PRS-BUFFER(I-PTR:1) = PRS-DELIMITER
add 1 to B-COUNT
if PRS-KEEP-NULL-FIELDS = 'Y'
or B-COUNT = 1
and PRS-SIZE(O-PTR) > 0
if O-PTR < PRS-TABLE-MAX
add 1 to O-PTR
add 1 to PRS-NUMBER-OF-ITEMS
else
move PRS-BUFFER-SIZE to I-PTR
end-if
end-if
else
subtract B-COUNT from B-COUNT
add 1 to PRS-SIZE(O-PTR)
if PRS-SIZE(O-PTR) = 1
move I-PTR to PRS-POSITION(O-PTR)
end-if
end-if
add 1 to I-PTR
if PRS-TERMINATOR = 'Y'
and I-PTR not > PRS-BUFFER-SIZE
and PRS-BUFFER(I-PTR:1) = PRS-TERMINATOR-BYTE
if PRS-SIZE(O-PTR) > 0
add 1 to PRS-NUMBER-OF-ITEMS
end-if
add PRS-BUFFER-SIZE to 1 giving I-PTR
end-if
exit.
*****************************************************************
* Display CONSOLE messages... *
*****************************************************************
Z-DISPLAY-MESSAGE-TEXT.
if MESSAGE-TEXT-2 = SPACES
display MESSAGE-BUFFER(1:79)
else
display MESSAGE-BUFFER
end-if
move all SPACES to MESSAGE-TEXT
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 copy file (PASSPARS.cpy) used for the pass area when calling the parsing routine.
*****************************************************************
* Data Structure or Pass Area used for calling SIMOPARS. *
*****************************************************************
* Copyright (C) 1987-2019 SimoTime Technologies *
* All Rights Reserved *
*****************************************************************
* Provided by SimoTime Technologies *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
* *
* PRS-REQUEST Type of request, must be zero (0) for *
* parsing. This item is provided by the *
* calling program and is not modified *
* by the parsing routine. *
* PRS-STATUS This is an indicator as to the success *
* or failure of the request. A value of *
* zero (0000) indicates the routine was *
* successful. A non-zero value indicates *
* a failure. *
* *
* ------------------------------------------------------------- *
* The following fields are provided by the calling routine. *
* *
* PRS-DELIMITER This is a one byte character that is *
* used as a delimiter. This item is *
* provided by the calling program and *
* is not modified by the parsing routine. *
* *
* PRS-KEEP-NULL-FIELDS This must be a Yes (Y) or No (N) value *
* (Y) will indicate a Yes, keep null field *
* (N) will indicate a No and null fields *
* will be dropped. *
* PRS-TERMINATOR This must be a Yes (Y) or No (N) value *
* to indicate a character that will be *
* used for termination of the parsing. *
* If (Y) then the next parameter is used *
* as a termination character. If (N) the *
* buffer will be parsed according to the *
* size of the buffer or maximum number *
* of table entries. This item is provided *
* by the calling program and is not *
* modified by the parsing routine. *
* PRS-TERMINATOR-BYTE If the previous parameter is (Y) this *
* byte will be used to terminate the *
* parsing when it is encountered in the *
* data string. This item is provided by *
* the calling program and is not modified *
* by the parsing routine. *
* *
* PRS-BUFFER-SIZE The size of the data string to be *
* parsed and must be a value of 1-1024. *
* This item is provided by the calling *
* program and is not modified by the *
* parsing routine. *
* PRS-BUFFER This is the data string or field that *
* will be parsed. This item is provided *
* by the calling program and is not *
* modified by the parsing routine. *
* *
* PRS-TABLE-MAX The maximum number of table entries *
* available for the POSITION/SIZE values *
* of the words in the input buffer. *
* This item is provided by the calling *
* program and is not modified by the *
* parsing routine. *
* *
* ------------------------------------------------------------- *
* The following fields are updated by the parsing routine. *
* *
* PRS-NUMBER-OF-ITEMS This is the number of keywords found *
* in the input data string. This item is *
* provided by the parsing routine. *
* *
* PRS-LAST-SIG-BYTE This is the position of the last *
* significant, non-delimiter byte. If the *
* PRS-TERMINATOR is "Y" this will be the *
* last significant byte before the *
* terminator byte. *
* *
* PRS-POSITION This is a table of 64 elements of *
* 4-bytes. The value is either zero (0) *
* or the position of a keyword within the *
* input data string. The first position *
* within the buffer is one (1). *
* This item is provided by the parsing *
* routine. *
* PRS-SIZE This is a table of 64 elements of *
* 4-bytes. The value is either zero (0) *
* or the size of a keyword within the *
* input data string. This item is provided *
* by the parsing routine. *
* *
* ------------------------------------------------------------- *
* NOTE... The table element number is the number *
* of the word within the data buffer. *
* The data buffer is PRS-BUFFER. *
* For example, PRS-POSITION(1) would point *
* to the position of the first character *
* of the first word in the data buffer *
* PRS-SIZE(1) would specify the number of *
* characters in the first word. *
* *
*****************************************************************
01 PRS-PARAMETERS.
05 PRS-REQUEST PIC X.
05 PRS-STATUS PIC 9(4).
*** Provided by the calling program...
05 PRS-DELIMITER PIC X.
05 PRS-KEEP-NULL-FIELDS PIC X.
05 PRS-TERMINATOR PIC X.
05 PRS-TERMINATOR-BYTE PIC X.
05 PRS-SPACE-TRUNCATION PIC X.
05 PRS-BUFFER-SIZE PIC 9(4).
05 PRS-BUFFER PIC X(2048).
05 PRS-TABLE-MAX PIC 9(4).
*** Updated by the parsing routine...
05 PRS-NUMBER-OF-ITEMS PIC 9(4).
05 PRS-LAST-SIG-BYTE PIC 9(4).
05 PRS-POSITION OCCURS 128 TIMES
PIC 9(4).
05 PRS-SIZE OCCURS 128 TIMES
PIC 9(4).
*** PASSPARS - End-of-Copy File - - - - - - - - - - - PASSPARS *
*****************************************************************
*
This suite of programs will describe how to parse a data string using COBOL. This document may be used to assist as a tutorial for new programmers or as a quick reference for experienced programmers.
In the world of programming there are many ways to solve a problem. This 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.
Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.
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 connect.
This suite of programs and documentation is available for download. Link to an Evaluation zPAK Option that includes the program members, documentation and control files.
A good place to start is The SimoTime Home Page 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 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 |
| COBOL Parsing Routine using Reference Modification |
| Copyright © 1987-2025 SimoTime Technologies and Services All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |