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

How to check if a field is holding proper decimal value or n


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

New User


Joined: 26 Dec 2007
Posts: 18
Location: Chennai, India

PostPosted: Wed Feb 25, 2009 4:41 pm
Reply with quote

Hi all,
I am facing an issue and in need of your help to solve it.

Code:

05 WS-AMOUNT-CHAR PIC X(20).
05 WS-AMOUNT-DEC  REDEFINES WS-AMOUNT-CHAR
                                 PIC -9(16).99.
05 WS-AMOUNT-SIGNED PIC S9(16)V99.

MOVE WS-AMOUNT-DEC  TO WS-AMOUNT-SIGNED


The issue I am facing is some times with production data WS-AMOUNT-CHAR is holding soe junk value like '**********'. In that case the MOVE statement fails with S0C7 abend.

My intention is to execute the MOVE if the WS-AMOUNT-DEC field is holding valid value. other wise I will move Zeroes to WS-AMOUNT-SIGNED.

I tried with is numeric on both WS-AMOUNT-DEC and WS-AMOUNT-CHAR but both returns false even if it holds some valid value like 0.00.

Please help
TIA
Sourav
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: Wed Feb 25, 2009 4:58 pm
Reply with quote

You should be able to say
Code:
IF  WS-AMOUNT-DEC NUMERIC
    MOVE WS-AMOUNT-DEC TO WS-AMOUNT-SIGNED
ELSE
    MOVE ZERO TO WS-AMOUNT-SIGNED
END-IF.
If this isn't working, add a display of WS-AMOUNT-DEC and post the output from a few lines.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Feb 25, 2009 5:47 pm
Reply with quote

WS-AMOUNT-DEC is actually an x-type field. (edit mask).

would suggest a
Code:

COMPUTE WS-AMOUNT-SIGNED
      = FUNCTION NUMVAL(WS-AMOUNT-DEC)
END-COMPUTE


(You may need to change the syntax for the NUMVAL depending on your compiler)
Back to top
View user's profile Send private message
sourav_dasgupta

New User


Joined: 26 Dec 2007
Posts: 18
Location: Chennai, India

PostPosted: Wed Feb 25, 2009 6:46 pm
Reply with quote

Robert,

If I do
Code:

IF  WS-AMOUNT-DEC NUMERIC
    MOVE WS-AMOUNT-DEC TO WS-AMOUNT-SIGNED
ELSE
    MOVE ZERO TO WS-AMOUNT-SIGNED
END-IF.

then the problem I am facing is, it is returning false even if WS-AMOUNT-DEC is containing 123.00
so in WS-AMOUNT-SIGNED zeroes are being moved.
I have added display as you said and checked in Xped.

While googling for this i found this
IBM-PK26004
But there is no solution or work around given.

The same is happening for me for a -9(16).99 field which is a signed edited numeric.

Thanks
Sourav
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: Wed Feb 25, 2009 6:52 pm
Reply with quote

When I look at PK26004, I see:
Quote:
This problem has been resolved with WebSphere Developer for
zSeries V6.0.1 Interim Fix 004 which will be available from
the Rational Product Updater or WDz product web download page:
which sounds like a fix to me -- resolved means fixed. Perhaps you should contact your site support group and have them apply this fix?

And why wouldn't WS-AMOUNT-DEC contain 0000000000000123.00? If it contains a batch of spaces and 123.00, then the field is not numeric and will fail the test no matter whether or not the PK26004 fix is applied.

You might want to use FUNCTION NUMVAL if you can have spaces in your value.
Back to top
View user's profile Send private message
sourav_dasgupta

New User


Joined: 26 Dec 2007
Posts: 18
Location: Chennai, India

PostPosted: Wed Feb 25, 2009 6:54 pm
Reply with quote

Dick,

If I use NUMVAL then if an junk value comes WS-AMOUNT-DEC then I think it will abend.
As WS-AMOUNT-DEC is a redefine of WS-AMOUNT-CHAR and WS-AMOUNT-CHAR can hold alphanumeric also, it is quite possible.
Have not tested though. I may be wrong too.

In normal scenario I am expecting one amount value in this field but in some one off scenarion i an getting junk values like '***********' also, which is alphanumeric.

Thanks
Sourav
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: Wed Feb 25, 2009 7:03 pm
Reply with quote

Run a loop across WS-AMOUNT-CHAR checking each character (via reference modification) to be space, +, -, a digit, or a decimal point. If you have anything else, put out an error message and don't use WS-AMOUNT-DEC. Otherwise, you can use FUNCTION NUMVAL to convert the value to a valid numeric and use it.
Back to top
View user's profile Send private message
sourav_dasgupta

New User


Joined: 26 Dec 2007
Posts: 18
Location: Chennai, India

PostPosted: Wed Feb 25, 2009 7:07 pm
Reply with quote

Robert,
Even if WS-AMOUNT-DEC contains 0000000000000123.23 (without any space, leading/trailing), then also the numeric check fails and returns false in my case. Maybe I need the site support team to apply the fix.
Thanks
Sourav
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: Wed Feb 25, 2009 7:39 pm
Reply with quote

From the COBOL Language Reference manual (link at the top of the page):
Quote:
NUMERIC
identifier-1 consists entirely of the characters 0 through 9, with or without an operational sign.
so having the period in the value makes it not numeric by definition. You can either redefine as two fields before and after the decimal point and check each separately, or use reference modification to check each byte one at a time.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Feb 26, 2009 8:10 am
Reply with quote

You can redef WS-AMOUNT-CHAR as WAC-SIGN, WAC-DIGITS,
WAC-DEC-PT and WAC-CENTS.

Then: (untested code)

Code:
IF WAC-SIGN NOT = (' ' AND '-')  (not sure about this compound)
   OR
   WAC-DIGITS NOT NUMERIC
   OR
   WAC-DEC-PT NOT = '.'
   OR
   WAC-CENTS NOT NUMERIC
   MOVE ' 0000000000000000.00' TO WS-AMOUNT-SIGNED
   (or whatever)
ELSE
   MOVE WS-AMOUNT-DEC TO WS-AMOUNT-SIGNED
END-IF
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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Join 2 files according to one key field. JCL & VSAM 3
Search our Forums:

Back to Top