Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to check if a field is holding proper decimal value or n

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to check if a field is holding proper decimal value or n
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: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Wed Feb 25, 2009 4:58 pm    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Wed Feb 25, 2009 5:47 pm    Post subject:
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    Post subject:
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: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Wed Feb 25, 2009 6:52 pm    Post subject:
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    Post subject:
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: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Wed Feb 25, 2009 7:03 pm    Post subject:
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    Post subject:
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: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Wed Feb 25, 2009 7:39 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts JES2 job size field matching Windows ... SRICOBSAS All Other Mainframe Topics 4 Tue Sep 05, 2017 5:49 pm
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us