Logical OR Function Boolean Logic using COBOL |
The SimoTime Home Page |
This suite of programs is provided as a COBOL programming example of one of the possible solutions when performing Boolean logic. The AND, OR and NOT are the primary operations of Boolean logic. The XOR is a permutation of the primary operations of Boolean logic. This Test Case will focus on the Logical OR Function.
This document will focus on the Logical OR Function and is one of a suite of Logical Operator Routines.
| ||||||
The Three Logical Operations provided by SimoTime |
This test case uses a driver program to call the Logical OR routine that does the Logical OR function. This example contains one JCL member to execute the two COBOL programs. The main COBOL program (LORORRC1.CBL) is used to demonstrate and test the Logical OR functions. The Logical OR function is in a separate, callable COBOL program (STORRPGM.CBL). Both COBOL programs were written and tested using the Enterprise COBOL dialect. Both COBOL programs will work with COBOL for MVS or COBOL/370 and are ANSI/85 compliant. A JCL member is provided to run the job as an MVS batch job on an IBM Mainframe System running ZOS or Linux, UNIX or Windows (LUW) System running Micro Focus Enterprise Server. A Windows command file is provided to run the job on a Windows System using Micro Focus COBOL technology.
In the world of programming there are many ways to solve a problem. This suite of programs is provided as a COBOL programming example of one of the possible solutions to performing a Logical OR function. This example may serve as a tutorial for new programmers and as a reference for experienced programmers. Additional information (including the original Assembler routine that does the logical OR function) is provided in the Downloads and Links to Similar Pages section of this document.
This type of Boolean logic and bit manipulation is quite often considered something that cannot be done using COBOL. Many years ago I was asked to provide a mainframe assembler routine to perform a Logical OR function using two user-defined data strings. I delivered the callable routine and was well paid for the task. However, something the client said bothered me, "I have been told this cannot be done in COBOL."
I have heard this statement many times over the years 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.
Boolean logic is possible using COBOL. An assembler routine or the use of a language extension is not required. This capability allows a single source string to be used when moving an application between a Mainframe System and a Linux, UNIX or Windows (LUW) System. The LUW environments will require Micro Focus Enterprise Developer.
Note: Refer to the Download and Links to Similar Pages section of this document for links to additional documents that discuss this topic.
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 requires three (3) parameters, two data strings and a length value.
This section illustrates a logical OR function using two data strings with a length of one (1) byte. The following shows the data structures that are passed to the logical OR routine.
01 ORR-ONE-BYTE-STRUCTURE. 05 ORR-SOURCE-A-01 pic X value LOW-VALUE. 05 ORR-TARGET-A-01 pic X value LOW-VALUE. 05 ORR-LENGTH-A-01 pic 9(4) COMP value 0. . . . . . . The following shows the call to the logical OR routine. . . . . . . add 1 to ZERO giving OR-LENGTH-A-01 move 'A' to ORR-SOURCE-A-01 move X'02' to ORR-TARGET-A-01 call 'STORRPGM' using ORR-SOURCE-A-01 ORR-TARGET-A-01 ORR-LENGTH-A-01
The preceding snippet of code will use the logical OR function to convert the character "A" to be a character "C".
This section illustrates a logical OR function using two data strings with a length of ten (10) digits. The following shows the data structures that are passed to the logical OR routine.
01 NBR-0-9 pic 9(10) value 0123456789. 01 MASK-X-01 pic X(10) value X'01010101010101010101'. . . . . . . The following shows the call to the logical OR routine. . . . . . . Add 10 to ZERO giving XOR-LENGTH-A-01 call 'STORRPGM' using NBR-0-9 MASK-X-01 ORR-LENGTH-A-01
The preceding snippet of code uses a logical OR function to convert an even-value number to the next higher odd-number value. The input of "0123456789" will be converted to "1133557799".
The following is the Windows Command file (LORORRW1.cmd) that is required to run as a job on a Linux, UNIX or Windows System using Micro Focus COBOL Technology.
@echo OFF rem * ******************************************************************* rem * LORORRW1.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 - Test Case for OR Logical Operator Routine. rem * Author - SimoTime Technologies rem * Date - December 15, 2016 rem * rem * This set of programs illustrates the use a COBOL program to do rem * a logical AND function. rem * rem * ************ rem * * LORORRW1 * rem * ********cmd* rem * * rem * * rem * ************ ************ rem * * LORORRC1 *------* SYSOUT * rem * ********cbl* ************ rem * * * rem * * * ************ rem * * *--call--* STORRPGM * rem * * ********cbl* rem * * rem * ************ rem * * EOJ * rem * ************ rem * rem * ******************************************************************* rem * Step 1, Prepare the Environment... rem * set CmdName=LORORRW1 call ..\ENV1BASE %CmdName% if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG set JobStatus=0000 rem * call SimoNOTE "*******************************************************%CmdName%" call SimoNOTE "Starting JobName %CmdName%" rem * rem * ******************************************************************* rem * Step 2, Execute the Test Program for a logical OR... call SimoNOTE "Continue JobName %CmdName% Execute the OR Test Program" run LORORRC1 if not ERRORLEVEL = 0 set JobStatus=0010 if not %JobStatus% == 0000 goto :EojNok rem * rem * ******************************************************************* rem * Step 3, End-of-Job Processing... :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 "%1" == "nopause" pause
The following is the mainframe JCL member (LORORRJ1.jcl) that is required to run as a job on an IBM Mainframe System using ZOS or a Linux, UNIX or Windows System using Micro Focus COBOL Technology.
//LORORRJ1 JOB SIMOTIME,'CBL BIT MANIPULATE',CLASS=1,MSGCLASS=0, // NOTIFY=CSIP1 //* ******************************************************************* //* LORORRJ1.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 Logical OR Function //* Author - SimoTime Technologies //* Date - January 01, 1989 //* //* This set of programs illustrates the use a COBOL program to do //* a Logical OR function. //* //* The DD statement for SYSOUT is required by this example. The //* COBOL program may be compiled using the SYSOUT directive and //* without the DD statement for SYSOUT an RTS173 or RTS227 may occur. //* //* 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 Developer. //* //* ************ //* * LORORRJ1 * //* ********jcl* //* * //* * //* ************ ************ //* * LORORRC1 *------* SYSOUT * //* ********cbl* ************ //* * * //* * * ************ //* * *--call--* STORRPGM * //* * ********cbl* //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //* Step 1 of 1, This is a single step job. //* //CBLBITS1 EXEC PGM=LORORRC1 //STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //SYSOUT DD SYSOUT=* //*
There are two (2) COBOL members in this suite of programs, a mainline (or driver) program and a callable routine that does the XOR function.
This program (LORORRC1.cbl) was written to test the callable program (STXORPGM) that does the Exclusive OR (XOR) Function
IDENTIFICATION DIVISION. PROGRAM-ID. LORORRC1. AUTHOR. SIMOTIME TECHNOLOGIES. ***************************************************************** * SOURCE MODULE LORORRC1.CBL ***************************************************************** * LORORRC1 - Driver program, a logical OR Function Test. * * DESCRIPTION * ----------- * This program will do a logical OR of two data strings. * * This program is one of a suite of Logical Operator Routines. * LORANDC1 calls STANDPGM to perform a logical AND Function. * LORORRC1 calls STORRPGM to perform a logical OR Function. * LORXORC1 calls STXORPGM to perform an Exclusive OR Function. * ***************************************************************** * MAINTENANCE * ----------- * 1999/03/89 SimoTime, Created program. * 1999/03/89 SimoTime, No changes to date. * ***************************************************************** ENVIRONMENT DIVISION. ***************************************************************** DATA DIVISION. WORKING-STORAGE SECTION. ***************************************************************** * Data-structure for Title and Copyright... * ------------------------------------------------------------ 01 SIM-TITLE. 05 T1 pic X(11) value '* LORORRC1 '. 05 T2 pic X(34) value 'Test Case for logical OR Function '. 05 T3 pic X(10) value ' v08.06.05'. 05 T4 pic X(24) value ' http://www.simotime.com'. 01 SIM-COPYRIGHT. 05 C1 pic X(11) value '* LORORRC1 '. 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 ORR-ONE-BYTE-STRUCTURE. 05 ORR-SOURCE-A-01 pic X value LOW-VALUE. 05 ORR-TARGET-A-01 pic X value LOW-VALUE. 05 ORR-LENGTH-A-01 pic 9(4) COMP value 0. 01 NBR-0-9 pic 9(10) value 0123456789. 01 MASK-X-01 pic X(10) value X'01010101010101010101'. ***************************************************************** PROCEDURE DIVISION. perform POST-STARTUP-INFO-TO-SYSOUT perform TEST-CASE-01 perform TEST-CASE-02 display '* LORORRC1 Complete RC=' RETURN-CODE upon console display '* LORORRC1 Complete RC=' RETURN-CODE GOBACK. ***************************************************************** TEST-CASE-01. * A simple logical OR using single-byte data strings. * * ORR-SOURCE-A-01 ORR-TARGET-A-01 * Before ASC 01000001 00000010 * After ASC 01000001 01000011 * Before EBC 11000001 00000010 * After EBC 11000001 11000011 * add 1 to ZERO giving ORR-LENGTH-A-01 move 'A' to ORR-SOURCE-A-01 move X'02' to ORR-TARGET-A-01 call 'STORRPGM' using ORR-SOURCE-A-01 ORR-TARGET-A-01 ORR-LENGTH-A-01 display ORR-SOURCE-A-01 '-' ORR-TARGET-A-01 exit. ***************************************************************** TEST-CASE-02. * Use the logical OR for each byte of a data string. * * =NBR-0-9== ======MASK-X-01===== * Before 0123456789 X'01010101010101010101' * After 0123456789 0000000000 * After, ASC X'30313233343536373839' X'01010101010101010101' * After, EBC X'F0F1F2F3F4F5F6F7F8F9' X'01010101010101010101' * display NBR-0-9 " - X'01010101010101010101'" add 10 to ZERO giving ORR-LENGTH-A-01 call 'STORRPGM' using NBR-0-9 MASK-X-01 ORR-LENGTH-A-01 display NBR-0-9 ' - ' MASK-X-01 exit. ***************************************************************** POST-STARTUP-INFO-TO-SYSOUT. display SIM-TITLE display SIM-COPYRIGHT exit.
The original version of this program (STORRPGM) was created on an IBM Mainframe System and was written in IBM Assembler/H and later recompiled using HLASM. A replacement program was required when it was necessary to move a segment of a business application to a Windows System.
The requirement was to use a single source code base for a version of the application segment would compile and execute on an IBM Mainframe System and a Linux, UNIX or Windows (LUW) System. The LUW environment would require Micro Focus COBOL technology.
The HLASM version of the XOR program was re-written in COBOL and complies with the ANSI/85 standard and has been compiled and executed using various COBOL compilers with various dialects (OS/390, Enterprise COBOL and more).
For additional information about this program please call or send an e-mail to: helpdesk@simotime.com
This suite of programs is provided as a COBOL programming example of one of the possible solutions when performing Boolean logic. This Test Case will perform an Logical OR Function. 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 Bit Manipulation using a COBOL program calling COBOL to do the accessing of individuals bits within a byte.
Explore Bit Manipulation using a COBOL program calling Assembler to do the accessing of individuals bits within a byte.
Explore How to do a logical AND Function using a COBOL program that calls a COBOL routine to do the actual logical AND of two data strings.
Explore How to do an Exclusive OR (XOR) using a COBOL program that calls a COBOL routine to do the actual XOR of two data strings.
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.
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 |
Logical OR using COBOL |
Copyright © 1987-2025 SimoTime Technologies and Services All Rights Reserved |
When technology complements business |
http://www.simotime.com |