IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Problem with numeric variable redefined from alpha numeric


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kalyan.v

New User


Joined: 04 Feb 2008
Posts: 65
Location: Hyd

PostPosted: Thu Nov 26, 2009 9:35 pm
Reply with quote

Hi,

In my program there are two variables declared as follows

Code:

              10  CLMIN-TOTAL-CLAIM-PAID       PIC X(10).
              10  FILLER REDEFINES CLMIN-TOTAL-CLAIM-PAID.
                  15  CLMIN-TOT-CLAIM-PAID-R   PIC S9(8)V99.

              10  CLMIN-CLAIM-INT-AMT          PIC X(10).
              10  FILLER REDEFINES CLMIN-CLAIM-INT-AMT.
                  15  CLMIN-CLAIM-INT-AMT-R    PIC S9(8)V99.


and those variables are used in the program as follows

For first variable

Code:

DISPLAY 'CLMIN-TOT-CLAIM-PAID-R :' CLMIN-TOT-CLAIM-PAID-R.
DISPLAY 'WS-AMOUNT1 : ' WS-AMOUNT1.
ADD CLMIN-TOT-CLAIM-PAID-R        TO WS-AMOUNT1.
DISPLAY 'WS-AMOUNT1 : ' WS-AMOUNT1.


And results for this captured from sysout
Code:

CLMIN-TOT-CLAIM-PAID-R :-000020156
WS-AMOUNT1 : 000000009565B
WS-AMOUNT1 : 000000011580H


So the data coming from the input has "-" sign in the starting but cobol is ignoring that sign and adding the value to the WS-AMOUNT variable.

For the second variable
Code:

MOVE CLMIN-CLAIM-INT-AMT          TO WS-WORK-AMOUNT.
DISPLAY 'CLMIN-CLAIM-INT-AMT :' CLMIN-CLAIM-INT-AMT
MOVE WS-WORK-AMT-DOL              TO WS-CONV-AMT-DOL2.
MOVE WS-WORK-AMT-CENT             TO WS-CONV-AMT-CENT2.
MOVE WS-CONVERTED-AMOUNT2         TO WS-SIGNED-AMOUNT2.
DISPLAY 'WS-SIGNED-AMOUNT2 :' WS-SIGNED-AMOUNT2
IF WS-WORK-SIGN EQUAL '-'
   COMPUTE WS-SIGNED-AMOUNT2 = (WS-SIGNED-AMOUNT2 * -1)
DISPLAY 'WS-SIGNED-AMOUNT2 IF :' WS-SIGNED-AMOUNT2
ELSE
   COMPUTE WS-SIGNED-AMOUNT2 = (WS-SIGNED-AMOUNT2 * 1)
DISPLAY 'WS-SIGNED-AMOUNT2 ELS:' WS-SIGNED-AMOUNT2


Result for this code is

Code:

