COBOL Numeric Edits
Edit or Scan a Numeric Field
  Table of Contents  v-16.01.01 - cblnum01.htm 
  Introduction
  Job Scripts
  Windows Command File
  JCL Member
  The COBOL Program
  Summary
  Software Agreement and Disclaimer
  Downloads and Links
  Current Server or Internet Access
  Internet Access Required
  Glossary of Terms
  Comments or Feedback
  Company Overview
The SimoTime Home Page 

Table of Contents Previous Section Next Section Introduction

This is an example of how COBOL can test that a data field contains a valid numeric value. It also illustrates how to redefine a numeric field and then scan the field from left to right testing for a digit in each position. The following is output from the sample demonstration program. The following shows the contents of the field, the type of test (i.e. Alphamerical, Numeric or Signed) and the results.


* CBLNUMC1 Test or Scan a Numeric Field       v12.06.06 http://www.simotime.com
* CBLNUMC1 Copyright 1987-2012 --- SimoTime Enterprises --- All Rights Reserved
* CBLNUMC1 *
* CBLNUMC1 *---------------------------------------------------------------*
* CBLNUMC1 * Starting Example-01, Field contains all digits
* CBLNUMC1 * Simple Numeric Check is Starting
* CBLNUMC1 0000000000000001 Test Alphameric...Content Numeric...
* CBLNUMC1 0000000000000001 Test Numeric......Content Numeric...
* CBLNUMC1 0000000000000001 Test Signed.......Numeric and Positive value...
* CBLNUMC1 * Simple Numeric Check is Finished
* CBLNUMC1 *
* CBLNUMC1 * Finished Example-01, Field contains all digits
* CBLNUMC1 *
* CBLNUMC1 *---------------------------------------------------------------*
* CBLNUMC1 * Starting Example-02, Field contains leading spaces
* CBLNUMC1 * Simple Numeric Check is Starting
* CBLNUMC1              123 Test Alphameric...Content NOT Numeric...
* CBLNUMC1              123 Test Numeric......Content NOT Numeric...
* CBLNUMC1              123 Test Signed.......Content NOT Numeric...
* CBLNUMC1 * Simple Numeric Check is Finished
* CBLNUMC1 *
* CBLNUMC1 * Finished Example-02, Field contains leading spaces
* CBLNUMC1 *
* CBLNUMC1 *---------------------------------------------------------------*
* CBLNUMC1 * Starting Example-03, Sign in zone of units position
* CBLNUMC1 * Simple Numeric Check is Starting
* CBLNUMC1 0000000000000001 Test Alphameric...Content Numeric...
* CBLNUMC1 0000000000000001 Test Numeric......Content Numeric...
* CBLNUMC1 0000000000000001 Test Signed.......Numeric and Positive value...
* CBLNUMC1 * Simple Numeric Check is Finished
* CBLNUMC1 *
* CBLNUMC1 * Finished Example-03, Sign in zone of units position
* CBLNUMC1 *
* CBLNUMC1 *---------------------------------------------------------------*
* CBLNUMC1 * Starting Example-04, Sign in zone of units position
* CBLNUMC1 * Simple Numeric Check is Starting
* CBLNUMC1 000000000000000q Test Alphameric...Content NOT Numeric...
* CBLNUMC1 000000000000000q Test Numeric......Content NOT Numeric...
* CBLNUMC1 000000000000000q Test Signed.......Numeric and Negative value...
* CBLNUMC1 * Simple Numeric Check is Finished
* CBLNUMC1 *
* CBLNUMC1 * Finished Example-04, Sign in zone of units position
* CBLNUMC1 *
* CBLNUMC1 *---------------------------------------------------------------*
* CBLNUMC1 * Starting Example-05, Sign in zone of units position
* CBLNUMC1 * Simple Numeric Check is Starting
* CBLNUMC1 0000000000000000 Test Alphameric...Content Numeric...
* CBLNUMC1 0000000000000000 Test Numeric......Content Numeric...
* CBLNUMC1 0000000000000000 Test Signed.......Numeric and Zero value...
* CBLNUMC1 * Simple Numeric Check is Finished
* CBLNUMC1 *
* CBLNUMC1 * Scan for Digits is Starting...
* CBLNUMC1 0000000000000001 Scan for Digits...Content ALL Digits... 016 Y
* CBLNUMC1 * Scan for Digits is Finished...
* CBLNUMC1 *
* CBLNUMC1 * Scan for Digits is Starting...
* CBLNUMC1              123 Scan for Digits...Content NOT Digits... 001 N
* CBLNUMC1 * Scan for Digits is Finished...
* CBLNUMC1 *
* CBLNUMC1 * Scan for Digits is Starting...
* CBLNUMC1 123              Scan for Digits...Content NOT Digits... 004 N
* CBLNUMC1 * Scan for Digits is Finished...
* CBLNUMC1 *
* CBLNUMC1 * Scan for Digits is Starting...
* CBLNUMC1 000000000000000A Scan for Digits...Content NOT Digits... 016 N
* CBLNUMC1 * Scan for Digits is Finished...
* CBLNUMC1 *
* CBLNUMC1 * Scan for Digits is Starting...
* CBLNUMC1 0123456789ABCDEF Scan for Digits...Content NOT Digits... 011 N
* CBLNUMC1 * Scan for Digits is Finished...
* CBLNUMC1 *
* CBLNUMC1 * Access each byte of a field
* CBLNUMC1 0123456789ABCDEF Position 001 is - 0
* CBLNUMC1 0123456789ABCDEF Position 002 is - 1
* CBLNUMC1 0123456789ABCDEF Position 003 is - 2
* CBLNUMC1 0123456789ABCDEF Position 004 is - 3
* CBLNUMC1 0123456789ABCDEF Position 005 is - 4
* CBLNUMC1 0123456789ABCDEF Position 006 is - 5
* CBLNUMC1 0123456789ABCDEF Position 007 is - 6
* CBLNUMC1 0123456789ABCDEF Position 008 is - 7
* CBLNUMC1 0123456789ABCDEF Position 009 is - 8
* CBLNUMC1 0123456789ABCDEF Position 010 is - 9
* CBLNUMC1 0123456789ABCDEF Position 011 is - A
* CBLNUMC1 0123456789ABCDEF Position 012 is - B
* CBLNUMC1 0123456789ABCDEF Position 013 is - C
* CBLNUMC1 0123456789ABCDEF Position 014 is - D
* CBLNUMC1 0123456789ABCDEF Position 015 is - E
* CBLNUMC1 0123456789ABCDEF Position 016 is - F
* CBLNUMC1
* CBLNUMC1 SIGN TRAILING SEPARATE...
* CBLNUMC1 00100000000-
* CBLNUMC1 00100000000+
* CBLNUMC1
* CBLNUMC1 SIGN TRAILING...
* CBLNUMC1 00100000000+
* CBLNUMC1 00100000000-
* CBLNUMC1
* CBLNUMC1 SIGN TRAILING...
* CBLNUMC1 00100000000-
* CBLNUMC1 00100000000+
* CBLNUMC1
* CBLNUMC1 SIGN LEADING...
* CBLNUMC1 -00100000000
* CBLNUMC1 +00100000000
* CBLNUMC1
* CBLNUMC1 Edit for Display...
* CBLNUMC1     1,256.98
* CBLNUMC1 * Finished Example-05, Sign in zone of units position
* CBLNUMC1 *
* CBLNUMC1 *---------------------------------------------------------------*
* CBLNUMC1 * Starting Example-06, Test explicit decimal point
* CBLNUMC1 * Length of NUMBER-DECIMAL-5-2X is 8
* CBLNUMC1 * 12345.67
* CBLNUMC1 * 12345.67
* CBLNUMC1 * Length of NUMBER-DECIMAL-5-2X is 8
* CBLNUMC1 * 76543.21
* CBLNUMC1 * 76543.21
* CBLNUMC1 * Finished Example-06, Test explicit decimal point
* CBLNUMC1 *
* CBLNUMC1 *---------------------------------------------------------------*
* CBLNUMC1 * Starting Example-07, An arithmetic compare
* CBLNUMC1 * ZONED-FORMAT-S09V02 EQ ZONED-FORMAT-S09V02
* CBLNUMC1 * Finished Example-07, An arithmetic compare
* CBLNUMC1 *
* CBLNUMC1 *---------------------------------------------------------------*
* CBLNUMC1 * Starting Example-08, a floating point field - WIP
31428571
 .31428566E 01
 .314285714285714280E 01
