Parse a Data String SimoPARS - The COBOL Source Code |
The SimoTime Home Page |
This document provides a listing of the COBOL source code for viewing. Additional information about this program may be obtained by sending an e-mail to: helpdesk@simotime.com
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-2024
SimoTime Technologies and Services
All Rights Reserved
The SimoPARS routine (or callable program) will read a data string from left-to-right and based on a user defined delimiter byte it will identify the starting position and size of each field (or sub-string) within the data string.
The following is a snippet of code that shows how to use the SimoPARS callable program.
* 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 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). For a detailed description of the pass area refer to the COBOL Copy File section of this document that defines the structure of the pass area.
| ||||||||||||||||||||||||||||||||
A Brief Description of each of the Fields Used within the Pass Area |
The following member (SIMOPARS.cbl) is the COBOL Source Code.
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 member (PASSPARS.cpy) is the COBOL copy file that may be used when calling SimoPARS.
***************************************************************** * 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 document describes a COBOL programming technique for scanning a data buffer and identifying smaller text strings (based on a user-defined delimiter character) within the data buffer. The output of the scan will produce a set of arrays that show the starting position and size of each text string within the data buffer. 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, Comment 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 a complete list of the SimoTime Callable Routines or Utility Programs. This includes the callable routines and utility programs for the Micro Focus environment.
Explore an Extended List of Software Technologies that are available for review and evaluation. The software technologies (or Z-Packs) provide individual programming examples, documentation and test data files in a single package. The Z-Packs are usually in zip format to reduce the amount of time to download.
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 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 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 |
Parse a Data String using COBOL Reference Modification |
Copyright © 1987-2024 SimoTime Technologies and Services All Rights Reserved |
When technology complements business |
http://www.simotime.com |