COBOL Numeric Edits
 Edit or Scan a Numeric Field
http://www.simotime.com
When technology complements business    Copyright © 1987-2010  SimoTime Enterprises  All Rights Reserved
  Table of Contents Version 10.03.20 
  Introduction
  The Windows Command File
  The JCL Member
  The COBOL Demonstration Program
  Summary
 
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Comments or Suggestions
  About SimoTime

Introduction
(Next) (Previous) (Table-of-Contents)

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. Alphameric, Numeric or Signed) and the results.

* CBLNUMC1  Test or Scan a Numeric Field      v1.1.00EV http://www.simo
* CBLNUMC1 (C) Copyright 2000   SimoTime Enterprises, LLC   All Rights
* CBLNUMC1 *
* CBLNUMC1 * 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 valu
* CBLNUMC1 * Simple Numeric Check is Finished
* CBLNUMC1 *
* CBLNUMC1 * 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 * Field contains sign in zone of units position
* CBLNUMC1 * Simple Numeric Check is Starting
* CBLNUMC1 000000000000000A Test Alphameric...Content NOT Numeric...
* CBLNUMC1 000000000000000A Test Numeric......Content NOT Numeric...
* CBLNUMC1 000000000000000A Test Signed.......Numeric and Positive valu
* CBLNUMC1 * Simple Numeric Check is Finished
* CBLNUMC1 *
* CBLNUMC1 * Field contains sign in zone of units position
* CBLNUMC1 * Simple Numeric Check is Starting
* CBLNUMC1 000000000000000J Test Alphameric...Content NOT Numeric...
* CBLNUMC1 000000000000000J Test Numeric......Content NOT Numeric...
* CBLNUMC1 000000000000000J Test Signed.......Numeric and Negative valu
* CBLNUMC1 * Simple Numeric Check is Finished
* CBLNUMC1 *
* CBLNUMC1 * Field contains sign in zone of units position
* CBLNUMC1 * Simple Numeric Check is Starting
* CBLNUMC1 000000000000000{ Test Alphameric...Content NOT Numeric...
* CBLNUMC1 000000000000000{ Test Numeric......Content NOT Numeric...
* CBLNUMC1 000000000000000{ 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
* CBLNUMC1 * Scan for Digits is Finished...
* CBLNUMC1 *
* CBLNUMC1 * Scan for Digits is Starting...
* CBLNUMC1              123 Scan for Digits...Content NOT Digits... 001
* CBLNUMC1 * Scan for Digits is Finished...
* CBLNUMC1 *
* CBLNUMC1 * Scan for Digits is Starting...
* CBLNUMC1 123              Scan for Digits...Content NOT Digits... 004
* CBLNUMC1 * Scan for Digits is Finished...
* CBLNUMC1 *
* CBLNUMC1 * Scan for Digits is Starting...
* CBLNUMC1 000000000000000A Scan for Digits...Content NOT Digits... 016
* CBLNUMC1 * Scan for Digits is Finished...
* CBLNUMC1 *
* CBLNUMC1 * Scan for Digits is Starting...
* CBLNUMC1 0123456789ABCDEF Scan for Digits...Content NOT Digits... 011
* 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 *
* CBLNUMC1 Thank you for using this sample by SimoTime Enterprises, LLC
* CBLNUMC1 Please send comments or suggestions to 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 alphameric 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.

Note: The source code for this example is available from the SimoTime Library under Download Directory at  www.simotime.com

The Windows Command File
(Next) (Previous) (Table-of-Contents)

The following is the Windows Command file (CBLNUME1.CMD) that is required to run as a job on a PC using Micro Focus Net Express.

@echo OFF
rem  * *******************************************************************
rem  *                   This program is provided by:                    *
rem  *                    SimoTime Enterprises, LLC                      *
rem  *           (C) Copyright 1987-2010 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 Enterprises
rem  * Date    - November 11, 2003
rem  * Version - 06.07.16
rem  *
rem  * ********************************************************************
rem  * Step   1 of 2  Set the global environment variables...
rem  *
     setlocal
     call Env1PROD
     if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
     set CmdName=CblNumE1
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

The JCL Member
(Next) (Previous) (Table-of-Contents)

The following is the mainframe JCL (CBLNUMJ1.JCL) required to run the mainline program.

//CBLNUMJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1,
//             COND=(0,LT)
//* *******************************************************************
//*                   This program is provided by:                    *
//*                    SimoTime Enterprises, LLC                      *
//*           (C) Copyright 1987-2010 All Rights Reserved             *
//*             Web Site URL:   http://www.simotime.com               *
//*                   e-mail:   helpdesk@simotime.com                 *
//* *******************************************************************
//*
//* Text   -   COBOL processing of numeric fields...
//* Author -   SimoTime Enterprises
//* 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 will run on a mainframe under MVS or on a
//* Personal Computer with Windows and Micro Focus Mainframe Express.
//*
//* *******************************************************************
//* 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=*
//*

The COBOL Demonstration Program
(Next) (Previous) (Table-of-Contents)

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 ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2010 SimoTime Enterprises, LLC.            *
      *                                                               *
      * 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 Enterprises. 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           *
      * Enterprises.                                                  *
      *                                                               *
      * 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           *
      * Enterprises.                                                  *
      *                                                               *
      * SimoTime Enterprises makes no warranty or representations     *
      * about the suitability of the software for any purpose. It is  *
      * provided "AS IS" without any express or implied warranty,     *
      * including the implied warranties of merchantability, fitness  *
      * for a particular purpose and non-infringement. SimoTime       *
      * Enterprises 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 Enterprises                                          *
      * 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 Enterprises,  *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Enterprises         *
      *        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 ' v07.11.20'.
           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-2010 '.
           05  C3 pic X(28) value '  SimoTime Enterprises, LLC '.
           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 sample '.
           05  C3 pic X(32) value 'by SimoTime Enterprises, LLC    '.
           05  C4 pic X(04) value '    '.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* CBLNUMC1 '.
           05  C2 pic X(32) value 'Please send comments or suggesti'.
           05  C3 pic X(32) value 'ons to helpdesk@simotime.com    '.
           05  C4 pic X(04) value '    '.

      *****************************************************************
      *    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  PIC-S9-COMP-3           pic S9(4)   COMP-3  value 0.
      *****************************************************************
       PROCEDURE DIVISION.

           perform Z-POST-COPYRIGHT.

      *    The following examples use the COBOL capabilty of testing
      *    if a field contains a numeric value. The examples use the
      *    IF field-name IS NUMERIC capability.
      *
      *    Example-01, Move all digits into the field...
      *
           move '*'                          to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           move '* Field contains all digits'  to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           move '0000000000000001' to FIELD-AS-ALPHAMERIC
           perform TEST-SIMPLE-NUMERIC
      *
      *    EXAMPLE-02, Move a right-adjusted, numeric value with
      *    leading spaces into the field...
      *
           move '* Field contains leading spaces'  to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
           move '             123' to FIELD-AS-ALPHAMERIC
           perform TEST-SIMPLE-NUMERIC
      *
      *    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'
      *
           move '* Field contains 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.
      *
      *    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'
      *
           move '* Field contains 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
      *
      *    Example-05, Create a value of ZERO...
      *    The EBCDIC value is X'F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0C0'
      *    The ASCII  value is X'30303030303030303030303030303030'
      *
           move '* Field contains 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
      *
      *    Example-06, Test for field with explicit decimal point...
      *
           move '* Field with 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 '*'                to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE
      *
      *    Example-07, Test for floating point...
      *
           move '* Field defined as floating point'
             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 '*'                to MESSAGE-TEXT
           perform Z-POST-CONSOLE-MESSAGE

      *
      *    Example-08, Test for floating point...
      *
           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

           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.

      *****************************************************************
       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 'Length of NUMBER-DECIMAL-5-2X is '
                   LENGTH OF NUMBER-DECIMAL-5-2

           display NUMBER-DECIMAL-5-2
           move NUMBER-DECIMAL-5-2X to WORK-EIGHT
           display 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 Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

Summary
(Next) (Previous) (Table-of-Contents)

The purpose of this document is to assist as a tutorial for new programmers or as a quick reference for experienced programmers. These sample programs are made available on an "as-is" basis and may be downloaded, copied and modified for specific situations as long as the copyright information is not removed or changed. As always, it is the programmer's responsibility to thoroughly test all programs.

Software Agreement and Disclaimer
(Next) (Previous) (Table-of-Contents)

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 Enterprises.

Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to Simotime Enterprises. 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 Enterprises.

SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises 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.

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

Downloads and Links to Similar Pages
(Next) (Previous) (Table-of-Contents)

You may download this example at http://www.simotime.com/sim4dzip.htm#COBOLNumericFields as a Z-Pack. The 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.

Please view the complete list of SimoTime Z-Pack Examples at http://www.simotime.com/sim4dzip.htm.

Note: You must be attached to the Internet to download a Z-Pack or view the list.

Check out  The COBOL Connection  for more examples of mainframe COBOL coding techniques and sample code.

The following list provides links to additional SimoTime documents about numeric data fields.

Link Name Description
number01 This is an introductory, self-study course about the commonly used numeric formats available on the mainframe. The course material may be purchased from SimoTime. The documentation may be viewed online.
databn01 This is a White Paper that describes the usage and format of BINARY fields (or "USAGE IS COMPUTATIONAL" in COBOL terminology).
datapk01 This is a White Paper that describes the usage and format of PACKED-DECIMAL fields (or "USAGE IS COMPUTATIONAL-3" in COBOL terminology).
datazd01 This is a White Paper that describes the usage and format of ZONED-DECIMAL fields (or "USAGE IS DISPLAY" in COBOL terminology).

The following chart provides a list of the sample COBOL programs that focus on processing numeric fields.

HTML Tag Description
cblnum01 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.
cblraz01 This suite of programs provides an example of a routine that will Right Adjust (or Right Justify) a text string within a numeric field and fill the left-most or high-order bytes with zeroes.
cbltxn01 This suite of programs provides an example of how a COBOL program calls a COBOL routine to create a 150-character, English-oriented text data string from a 12-digit numeric field. For example, if the numeric field contains 000000001234 then a text string is created with the following information, One-Thousand-Two-Hundred-Thirty-Four
nbrtyp01 This suite of example programs will describe the use, format and size of some of the commonly used numeric fields of the COBOL programming language. This example also illustrates how to redefine a numeric field and how to display the actual hexadecimal content of a numeric field.
number01 This document is an introduction to the various numeric formats used by COBOL and the IBM mainframe systems The session will describe three of the popular numeric formats used with COBOL and IBM Mainframe systems. The discussions include further detail about the issues and concerns of unsigned (or implied positive) numbers, signed (positive or negative) numbers and decimal or whole numbers. A sample of how to convert non-print formats to display or print formats is included along with a sample COBOL program.
numbug01 The challenge with this program is that it is expected to process the various numeric items in the same manner as the mainframe. For example, a zoned-decimal field that contains leading spaces should not cause an ABEND (i.e. 163 error on Micro Focus) but should treat the leading spaces as zeroes and complete the arithmetic calculation. However, a packed-decimal field that contains non-numeric values would issue a S0C7 (referred to as a sock-seven) on the mainframe and should issue a 163 error in the Micro Focus environment.

To review all the information available on this site start at  The SimoTime Home Page .

Comments or Suggestions
(Next) (Previous) (Table-of-Contents)

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

About SimoTime Enterprises
(Next) (Previous) (Table-of-Contents)

Founded in 1987, SimoTime Enterprises 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. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. 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. 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
Copyright © 1987-2010  SimoTime Enterprises  All Rights Reserved
When technology complements business
http://www.simotime.com