Logical AND Function
Boolean Logic using COBOL
  Table of Contents  v-24.01.01 – lorand01.htm 
  Introduction
  Call Interface
  AND of Single Byte Data Strings
  AND of Data Strings
  The CMD Member
  The JCL Member
  COBOL Source Members
  Driver Program
  AND Callable Routine
  Summary
  Software Agreement and Disclaimer
  Downloads and Links
  Current Server or Internet Access
  Internet Access Required
  Glossary of Terms
  Contact or Feedback
  Company Overview
The SimoTime Home Page 

Table of Contents Previous Section Next Section Introduction

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 AND Function.

This document will focus on the logical AND Function and is one of a suite of Logical Operator Routines.

1 LORANDC1 calls STANDPGM to perform a logical AND Function.
2 LORORRC1 calls STORRPGM to perform a logical OR Function.
3 LORXORC1 calls STXORPGM to perform an Exclusive OR Function.
  The Three Logical Operations provided by SimoTime

This test case uses a driver program to call the logical AND routine that does the logical AND function. This example contains one JCL member to execute the two COBOL programs. The main COBOL program (LORANDC1.CBL) is used to demonstrate and test the logical AND functions. The logical AND function is in a separate, callable COBOL program (STANDPGM.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 an XOR 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 XOR 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 AND 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 capabilty 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-2024
SimoTime Technologies and Services
All Rights Reserved

Table of Contents Previous Section Next Section Call Interface

The callable interface requires three (3) parameters, two data strings and a length value.

Table of Contents Previous Section Next Section AND of Single Byte Data Strings

This section illustrates a logical AND function using two data strings with a length of one (1) byte. The following shows the data structures that are passed to the logical AND routine.

       01  AND-ONE-BYTE-STRUCTURE.
           05  AND-SOURCE-A-01     pic X       value LOW-VALUE.
           05  AND-TARGET-A-01     pic X       value LOW-VALUE.
           05  AND-LENGTH-A-01     pic 9(4)    COMP  value 0.
           . . .
           . . .
           The following shows the call to the AND routine.
           . . .
           . . . 
           add 1 to ZERO giving AND-LENGTH-A-01
           Move '3'   to AND-SOURCE-A-01
           move X'FD' to AND-TARGET-A-01
           call 'STANDPGM' using AND-SOURCE-A-01
                                 AND-TARGET-A-01
                                 AND-LENGTH-A-01

The preceding snippet of code will use the logical AND function to convert the digit "3" to be a digit "1".

Table of Contents Previous Section Next Section AND of Data Strings

This section illustrates a logical AND function using two data strings with a length of ten (10) digits. The following shows the data structures that are passed to the logical AND routine.

       01  NBR-0-9     pic 9(10) value 0123456789.
       01  MASK-X-F0   pic X(10) value X'F0F0F0F0F0F0F0F0F0F0'.
           . . .
           . . .
           The following shows the call to the logical AND routine.
           . . .
           . . . 
           Add 10 to ZERO giving XOR-LENGTH-A-01
           call 'STANDPGM' using NBR-0-9 MASK-X-F0 AND-LENGTH-A-01

The preceding snippet of code will use the logical AND function to force a data string of digits to all zeroes.

Table of Contents Previous Section Next Section The CMD Member

The following is the Windows Command file (LORANDW1.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  *               LORANDW1.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 AND 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  *   * LORANDW1 *
rem  *   ********cmd*
rem  *        *
rem  *        *
rem  *   ************      ************
rem  *   * LORANDC1 *------*  SYSOUT  *
rem  *   ********cbl*      ************
rem  *        *   *
rem  *        *   *        ************
rem  *        *   *--call--* STANDPGM *
rem  *        *            ********cbl*
rem  *        *
rem  *   ************
rem  *   *   EOJ    *
rem  *   ************
rem  *
rem  * *******************************************************************
rem  * Step 1, Prepare the Environment...
rem  *
     set CmdName=LORANDW1
     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 AND...
     call SimoNOTE "Continue JobName %CmdName% Execute the AND Test Program"
     run LORANDC1
     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

Table of Contents Previous Section Next Section The JCL Member

The following is the mainframe JCL member (LORANDJ1.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.

//LORANDJ1 JOB SIMOTIME,'CBL BIT MANIPULATE',CLASS=1,MSGCLASS=0,
//             NOTIFY=CSIP1
//* *******************************************************************
//*       LORANDJ1.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 AND Function
//* Author - SimoTime Technologies
//* Date   - January 01, 1989
//*
//* This set of programs illustrates the use a COBOL program to do
//* a Logical AND 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.
//*
//*   ************
//*   * LORANDJ1 *
//*   ********jcl*
//*        *
//*        *
//*   ************      ************
//*   * LORANDC1 *------*  SYSOUT  *
//*   ********cbl*      ************
//*        *   *
//*        *   *        ************
//*        *   *--call--* STANDPGM *
//*        *            ********cbl*
//*        *
//*   ************
//*   *   EOJ    *
//*   ************
//*
//* *******************************************************************
//* Step 1 of 1, This is a single step job.
//*
//CBLBITS1 EXEC PGM=LORANDC1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//SYSOUT   DD  SYSOUT=*
//*

Table of Contents Previous Section Next Section COBOL Source Members

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.

Table of Contents Previous Section Next Section Driver Program

This program (LORANDC1.cbl) was written to test the callable program (STANDPGM) that does the logical AND Function

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    LORANDC1.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      * SOURCE MODULE LORANDC1.CBL
      *****************************************************************
      * LORANDC1 - Driver program, logical AND Function Test.
      *
      * DESCRIPTION
      * -----------
      * This program will do a logical AND 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 '* LORANDC1 '.
           05  T2 pic X(34) value 'Test Case for logical AND 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 '* LORANDC1 '.
           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  AND-ONE-BYTE-STRUCTURE.
           05  AND-SOURCE-A-01     pic X       value LOW-VALUE.
           05  AND-TARGET-A-01     pic X       value LOW-VALUE.
           05  AND-LENGTH-A-01     pic 9(4)    COMP  value 0.

       01  NBR-0-9     pic 9(10) value 0123456789.
       01  MASK-X-F0   pic X(10) value X'F0F0F0F0F0F0F0F0F0F0'.

      *****************************************************************
       PROCEDURE DIVISION.
           perform POST-STARTUP-INFO-TO-SYSOUT

           perform TEST-CASE-01
           perform TEST-CASE-02

           display '* LORANDC1 Complete RC=' RETURN-CODE upon console
           display '* LORANDC1 Complete RC=' RETURN-CODE

           GOBACK.

      *****************************************************************
       TEST-CASE-01.
      *    A simple logical AND using single-byte data strings.
      *
      *                AND-SOURCE-A-01   AND-TARGET-A-01
      *    Before ASC      00110011          11111101
      *    After  ASC      00110011          00110001
      *    Before EBC      11110011          11111101
      *    After  EBC      11110011          11110001
      *
           add 1 to ZERO giving AND-LENGTH-A-01
           move '3'   to AND-SOURCE-A-01
           move X'FD' to AND-TARGET-A-01

           call 'STANDPGM' using AND-SOURCE-A-01
                                 AND-TARGET-A-01
                                 AND-LENGTH-A-01

           display AND-SOURCE-A-01 '-' AND-TARGET-A-01
           exit.

      *****************************************************************
       TEST-CASE-02.
      *    Use the logical AND function to force a data string of
      *    digits to all zeroes.
      *
      *              =NBR-0-9==                ======MASK-X-F0=====
      *  Before      0123456789                X'F0F0F0F0F0F0F0F0F0F0'
      *  After       0123456789                0000000000
      *  After, ASC  X'30313233343536373839'   X'30303030303030303030'
      *  After, EBC  X'F0F1F2F3F4F5F6F7F8F9'   X'F0F0F0F0F0F0F0F0F0F0'
      *
           display NBR-0-9 " - X'F0F0F0F0F0F0F0F0F0F0'"
           add 10 to ZERO giving AND-LENGTH-A-01

           call 'STANDPGM' using NBR-0-9 MASK-X-F0 AND-LENGTH-A-01

           display NBR-0-9 ' - ' MASK-X-F0
           exit.

      *****************************************************************
       POST-STARTUP-INFO-TO-SYSOUT.
           display SIM-TITLE
           display SIM-COPYRIGHT
           exit.

Table of Contents Previous Section Next Section AND Callable Routine

The original version of this program (STANDPGM) 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 that 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 AND 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

Table of Contents Previous Section Next Section Summary

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 a logical AND 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.

Table of Contents Previous Section Next Section 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.

Table of Contents Previous Section Next Section Downloads and Links

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.

Table of Contents Previous Section Next Section Current Server or Internet Access

The following links may be to the current server or to the Internet.

Link to Internet   Link to Server   Explore Bit Manipulation using a COBOL program calling COBOL to do the accessing of individuals bits within a byte.

Link to Internet   Link to Server   Explore Bit Manipulation using a COBOL program calling Assembler to do the accessing of individuals bits within a byte.

Link to Internet   Link to Server   Explore How to do a logical OR Function using a COBOL program that calls a COBOL routine to do the actual logical OR of two data strings.

Link to Internet   Link to Server   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.

Link to Internet   Link to Server   Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.

Link to Internet   Link to 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.

Link to Internet   Link to Server   Explore The File Status Return Codes that are used to interpret the results of accessing VSAM data sets and/or QSAM files.

Table of Contents Previous Section Next Section Internet Access Required

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.

Table of Contents Previous Section Next Section Glossary of Terms

Link to Internet   Link to Server   Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.

Table of Contents Previous Section Next Section Contact or Feedback

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.

Table of Contents Previous Section Next Section Company Overview

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 AND using COBOL
Copyright © 1987-2024
SimoTime Technologies and Services
All Rights Reserved
When technology complements business
http://www.simotime.com