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

Checking whether a Signed numeric field is numeric/not.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Sep 13, 2011 6:28 pm
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Sep 13, 2011 6:56 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Sep 13, 2011 6:58 pm
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: 1353
Location: Israel

PostPosted: Tue Sep 13, 2011 8:34 pm
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

Superior Member


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

PostPosted: Mon Sep 19, 2011 12:36 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Sep 19, 2011 1:13 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Sep 19, 2011 2:16 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Sep 19, 2011 3:41 pm
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

Superior Member


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

PostPosted: Mon Sep 19, 2011 7:22 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Sep 19, 2011 7:24 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts S0C7 - Field getting overlayed COBOL Programming 2
Search our Forums:

Back to Top