* CBLNUMC1 * Finished Example-08, a floating point field - WIP
* CBLNUMC1 *
* CBLNUMC1 *---------------------------------------------------------------*
* CBLNUMC1 * Starting Example-08, Test for floating point - WIP
* CBLNUMC1 * LOW-VALUES field is NOT numeric
* CBLNUMC1
* CBLNUMC1 * ZEROES field is numeric
* CBLNUMC1 *
* CBLNUMC1 * Finished Example-08, Test for floating point - WIP
* CBLNUMC1 Thank you for using this software provided from SimoTime Enterprises
* CBLNUMC1 Please send all inquires or suggestions to the helpdesk@simotime.com

The preceding sample output shows the results of an "IF FIELD-NAME IS NUMERIC" test for a signed, numeric field. In most cases the sign is not a problem. However, if the numeric field must be all digits then the field should be redefined as alphamerical or a test to scan the field should be used.

In the wonderful 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 determining the contents of a numeric 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-2017
SimoTime Technologies and Services
All Rights Reserved

Table of Contents Previous Section Next Section Job Scripts

This suite of programs includes two types of job scripts. The Windows CMD File is provided to run on a Windows System with Micro Focus COBOL technologies. The JCL Member is provided to run on an IBM Mainframe System or Micro Focus Enterprise Server running on a Linux, UNIX or Windows System.

