We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Cobol programming: Move data problem

Medium Priority
282 Views
Last Modified: 2020-04-13
Hi,

I am designing a programe that reads data from a sequential file.
within it I am having and error of "illegal character in numeric field" run time error 163
I am trying to move the data held in F1-USAGE TO WS-USAGE

My statement is
MOVE F1-USAGE TO WS-USAGE
an this is where the program stops with the abovementioned error.
the pic fields invovled are
F1-USAGE   PIC 9(08)
WS-USAGE PIC 9(08)

I have stepped through the programe using the watch option and when it gets to the statement it seems that there is nothing in the F1-USAGE field.

Is it not possible to move data from an input field like this?

KazIT
Comment
Watch Question

Since your F1-USAGE field is defined as numeric (PIC 9(08)) the input must be all numeric (i.e. no spaces, no alpha). When cobol moves data to a numeric field it verifies that the data is indeed numeric and if not, will blow off with an error. It sounds like you haven't properly read the input into the F1-USAGE field prior to your MOVE statement.
As Dean said, this could be a case of not reading the data from the file with the proper layout.  Or, it could be that your data doesn't always contain "leading" zeroes for numeric fields (or is even completely blank for 0 values)... depending on the source of the data this is a fairly common thing.  What you may need to do in that case is "pre-process" the data a bit before using it with the main logic of your program.  Here is one sample to demonstrate that (there are multiple ways to achieve the same goal):

assumption 1:  your definition of F1-USAGE is something like this:     05  F1-USAGE      PIC 9(08).

add this statement immediately after the definition of F1-USAGE...

         05  F1-USAGEX    REDEFINES F1-USAGE  PIC X(08).

then, just before your MOVE statement that currently fails, add these lines...

        INSPECT F1-USAGEX REPLACING LEADING ' ' WITH '0'
        IF F1-USAGEX NUMERIC
            MOVE F1-USAGE TO WS-USAGE
        ELSE
            MOVE 0 TO WS-USAGE
            PERFORM ERROR-ROUTINE
        END-IF

Note that the "PERFORM ERROR-ROUTINE" is optional and would be something you would need to write in order to record the fact that there was non-numeric data found even after addressing the leading-zeros issue.

hth,
Lynn

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.