Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Checking whether a Signed numeric field is numeric/not.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
vimalravi83

New User


Joined: 28 Feb 2010
Posts: 21
Location: Bloomington, IL

PostPosted: Tue Sep 13, 2011 5:34 pm    Post subject: Checking whether a Signed numeric field is numeric/not.
Reply with quote

Please guied me how to check whether a Signed numeric field is numeric/not.

I have a field named WS-TEMP declared a s PIC +12.99. I need to check if it is numeric or not. To dod so i tried spiltting up the field & check it separately. I cant check the one with + sign. Pls help me with it.

I tried looking for some previous posts on this topic but couldn't find any.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Sep 13, 2011 6:12 pm    Post subject:
Reply with quote

Quote:
I have a field named WS-TEMP declared a s PIC +12.99


BS

when you want to start communicating in something besides guesses and bs,
someone may want to assist you with a subject,
much easier learned by reading the application programmers manual
and the language reference.

and you lie..........there have been threads, lately, about this very beginner problem.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7908
Location: Bellevue, IA

PostPosted: Tue Sep 13, 2011 6:28 pm    Post subject:
Reply with quote

Quote:
I have a field named WS-TEMP declared a s PIC +12.99.
Uh, no you don't. If you tried this, the COBOL compiler returns:
Quote:
77 WS-OP PIC +12.99.
S Character(s) "12" were found as "PICTURE" string character(s). A
"PICTURE" string of "S9(1)" was assumed.
If you cannot even tell us what you really have coded, how do you expect us to help you?
Back to top
View user's profile Send private message
vimalravi83

New User


Joined: 28 Feb 2010
Posts: 21
Location: Bloomington, IL

PostPosted: Tue Sep 13, 2011 6:39 pm    Post subject:
Reply with quote

Thank you!
Well, in the copyboook the variable WS-TEMP is declared as PIC +12.99 & the value assigned to it in the dataset is +350.85.
I wanted to check whether the field WS-TEMP is numeric or not. I couldn't do so using the usual numeric check method like:-

IF WS-TEMP IS NUMERIC
CONTINUE
ELSE
MOVE ZEROS TO WS_TEMP.

I declared another variable WS-TEMP1 as 9(12).99 and moved value in it..the value is getting moved properly into this...but not able to do a NUMERIC check!!!
I am able to do numeric check for the floating point part alone but not for the value in 9(12) part!! :-(
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7908
Location: Bellevue, IA

PostPosted: Tue Sep 13, 2011 6:56 pm    Post subject:
Reply with quote

From the COBOL Language Reference manual (link at the top of this page), section 6.1.6.2:
Quote:
NUMERIC
identifier-1 consists entirely of the characters 0 through 9, with or without an operational sign.

If its PICTURE does not contain an operational sign, the identifier being tested is determined to be numeric only if the contents are numeric and an operational sign is not present.

If its PICTURE does contain an operational sign, the identifier being tested is determined to be numeric only if the item is an elementary item, the contents are numeric, and a valid operational sign is present.

Note: Valid operational signs are determined from the setting of the NUMCLS installation option and the NUMPROC compiler option. For more information, see the Enterprise COBOL Programming Guide .
A variable defined as 9(12).99 has a characer that is neither a numeric digit nor operational sign -- namely, the decimal point. If you had defined the variable as 9(12)V99, your IF NUMERIC test would have worked.

Quote:
Well, in the copyboook the variable WS-TEMP is declared as PIC +12.99
Prove this by copying and pasting the compile of the program showing the WS-TEMP definition -- since I've already shown that the compiler will not allow +12.99 as a variable definition.
+9(12).99 would be valid, but not +12.99.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Tue Sep 13, 2011 6:58 pm    Post subject: Reply to: Checking whether a Signed numeric field is numeric
Reply with quote

Assuming that what you actually have is +9(12).99, this is a "numeric-edited" field.

If it is already in your copybook like that, why do you want to test it for numeric?

If you do,

Code:
01  afieldofwhatevernameyoufancy.
    05  afieldtotestthesign PIC X.
    05  afieldtotesttheintegerpart PIC X(12).
    05  afieldtotestthedecimalplace PIC X.
    05  afieldtotestthedecimalpart PIC XX.


Test the 2nd and 4th for numeric. Test the 3rd for ".". Test the 1st for a valid result after using "+" in a numeric-edited PICTURE (check the manual).
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Tue Sep 13, 2011 8:34 pm    Post subject: Re: Checking whether a Signed numeric field is numeric/not.
Reply with quote

vimalravi83 wrote:
I have a field named WS-TEMP
As we all like field names with a meaning, I guess that this is a temperature...

Quote:
declared a s PIC +12.99.
It could be +(12).99

What is the real PIC ?
Is there always a sign, and can the sign be '-' too ?
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Sep 19, 2011 12:36 pm    Post subject:
Reply with quote

Marso - I'd say it's TEMPorary! icon_biggrin.gif

How've you been, Sir! icon_smile.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Sep 19, 2011 1:13 pm    Post subject: Reply to: Checking whether a Signed numeric field is numeric
Reply with quote

seen a program with about 30 work/temporary variables
declared as
ws-work01
ws-work02
.....
ws-work28

what about that ? icon_cool.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Sep 19, 2011 2:16 pm    Post subject: Re: Reply to: Checking whether a Signed numeric field is num
Reply with quote

enrico-sorichetti wrote:
seen a program with about 30 work/temporary variables
declared as
ws-work01
ws-work02
.....
ws-work28

what about that ? icon_cool.gif


A fire-fighther's work-schedule for February (non-leap-year)?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Sep 19, 2011 3:41 pm    Post subject: Reply to: Checking whether a Signed numeric field is numeric
Reply with quote

Humour aside (from my post, I like it in Marso's) Marso makes an excellent point.

If you are going to be a sloppy programmer, then you just come up with the first name you think of, so for a "temporary" field, "temp". If you are a bit more of a thinker, you come up with a meaningful name, even for a "temporary" field.

So, Marso was giving the benefit of the doubt (or of irony).

If you want to post problems here, and avoid "irony" and its various relatives, use meaninful data-names.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Sep 19, 2011 7:22 pm    Post subject: Re: Reply to: Checking whether a Signed numeric field is num
Reply with quote

Bill Woodger wrote:
A fire-fighther's work-schedule for February (non-leap-year)?
If the fire-fighther's work for 30-days, we invoke another program? icon_eek.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Sep 19, 2011 7:24 pm    Post subject: Re: Reply to: Checking whether a Signed numeric field is num
Reply with quote

Anuj Dhawan wrote:
Bill Woodger wrote:
A fire-fighther's work-schedule for February (non-leap-year)?
If the fire-fighther's work for 30-days, we invoke another program? icon_eek.gif


Yes, sub-routines, one for each month so you can re-use some of the data-names (WS-TEMP1, WS-TEMP2 etc). Sub-routines called PROGB, PROGC, PROGD, etc.
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 Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Amount field is getting corrupted whe... thesumitk SYNCSORT 5 Tue Oct 18, 2016 8:20 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us