Table of Contents Previous Section Next Section Windows Command File

The following is the Windows Command file (CBLNUME1.cmd) that is required to run as a job on a Windows System using Micro Focus Server or Studio.

@echo OFF
rem  * *******************************************************************
rem  *               CBLNUME1.cmd - a Windows Command File               *
rem  *         This program is provided by SimoTime Technologies         *
rem  *           (C) Copyright 1987-2017 All Rights Reserved             *
rem  *             Web Site URL:   http://www.simotime.com               *
rem  *                   e-mail:   helpdesk@simotime.com                 *
rem  * *******************************************************************
rem  *
rem  * Text    - Various test of properties of numeric fields
rem  * Author  - SimoTime Technologies
rem  * Date    - November 11, 2003
rem  * Version - 06.07.16
rem  *
rem  * ********************************************************************
rem  * Step   1 of 2  Set the global environment variables...
rem  *
     setlocal
     if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
     set CmdName=CBLNUME1
     call ..\Env1BASE
rem  *
     call SimoNOTE "*******************************************************%CmdName%"
     call SimoNOTE "Starting JobName %CmdName%"
rem  * ********************************************************************
rem  * Step   2 of 2  Execute the sample program...
rem  *
     run CblNumC1
     if not "%ERRORLEVEL%" == "0" set JobStatus=0010
     if not "%JobStatus%" == "0000" 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 SysOut is %SYSOUT%"
     if not "%1" == "nopause" pause
     endlocal

Table of Contents Previous Section Next Section JCL Member

The following is the JCL member (CBLNUMJ1.jcl) required to run this job on an IBM Mainframe with ZOS or a Windows, UNIX or Linux System with Micro Focus Server.

//CBLNUMJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1,
//             COND=(0,LT)
//* *******************************************************************
//*       CBLNUMJ1.JCL - a JCL Member for Batch Job Processing        *
//*       This JCL Member is provided by SimoTime Technologies        *
//*           (C) Copyright 1987-2017 All Rights Reserved             *
//*             Web Site URL:   http://www.simotime.com               *
//*                   e-mail:   helpdesk@simotime.com                 *
//* *******************************************************************
//*
//* Text   -   COBOL processing of numeric fields...
//* Author -   SimoTime Technologies
//* Date   -   January 01, 1989
//*
//* This set of programs illustrate the use of COBOL for editing
//* and processing numeric fields. This is also a good example
//* of the Reference Modification feature of COBOL.
//*
//* This set of programs may be compiled and executed on a Mainframe
//* System with ZOS or a Linux, UNIX or Windows System with Micro Focus
//* Enterprise Server.
//*
//* *******************************************************************
//* Step 1 of 1, This is a single step job.
//*
//CBLNUMX1 EXEC PGM=CBLNUMC1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//SYSOUT   DD  SYSOUT=*
//*

Table of Contents Previous Section Next Section The COBOL Program

