View previous topic :: View next topic
|
Author |
Message |
vimalravi83
New User
Joined: 28 Feb 2010 Posts: 21 Location: Bloomington, IL
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
vimalravi83
New User
Joined: 28 Feb 2010 Posts: 21 Location: Bloomington, IL
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Marso - I'd say it's TEMPorary!
How've you been, Sir! |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
seen a program with about 30 work/temporary variables
declared as
ws-work01
ws-work02
.....
ws-work28
what about that ? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
enrico-sorichetti wrote: |
seen a program with about 30 work/temporary variables
declared as
ws-work01
ws-work02
.....
ws-work28
what about that ? |
A fire-fighther's work-schedule for February (non-leap-year)? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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? |
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 |
|
|
|