COBOL Numeric Edits
 Edit or Scan a Numeric Field
When technology complements business    Copyright © 1987-2012  SimoTime Enterprises  All Rights Reserved
  Table of Contents Version 11.03.22 
  Introduction
  The Windows Command File
  The JCL Member
  The COBOL Demonstration Program
  Summary
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Downloads and Links, Internet Access Required
  Downloads and Links, Local Access
  Glossary of Terms
  Comments, Suggestions or Feedback
  Company Overview
The SimoTime Home Page

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       v07.11.20 http://www.simotime.com
* CBLNUMC1 Copyright 1987-2012 --- SimoTime Enterprises --- All Rights Reserved
* 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 value...
* 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 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 * Field contains 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 * Field contains 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 * Field with explicit decimal point
Length of NUMBER-DECIMAL-5-2X is 8
12345.67
12345.67
Length of NUMBER-DECIMAL-5-2X is 8
76543.21
76543.21
* CBLNUMC1 *
* CBLNUMC1 * Field defined as floating point
31428571
 .31428566E 01
 .314285714285714280E 01
* CBLNUMC1 *
* CBLNUMC1 * LOW-VALUES field is NOT numeric
* CBLNUMC1
* CBLNUMC1 * ZEROES field is numeric
* CBLNUMC1 *
* 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 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.

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 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 Enterprises          *
rem  *           (C) Copyright 1987-2012 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
     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

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

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)
//* *******************************************************************
//*        This program is provided by: SimoTime Enterprises          *
//*           (C) Copyright 1987-2012 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-2012 SimoTime Enterprises.                 *
      *                                                               *
      * 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 expressed 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-2012 '.
           05  C3 pic X(28) value '--- SimoTime Enterprises ---'.
           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 softwar'.
           05  C3 pic X(32) value 'e provided from SimoTime Enterpr'.
           05  C4 pic X(04) value 'ises'.

       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  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. 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 choice of alternatives.

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

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

SimoTime Enterprises 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 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, documentation or training material.

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

This section includes links to documents with additional information that is beyond the scope and purpose of this document. The first sub-section requires an internet connection, the second sub-section references locally available documents.

Downloads and Links, Internet Access Required
(Next) (Previous) (Table-of-Contents)

The following links will require an internet connect.

A good place to start is The SimoTime Home Page for access to white papers, program examples and product information.

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.

Explore The ASCII and EBCDIC translation tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats.

Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and QSAM files.

Explore The Micro Focus Web Site for more information about products and services available from Micro Focus.

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

Downloads and Links, Local Access
(Next) (Previous) (Table-of-Contents)

The following links may be accessible without an internet connection.

Note: A SimoTime License is required for the items to be made available on a local server.

Numeric Type Description
Zoned Decimal  This document describes the zoned-decimal format. This is coded in COBOL as USAGE IS DISPLAY and is the default format if the USAGE clause is missing.
Note: This is the slowest performer and uses the most storage space but is easiest to display on a screen or print to a printer. This encoding scheme may be unsigned (implied positive) or signed. This type of field will require special handling for the sign position when migrating from a mainframe (EBCDIC) to a Micro Focus (ASCII) environment.
Packed Decimal  This document describes the packed-decimal format. This is coded in COBOL as USAGE IS COMPUTATIONAL-3 and is usually coded in its abbreviated form of COMP-3.
Note: The mainframe can perform arithmetic functions with this data format at the hardware (or micro-code) level. This type of encoding scheme was primarily used to save storage space. This encoding scheme may be unsigned (implied positive) or signed. When migrating from a mainframe (EBCDIC) to a Micro Focus (ASCII) environment this type of field should be left in its original format since this will be supported in the new environment.
Binary  This document describes the binary format. This is coded in COBOL as USAGE IS COMPUTATIONAL and is usually coded in its abbreviated form of COMP. This may also be coded with the keyword BINARY.
Note: This format will save storage space but was primarily used for performance. Register arithmetic uses this format. This encoding scheme may be unsigned (implied positive) or signed. When migrating from a mainframe (EBCDIC) to a Micro Focus (ASCII) environment this type of field should be left in its original format since this will be supported in the new environment.
Edited Numeric  This document describes the edited numeric format. This is coded in COBOL using an edit mask in the picture clause. An example would be PIC ZZZ.99+.
Note: This type of field is used for numbers that are to be displayed or printed and should be all text characters. This filed should be converted using standard conversion tables.
Floating Point  This format is used when a high level of precision is required or very large numbers are required. On the mainframe the default is to use the IBM 370 Floating Point Arithmetic. On Windows or UNIX using Micro Focus the default is to use the IEEE Standard for Floating Point Arithmetic. The IEEE standard provides a higher level of precision than 370. However, 370 provides for larger numbers by providing less precision.
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.
numprt01 Printing numeric fields, especially packed-decimal or binary (i.e. COMP-3 or COMP) requires special consideration. Also, signed, zoned-decimal fields will require special consideration. Most numeric fields will require some sort of editing before printing. This suite of programs provides examples of how a COBOL program may be used to properly print (or display) numeric fields.

Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and QSAM files.

Glossary of Terms
(Next) (Previous) (Table-of-Contents)

Check out  The SimoTime Glossary  for a list of terms and definitions used in the documents provided by SimoTime.

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

This document was created and is maintained by SimoTime Enterprises.

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.

Company Overview
(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
COBOL does Testing and Scanning of Numeric Field by SimoTime Enterprises
Copyright © 1987-2012 SimoTime Enterprises  All Rights Reserved
When technology complements business
http://www.simotime.com