This program (CBLNUMC1.cbl) was written to test and scan a numeric field for numeric values or digits.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLNUMC1.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      * Copyright (C) 1987-2017 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 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.                                                 *
      *                                                               *
      * Permission to use, copy and modify 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.                                                 *
      *                                                               *
      * 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: CBLNUMC1.CBL
      *****************************************************************
      *
      * CBLNUMC1 - Test and scan a numeric field.
      *
      *
      * DESCRIPTION
      * -----------
      * This program will first test the contents of a numeric field
      * for numeric values.
      * The program will then use a redefinition of the field to scan
      * from left to right for valid digits (i.e. values of 0-9).
      * The Reference Modification capability of COBOL is used to scan
      * the field.
      *
      *****************************************************************
      *
      * MAINTENANCE
      * -----------
      * 1996/03/15 Simmons, Created program.
      * 1996/03/15 Simmons, 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 '* CBLNUMC1 '.
           05  T2 pic X(34) value 'Test or Scan a Numeric Field      '.
           05  T3 pic X(10) value ' v12.06.06'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLNUMC1 '.
           05  C2 pic X(20) value 'Copyright 1987-2017 '.
           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 '* CBLNUMC1 '.
           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 '* CBLNUMC1 '.
           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 '* CBLNUMC1 '.
           05  MESSAGE-TEXT        pic X(68).

      *    The Field used for ALPHAMERIC, NUMERIC (unsigned)
      *    and SIGNED (Numeric).
       01  FIELD-AS-NUMERIC        pic 9(16).
       01  FIELD-AS-SIGNED         redefines FIELD-AS-NUMERIC
                                   pic S9(16).
       01  FIELD-AS-ALPHAMERIC     redefines FIELD-AS-NUMERIC
                                   pic X(16).

      *    Fields used for scanning by reference modification...
       01  IX-1                    pic 999     value 0.
       01  STOP-SCAN               pic 999     value 16.
       01  DIGIT-FLAG              pic X       value 'U'.

      *    Fields used for leading/trailing signed fields...
       01  FIELD-SIGN-TRAIL        pic S9(9)V99 SIGN TRAILING SEPARATE
                                   value -1000000.
       01  OTHER-SIGN-TRAIL        pic S9(9)V99 SIGN TRAILING
                                   value -1000000.
       01  FIELD-SIGN-LEAD         pic S9(9)V99 SIGN LEADING
                                   value -1000000.

      *    Fields used for editing to print or display the value...
       01  TEST-DOLLAR-AMOUNT      pic 9999999V99  value 1256.98.
       01  NUMBER-DISPLAY          pic Z,ZZZ,ZZ9.99.

      *    Fields for explicit decimal point...
       01  NUMBER-DECIMAL-5-2      pic 9(5).9(2).
       01  NUMBER-DECIMAL-5-2X     redefines NUMBER-DECIMAL-5-2
                                   pic X(8).
       01  WORK-EIGHT              pic X(8).

       01  FP-SHORT                COMP-1  value 0.
       01  FP-LONG                 COMP-2  value 0.

       01  PI-VALUE                pic 9v9999999   value 0.

       01  PIC-S9-LOW-VALUES       pic S9(7).
       01  PIC-S9-LOW-VALUES-R     redefines PIC-S9-LOW-VALUES
                                   pic X(7).

       01  PACKED-FORMAT-S09V02    pic S9(9)V99 COMP-3  value 256.
       01  ZONED-FORMAT-S09V02     pic S9(9)V99         value 256.

       01  PIC-S9-COMP-3           pic S9(4)   COMP-3  value 0.
      *****************************************************************
       PROCEDURE DIVISION.
           perform Z-POST-COPYRIGHT.

      *---------------------------------------------------------------*
      *    EXAMPLE-01, use the COBOL capabilty of testing if
      *    a field contains a numeric value. The example uses the
      *    IF field-name IS NUMERIC capability.
      *
           perform BREAK-BETWEEN-EXAMPLES
           move '* Starting Example-01, Field contains all digits'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           move '0000000000000001' to FIELD-AS-ALPHAMERIC
           perform TEST-SIMPLE-NUMERIC
           move '* Finished Example-01, Field contains all digits'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

      *---------------------------------------------------------------*
      *    EXAMPLE-02, Move a right-adjusted, numeric value with
      *    leading spaces into the field...
      *
           perform BREAK-BETWEEN-EXAMPLES
           move '* Starting Example-02, Field contains leading spaces'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           move '             123' to FIELD-AS-ALPHAMERIC
           perform TEST-SIMPLE-NUMERIC
           move '* Finished Example-02, Field contains leading spaces'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

      *---------------------------------------------------------------*
      *    EXAMPLE-03, Create a value of +1 with the sign in the
      *    high-order bits of the units position (byte)...
      *    The EBCDIC value is X'F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0C1'
      *    The ASCII  value is X'30303030303030303030303030303031'
      *
           perform BREAK-BETWEEN-EXAMPLES
           move '* Starting Example-03, Sign in zone of units position'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           add 1 to ZERO giving FIELD-AS-SIGNED
           perform TEST-SIMPLE-NUMERIC
      *
      *    !!! CAUTION !!! CAUTION !!! CAUTION !!! CAUTION !!!
      *
      *    Example-03 may give different results when executing
      *    in an EBCDIC or ASCII environment. Notice that a
      *    signed number for EBCDIC is not all digits and a signed
      *    number for ASCII is all digits.
      *    If the "FIELD-AS-SIGNED" is used in the "IF NUMERIC" test
      *    the results will be the same. If a redefinition of the
      *    field as a "PIC X" is used the results will be different.
           move '* Finished Example-03, Sign in zone of units position'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

      *---------------------------------------------------------------*
      *    EXAMPLE-04, Create a value of -1 with the sign in the
      *    high-order bits of the units position (byte)...
      *    The EBCDIC value is X'F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0D1'
      *    The ASCII  value is X'30303030303030303030303030303071'
      *
           perform BREAK-BETWEEN-EXAMPLES
           move '* Starting Example-04, Sign in zone of units position'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           subtract 1 from ZERO giving FIELD-AS-SIGNED
           perform TEST-SIMPLE-NUMERIC
           move '* Finished Example-04, Sign in zone of units position'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

      *---------------------------------------------------------------*
      *    EXAMPLE-05, Create a value of ZERO...
      *    The EBCDIC value is X'F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0C0'
      *    The ASCII  value is X'30303030303030303030303030303030'
      *
           perform BREAK-BETWEEN-EXAMPLES
           move '* Starting Example-05, Sign in zone of units position'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
      *    MOVE ALL ZEROES TO FIELD-AS-ALPHAMERIC
           subtract 1 from 1 giving FIELD-AS-SIGNED
           perform TEST-SIMPLE-NUMERIC
      *
      *    The following examples will scan the sixteen (16) byte
      *    field from left to right for valid digits.
      *
           move '0000000000000001' to FIELD-AS-ALPHAMERIC
           perform TEST-BY-REFERENCE-MODIFICATION

           move '             123' to FIELD-AS-ALPHAMERIC
           perform TEST-BY-REFERENCE-MODIFICATION

           move '123             ' to FIELD-AS-ALPHAMERIC
           perform TEST-BY-REFERENCE-MODIFICATION

           move '000000000000000A' to FIELD-AS-ALPHAMERIC
           perform TEST-BY-REFERENCE-MODIFICATION

           move '0123456789ABCDEF' to FIELD-AS-ALPHAMERIC
           perform TEST-BY-REFERENCE-MODIFICATION

      *    Access any byte within a field...
           move '0123456789ABCDEF' to FIELD-AS-ALPHAMERIC
           perform ACCESS-ANY-BYTE-IN-FIELD

      *    Test various leading and trailing signed fields...
           perform TEST-VARIOUS-SIGNED-FIELDS

           perform EDIT-FOR-DISPLAY
           move '* Finished Example-05, Sign in zone of units position'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

      *---------------------------------------------------------------*
      *    EXAMPLE-06, Test for field with explicit decimal point...
      *
           perform BREAK-BETWEEN-EXAMPLES
           move '* Starting Example-06, Test explicit decimal point'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           add 12345.67 to ZERO giving NUMBER-DECIMAL-5-2
           perform TEST-NUMERIC-EXPLICIT-DECIMAL

           add 76543.21 to ZERO giving NUMBER-DECIMAL-5-2
           perform TEST-NUMERIC-EXPLICIT-DECIMAL

           move '* Finished Example-06, Test explicit decimal point'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

      *---------------------------------------------------------------*
      *    EXAMPLE-07, Arithmetically compare to numeric values by
      *    using the COBOL capabilty of testing if a field
      *    contains a numeric value. This example uses the
      *    IF field-name IS NUMERIC capability.
      *    After checking for numeric values in each field the
      *    first field is subtracted from the second field and
      *    if the result is zero then the numeric values are equal.
      *
           perform BREAK-BETWEEN-EXAMPLES
           move '* Starting Example-07, An arithmetic compare'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
      *    The following IF/AND/AND logic will compare the two
      *    numeric values for an equal condition.
           if  PACKED-FORMAT-S09V02 is NUMERIC
           and ZONED-FORMAT-S09V02  is NUMERIC
           and PACKED-FORMAT-S09V02 - ZONED-FORMAT-S09V02 = ZERO
               move '* ZONED-FORMAT-S09V02 EQ ZONED-FORMAT-S09V02'
                 to MESSAGE-TEXT
               perform Z-POST-CONSOLE-MESSAGE
           else
               move '* ZONED-FORMAT-S09V02 NE ZONED-FORMAT-S09V02'
                 to MESSAGE-TEXT
               perform Z-POST-CONSOLE-MESSAGE
           end-if
           move '* Finished Example-07, An arithmetic compare'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

      *---------------------------------------------------------------*
      *    EXAMPLE-08, Test for floating point...
      *
           perform BREAK-BETWEEN-EXAMPLES
           move '* Starting Example-08, a floating point field - WIP'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           compute PI-VALUE = 22 / 7
           display PI-VALUE
           compute FP-SHORT = 22 / 7
           display FP-SHORT
           compute FP-LONG = 22 / 7
           display FP-LONG
           move '* Finished Example-08, a floating point field - WIP'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

      *---------------------------------------------------------------*
      *    EXAMPLE-09, Test for floating point...
      *
           perform BREAK-BETWEEN-EXAMPLES
           move '* Starting Example-08, Test for floating point - WIP'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           move LOW-VALUES to PIC-S9-LOW-VALUES-R
           if  PIC-S9-LOW-VALUES is numeric
               move '* LOW-VALUES field is numeric'
                 to MESSAGE-TEXT
               perform Z-POST-CONSOLE-MESSAGE
           else
               move '* LOW-VALUES field is NOT numeric'
                 to MESSAGE-TEXT
               perform Z-POST-CONSOLE-MESSAGE
           end-if
           perform Z-POST-CONSOLE-MESSAGE

           move all ZEROES to PIC-S9-LOW-VALUES-R
           if  PIC-S9-LOW-VALUES is numeric
               move '* ZEROES field is numeric'
                 to MESSAGE-TEXT
               perform Z-POST-CONSOLE-MESSAGE
           else
               move '* ZEROES field is NOT numeric'
                 to MESSAGE-TEXT
               perform Z-POST-CONSOLE-MESSAGE
           end-if
           add 1 to PIC-S9-LOW-VALUES
           move '*'                to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

           add 9999 to ZERO giving PIC-S9-COMP-3
           add 2 to PIC-S9-COMP-3
           move '* Finished Example-09, Test for floating point - WIP'
             to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

           perform Z-THANK-YOU.

           GOBACK.

      *****************************************************************
       ACCESS-ANY-BYTE-IN-FIELD.
           move '* Access each byte of a field' to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           add 1 to ZERO giving IX-1
           perform until IX-1 > STOP-SCAN
               move FIELD-AS-ALPHAMERIC         to MESSAGE-TEXT
               move 'Position nnn is - '        to MESSAGE-TEXT(18:17)
               move IX-1                        to MESSAGE-TEXT(27:3)
               move FIELD-AS-ALPHAMERIC(IX-1:1) to MESSAGE-TEXT(36:2)
               perform Z-POST-CONSOLE-MESSAGE
               add 1 to IX-1
           end-perform
           exit.

      *****************************************************************
       BREAK-BETWEEN-EXAMPLES.
           move '*' to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           move '*' to MESSAGE-TEXT
           move all '-' to MESSAGE-TEXT(2:64)
           move '*' to MESSAGE-TEXT(65:1)
           perform Z-POST-CONSOLE-MESSAGE
           exit.

      *****************************************************************
       EDIT-FOR-DISPLAY.
           move TEST-DOLLAR-AMOUNT to NUMBER-DISPLAY
           display '* CBLNUMC1 Edit for Display...'
           display '* CBLNUMC1 ' NUMBER-DISPLAY
           exit.

      *****************************************************************
      * The following routine will perform a test on the same
      * sixteen (16) bytes of memory using the following field
      * definitions.
      * FIELD-AS-NUMERIC                                 PIC 9(16).
      * FIELD-AS-ALPHAMERIC  REDEFINES FIELD-AS-NUMERIC  PIC X(16).
      * FIELD-AS-SIGNED      REDEFINES FIELD-AS-NUMERIC  PIC S9(16).
      *
       TEST-SIMPLE-NUMERIC.
           move '* Simple Numeric Check is Starting'  to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

      *    Test the Alphameric Redefine of the field...
           move FIELD-AS-ALPHAMERIC          to MESSAGE-TEXT
           move 'Test Alphameric...'         to MESSAGE-TEXT(18:18)
           if  FIELD-AS-ALPHAMERIC is NUMERIC
               move 'Content Numeric...    ' to MESSAGE-TEXT(36:22)
           else
               move 'Content NOT Numeric...' to MESSAGE-TEXT(36:22)
           end-if
           perform Z-POST-CONSOLE-MESSAGE

      *    Test the Numeric field...
           move FIELD-AS-NUMERIC  to MESSAGE-TEXT
           move 'Test Numeric......' to MESSAGE-TEXT(18:18)
           if  FIELD-AS-NUMERIC is NUMERIC
               move 'Content Numeric...    ' to MESSAGE-TEXT(36:22)
           else
               move 'Content NOT Numeric...' to MESSAGE-TEXT(36:22)
           end-if
           perform Z-POST-CONSOLE-MESSAGE

      *    Test the Signed-Numeric Redefine of the field...
           move FIELD-AS-ALPHAMERIC to MESSAGE-TEXT
           move 'Test Signed.......' to MESSAGE-TEXT(18:18)
           if  FIELD-AS-SIGNED is NUMERIC
               move 'Content Numeric...    ' to MESSAGE-TEXT(36:22)
               if  FIELD-AS-SIGNED = 0
                   move 'Numeric and Zero value...    '
                     to MESSAGE-TEXT(36:29)
               end-if
               if  FIELD-AS-SIGNED > 0
                   move 'Numeric and Positive value...'
                     to MESSAGE-TEXT(36:29)
               end-if
               if  FIELD-AS-SIGNED < 0
                   move 'Numeric and Negative value...'
                     to MESSAGE-TEXT(36:29)
               end-if
               perform Z-POST-CONSOLE-MESSAGE
           else
               move 'Content NOT Numeric...' to MESSAGE-TEXT(36:22)
               perform Z-POST-CONSOLE-MESSAGE
           end-if

           move '* Simple Numeric Check is Finished'  to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           move '*'  to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           exit.

      *****************************************************************
      * This routine uses the Reference Modification feature of COBOL
      * to scan the ten-byte Alphameric field from left to right.
      * If a non-digit is found then an 'N' is moved to the
      * DIGIT-FLAG field and IX-1 is the position where the first
      * non-digit value was encountered.
      * If the fields contains all digits then a 'Y' is moved to the
      * DIGIT-FLAG field and IX-1 is the number of digits.
      *
       TEST-BY-REFERENCE-MODIFICATION.
           move '* Scan for Digits is Starting...' to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           move FIELD-AS-ALPHAMERIC    to MESSAGE-TEXT
           move 'Scan for Digits...'   to MESSAGE-TEXT(18:18)
           add 1 to ZERO giving IX-1
           move 'U' to DIGIT-FLAG
           perform until IX-1       > STOP-SCAN
                   or    DIGIT-FLAG = 'N'
                   if  FIELD-AS-ALPHAMERIC(IX-1:1) < 0
                   or  FIELD-AS-ALPHAMERIC(IX-1:1) > 9
                       move 'N' to DIGIT-FLAG
                   end-if
                   if  DIGIT-FLAG = 'U'
                       add 1 to IX-1
                   end-if
           end-perform
           if  IX-1 = STOP-SCAN + 1
           and DIGIT-FLAG = 'U'
               subtract 1 from IX-1
               move 'Y' to DIGIT-FLAG
               move 'Content ALL Digits... ' to MESSAGE-TEXT(36:22)
               move IX-1                     to MESSAGE-TEXT(58:3)
               move DIGIT-FLAG               to MESSAGE-TEXT(62:1)
               perform Z-POST-CONSOLE-MESSAGE
           else
               move 'Content NOT Digits... ' to MESSAGE-TEXT(36:22)
               move IX-1                     to MESSAGE-TEXT(58:3)
               move DIGIT-FLAG               to MESSAGE-TEXT(62:1)
               perform Z-POST-CONSOLE-MESSAGE
           end-if
           move '* Scan for Digits is Finished...' to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           move '*'                    to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           exit.

      *****************************************************************
       TEST-VARIOUS-SIGNED-FIELDS.
           display  '* CBLNUMC1'
           display  '* CBLNUMC1 SIGN TRAILING SEPARATE...'
           display  '* CBLNUMC1 ' FIELD-SIGN-TRAIL
           evaluate FIELD-SIGN-TRAIL(12:1)
              when '-' move '+' to FIELD-SIGN-TRAIL(12:1)
              when '+' move '-' to FIELD-SIGN-TRAIL(12:1)
              when OTHER display 'FORMAT ERROR'
           end-evaluate
           display  '* CBLNUMC1 ' FIELD-SIGN-TRAIL

           display  '* CBLNUMC1'
           display  '* CBLNUMC1 SIGN TRAILING...'
           display  '* CBLNUMC1 ' FIELD-SIGN-TRAIL
           subtract FIELD-SIGN-TRAIL from ZERO giving FIELD-SIGN-TRAIL
           display  '* CBLNUMC1 ' FIELD-SIGN-TRAIL

           display  '* CBLNUMC1'
           display  '* CBLNUMC1 SIGN TRAILING...'
           display  '* CBLNUMC1 ' OTHER-SIGN-TRAIL
           COMPUTE  OTHER-SIGN-TRAIL = OTHER-SIGN-TRAIL * -1
           display  '* CBLNUMC1 ' OTHER-SIGN-TRAIL

           display  '* CBLNUMC1'
           display  '* CBLNUMC1 SIGN LEADING...'
           display  '* CBLNUMC1 ' FIELD-SIGN-LEAD
           subtract FIELD-SIGN-LEAD  from ZERO giving FIELD-SIGN-LEAD
           display  '* CBLNUMC1 ' FIELD-SIGN-LEAD
           display  '* CBLNUMC1'

           exit.

      ****************************************************************
       TEST-NUMERIC-EXPLICIT-DECIMAL.
           display '* CBLNUMC1 * Length of NUMBER-DECIMAL-5-2X is '
                   LENGTH OF NUMBER-DECIMAL-5-2

           display '* CBLNUMC1 * ' NUMBER-DECIMAL-5-2
           move NUMBER-DECIMAL-5-2X to WORK-EIGHT
           display  '* CBLNUMC1 * ' WORK-EIGHT
           exit.

      *****************************************************************
      * The following Z-Routines perform administrative tasks         *
      * for this program.                                             *
      *****************************************************************
       Z-POST-CONSOLE-MESSAGE.
           display MESSAGE-BUFFER
           move SPACES to MESSAGE-TEXT
           exit.

      *****************************************************************
       Z-POST-COPYRIGHT.
           display SIM-TITLE
           display SIM-COPYRIGHT
           exit.

      *****************************************************************
       Z-THANK-YOU.
           display SIM-THANKS-01
           display SIM-THANKS-02
           exit.
      *****************************************************************
      *      This example is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

