numberic data being truncated



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

numberic data being truncated

Postby nicole » Wed Nov 03, 2010 3:13 am

Hi there,

Ok here is my problem, The total amount of records written are being truncated somewhere in the program. The total amount is 15,630.60 but output shows 14,630.60. This is a cobol program and I have been trying to do the process of elimination by changing the pic fields or fillers, stuff like that and nothing is working. I have a feeling it has to do with the data being moved to another field, but still can't figure it out. Any suggestions?
nicole
 
Posts: 23
Joined: Thu Jul 22, 2010 10:02 pm
Has thanked: 0 time
Been thanked: 0 time

Re: numberic data being truncated

 

Re: numberic data being truncated

Postby dick scherrer » Wed Nov 03, 2010 3:18 am

Hello,

What is the amount in the first and the last record? These are records are the ones most often mis-handled.

How many records are used to total the amount?

How is the "target" amount determined?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: numberic data being truncated

Postby Robert Sample » Wed Nov 03, 2010 3:20 am

Your input variable is PIC 9(03)V9(02) or something similar. An amount field of 1000.00 exists on one input record, so the 1000.00 is being handled by COBOL as 0.00 and hence the shortage.

How much help do you expect to get when you don't provide any details such as variable PICTURE clauses, the number of input records, the actual data being used, or anything else?
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: numberic data being truncated

Postby nicole » Wed Nov 03, 2010 3:30 am

ok the input file record contains 44 characters (coin-record) and the output record contains 133 characters.
01 PREV-AMOUNT PIC S9(8)V99 COMP-3 VALUE +0.

ws-coin-record.
05 AMOUNT PIC X(07)

01 WS-TEMP-PAYSTN-RECORD
10 WS-PAYSTN-AMOUNT PIC S9(7)V99 COMP-3
VALUE +0.

01 WS-DOLLARS PIC 9(3).

01 WS-TEMP-CENTS PIC 99.

01 WS-CENTS REDEFINES WS-TEMP-CENTS
PIC V99.

01 WS-TEMP-AMOUNT PIC 9(3)V99.


I'm not sure if the above information is enough for you to understand. But it takes in a record, sorts it and makes it compliant . I was thinking it may have to do with my control record or perhaps the detail-line or maybe the moves. I hope this helps, if not I will post additional information.
nicole
 
Posts: 23
Joined: Thu Jul 22, 2010 10:02 pm
Has thanked: 0 time
Been thanked: 0 time

Re: numberic data being truncated

Postby Robert Sample » Wed Nov 03, 2010 3:33 am

If you place an amount of 1000 into this variable
01 WS-DOLLARS PIC 9(3).
COBOL will automatically truncate it to zero, which would cause your total to be off by 1000.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: numberic data being truncated

Postby nicole » Wed Nov 03, 2010 3:37 am

ok but I have changed it to PIC 9(7) and it didn't make a difference.
nicole
 
Posts: 23
Joined: Thu Jul 22, 2010 10:02 pm
Has thanked: 0 time
Been thanked: 0 time

Re: numberic data being truncated

Postby Robert Sample » Wed Nov 03, 2010 4:39 am

Since you posted a batch of variables without any of the underlying logic in the PROCEDURE DIVISION, it is quite possible that the problem is with one of the variables you did NOT post. Did you not notice this variable:
01 WS-TEMP-AMOUNT PIC 9(3)V99.
which has the same problem as I mentioned in my last post? Unless you analyze the code and understand what the issue really is, randomly changing PICTURE clauses or moving things around in your PROCEDURE DIVISION will make improvements only by accident -- and could make things worse.

You are providing only partial information and showing absolutely no interest in self improvement by actually learning and understanding what you are doing in your COBOL program. This does not bode well for your career in IT, which generally requires people who can think for themselves, analyze problems, and figure out answers on their own.

If all you want is for someone to write the code for you, I'm sure one of the more experienced people will happily do so for the appropriate amount of compensation (generally rates run 800 U.S. dollars per day -- or fraction of a day -- and up).
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: numberic data being truncated

Postby dick scherrer » Wed Nov 03, 2010 8:11 am

Hello,

What is the content of the "05 AMOUNT PIC X(07)" field? Actual dollars and cents 123.45 or implied cents 12345?

Suggest you use some other code to read the input file and determine if an amount is greater than 999.99. If the input value contains an actual decimal point consider using NUMVAL.

And to repeat - how do you know what the total should be?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: numberic data being truncated

Postby nicole » Wed Nov 03, 2010 7:28 pm

Hi again,

It is acutall dollars going in. In the data set being rolled in the dollar amount looks like this 15630.60. We know what the total should be because in the data set it adds up to a certain amount. But the amount that comes out in the report is a 1,000.00 short.
nicole
 
Posts: 23
Joined: Thu Jul 22, 2010 10:02 pm
Has thanked: 0 time
Been thanked: 0 time

Re: numberic data being truncated

Postby dick scherrer » Wed Nov 03, 2010 11:46 pm

Hello,

We know what the total should be because in the data set it adds up to a certain amount.
Suggest you compare the code that works against the code that does not work. . .

You most likely have skipped one or more records or mishandled one or more records.

Suggest you create a test file that is only a few records (making sure at least one of them has an amount of $1,000) and run the problem program using this test data.

Also suggest that every field/variable that is ever used for working with the amount be checked to make sure it is defined as large enough to handle $10000.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post