?
Solved

Cobol programming: Move data problem

Posted on 2006-03-29
2
Medium Priority
?
271 Views
Last Modified: 2008-03-04
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
0
Comment
Question by:KazIT
2 Comments
 
LVL 11

Expert Comment

by:DeanHorak
ID: 16322117
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
 
LVL 22

Accepted Solution

by:
JesterToo earned 2000 total points
ID: 16413389
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question