Table of Contents Previous Section Next Section Summary

This set of jobs will show how a COBOL program can test that a data field (or string) contains a valid numeric value. Also, it illustrates how to redefine a numeric field and then scan the field from left to right testing for a digit in each position. 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 document and the links to other documents are intended to provide a greater awareness of the Data Management and Application Processing alternatives.

The 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 send an e-mail to: helpdesk@simotime.com or call 415 883-6565. We appreciate hearing from you.

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 the Numbers Connection for additional information about the structure and processing of numeric data items (or numeric fields).

Link to Internet   Link to Server   Explore The Binary or COMP format for numeric data strings. This numeric structure is supported by COBOL and may be explicitly defined with the "USAGE IS COMP" or "USAGE IS BINARY" clause.

Link to Internet   Link to Server   Explore The Edited for Display format for numeric data strings. This numeric structure is supported by COBOL and may be used with an edit-mask to prepare the presentation for readability by human beings.

Link to Internet   Link to Server   Explore The Packed-Decimal or COMP-3 format for numeric data strings. This numeric structure is supported by COBOL and may be explicitly defined with the "USAGE IS COMP-3" clause.

Link to Internet   Link to Server   Explore The Zoned-Decimal format for numeric data strings. This numeric structure is the default numeric for COBOL and may be explicitly defined with the "USAGE IS DISPLAY" clause.

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 to interpret the results of accessing VSAM data sets and/or QSAM files.

Table of Contents Previous Section Next Section Internet Access Required

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 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 Comments or Feedback

This document was created and is copyrighted and maintained by SimoTime Technologies.

If you have any questions, suggestions, comments or feedback please call or send an e-mail to: helpdesk@simotime.com

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 or need assistance with converting non-relational data structures simply give us a call at 415 883-6565 or check the web site at http://www.simotime.com


Return-to-Top
COBOL does Testing and Scanning of Numeric Field by SimoTime Technologies
Copyright © 1987-2017
SimoTime Technologies and Services
All Rights Reserved
When technology complements business
http://www.simotime.com