CLMIN-CLAIM-INT-AMT :000000-020
WS-SIGNED-AMOUNT2 :000000000-020
WS-SIGNED-AMOUNT2 ELS:000000000002{


So even though there is a "-" symbol in between the variable, it is ignoring the sign and multiplying the value with 1 and giving the result.

I am posting this query to know whether there is any compiler option that is making cobol to ignore the sign in the variable, because when i executed the same code in AIX cobol it is abending showing data execption.

Thanks,
Kalyan.v
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Nov 26, 2009 10:38 pm
Reply with quote

first part: CLMIN-TOT-CLAIM-PAID-R :-000020156 indicates that you are loading your garbage into the x-type definition of CLMIN-TOT-CLAIM-PAID-R.

had you made the description of CLMIN-TOT-CLAIM-PAID-R other than display, you would have had the data exception on MVS.


what are the data descriptions of the ws-amount/ws-signed-amount fields?

since this is were the error is occurring,
it would have been helpful to supply the descriptions of the fields.

in short, your problem is you don't know/understand how mvs cobol works. either read the application programmers manual or give us the data descriptions.

since you are using the x-type field to accept the -000020156, either use a separate numeric field and populate it with NUMVAL or define the display field CLMIN-TOT-CLAIM-PAID-R as sign separate leading.
because anything else is garbage and again,
mvs is doing what you told it to do - add garbage.

learn to stop using display fields (rookie!) for computations.....
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Nov 26, 2009 11:15 pm
Reply with quote

actually, you nothing will enable a numeric display field containing 000000-020 to work properly.

you are going to either convert leading zeroes to spaces and then populate a real/valid numeric field with NUMVAL.

numeric display in COBO is x-type except COBOL allows you to perform numeric computations.
Back to top
View user's profile Send private message
kalyan.v

New User


Joined: 04 Feb 2008
Posts: 65
Location: Hyd

PostPosted: Fri Nov 27, 2009 8:27 am
Reply with quote

Hi,

I added the displays only to explain the problem clearly

as i told earlier when i used the same code in AIX cobol it is showing data exception but not in MVS.

For the first variable at the add statement and for the second variable at the compute statement i am getting data exception in AIX.

please find below the data descriptions of the other variables i mentioned above.

Code:

01  WS-WORK-AMOUNT.
    05  WS-WORK-SIGN              PIC X    VALUE SPACE.
    05  WS-WORK-AMT-DOL           PIC X(7) VALUE SPACES.
    05  WS-WORK-AMT-CENT          PIC XX   VALUE SPACES.

01  WS-CONVERTED-AMOUNT2.
    05  WS-CONV-AMT-DOL2          PIC 9(11) VALUE ZEROES.
    05  WS-CONV-AMT-CENT2         PIC 99   VALUE ZEROES.

01  WS-SIGNED-AMOUNT2             PIC S9(11)V99 VALUE +0.00.

01  WS-AMOUNT1                    PIC S9(11)V99 VALUE +0.00.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Nov 27, 2009 9:23 am
Reply with quote

Hello,

Quote:
So the data coming from the input has "-" sign in the starting but cobol is ignoring that sign
Incorrect. There is no sign. It does not matter that you "see" a minus sign - the system does not. So, the system adds what it does see - a positive value.

Quote:
So even though there is a "-" symbol in between the variable, it is ignoring the sign and multiplying the value with 1 and giving the result.
No matter how much you want this to be a sign or treated like a sign, it is not. . .

Quote:
I am posting this query to know whether there is any compiler option that is making cobol to ignore the sign in the variable
No - because there is no sign to ignore.

As DBZ mentioned, to get things to work as desired, you need to make sure the values are "good" before usng them in comparisons or calculations. Worse than an abend would be processes that produce incorrect results that are not discovered in the early testing. . .
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Nov 27, 2009 5:41 pm
Reply with quote

You seem surprised that you get different results on AIX compared to z/OS -- why? Implementations vary by machine; COBOL is no different.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Nov 27, 2009 6:27 pm
Reply with quote

it appears that AIX does not provide the flexibility to handle non-numerics in numeric display type fields.

a fact that the TS is just a little too thickheaded to comprehend.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Nov 27, 2009 11:16 pm
Reply with quote

It appears as though the compiler on the mainframe has been modified to let as much junk thru as possible without causing an abend. Possibly because of the "stuff" coming in that is unedited/"invalid" and the overall weakness in fundamentals with a high % of the new coders/developers. . .

Long, long ago, (iirc) the abend would have happened on the mainframe as well. . . Of course there was no AIX in those days.

d
Back to top
View user's profile Send private message
kalyan.v

New User


Joined: 04 Feb 2008
Posts: 65
Location: Hyd

PostPosted: Sat Nov 28, 2009 9:28 am
Reply with quote

Hi all

Thanks for your valuable replies, the only solution i had with me is to correct the data and i did it.

thanks,
kalyan.v
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sat Nov 28, 2009 10:18 am
Reply with quote

Quote:
Long, long ago, (iirc) the abend would have happened on the mainframe as well. . .
Yes, COBOL was less forgiving, in some cases, than it is today, especially when it comes to manipulating numeric data.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Nov 28, 2009 6:19 pm
Reply with quote

kalyan.v wrote:
the only solution i had with me is to correct the data and i did it.


if you mean that you corrected the data before running the program,
you took the wrong approach.

what happens the next time the data is not correct?

you need to lay code in your program
to validate your data before the program processes the data
and report exceptions - Programming 101.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Nov 29, 2009 6:04 am
Reply with quote

Hello,

Where did this data come from?

If this is a file created within the application, there is no reason to ever have bad data. The code should prevent this. If the data came from a preceeding process, that process must be fixed.

If the data came from some untrusted source (user entry from a terminal, customer provided uploaded, some sloppily written other appilcation, etc), the first process to process the data should validate all of the data before using it.

Code should not be introduced "all over the place" to react to bad data where none should exist.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Sun Nov 29, 2009 1:22 pm
Reply with quote

Quote:
Code should not be introduced "all over the place" to react to bad data where none should exist.


it' s the new school of nonsense application development
it takes less time to fix it than to do it right icon_evil.gif
Back to top
View user's profile Send private message
kalyan.v

New User


Joined: 04 Feb 2008
Posts: 65
Location: Hyd

PostPosted: Mon Nov 30, 2009 8:42 am
Reply with quote

dbzTHEdinosauer wrote:
kalyan.v wrote:
the only solution i had with me is to correct the data and i did it.


if you mean that you corrected the data before running the program,
you took the wrong approach.

what happens the next time the data is not correct?

you need to lay code in your program
to validate your data before the program processes the data
and report exceptions - Programming 101.


Ya thats what i did, i validated the data in my code and replaced the junk data with zeros and it is now working fine.

Thanks.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Nov 30, 2009 9:37 am
Reply with quote

Hello,

Quote:
i validated the data in my code and replaced the junk data with zeros and it is now working fine.
Please re-read my previous post. . . Where did the data come from?

The code may no longer abend, but that does not necessarily mean that "it is now working fine". You may be discarding something that should not be discarded. . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
Search our Forums:

Back to Top