Cobol programming: Move data problem

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
KazITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DeanHorakCommented:
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.
0
JesterTooCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.