View previous topic :: View next topic
|
Author |
Message |
hello2satish
New User
Joined: 21 Jul 2007 Posts: 5 Location: Mumbai
|
|
|
|
IN THE FOLLOWING PROGRAMM THERE IS VALIDATION THAT WS-ACCNO SHOULD ACCEPT ONLY NUMERIC VALUE (1,2....9.0) NO ALPHANUMERIC VALUES ARE ALLOWED BUT IT ACCEPT ALPHANUMERIC ALSO.
I WANT TO ACCEPT ONLY NUMERIC VALUE PLEASE HELP.
WHAT MODIFICATION DO I NEED TO DO IN FOLLOWING PROGRAMM ?
2000-MAIN.
DISPLAY "ACCOUNT NUMBER".
ACCEPT WS-ACCNO.
IF WS-ACCNO IS NUMERIC
AND WS-ACCNO > 0
MOVE WS-ACCNO TO D-ACCNO
ELSE
DISPLAY "INVALID ACCOUNT NUMBER"
DISPLAY "PLZ ENTER ACCOUNT NUMBER AGAIN"
GO TO 2000-MAIN
END-IF. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
First, learn what the "Caps Lock" key is used for......
Second, what is wrong with the code? |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Where are you executing this program? I guess not on mainframes.
Maybe you are writing this code in MS COBOL.
Then, just you need to declare the variable ws-accno as numeric, it should accept only numeric digits. |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
ACCEPT does not scrub the data for numeric or non-numeric. That has to be taken care of after the fact. Infact it doesn't even know what the data is until you press enter then I am guessing writes it into working storage as hex instead of numeric so non-numerics can be received. It is up to you as the programmer to scrub the data after input.
If you were to accept data from the standard console in any other language on any other platform the data read won't scrub the data either. It just reads and trys to dump the data to the variable. A benefit you may find in other languages is something like this
(What little c++ i remember, it may not be right syntactically)
int var1;
cin >> var1;
Now, the cin statement itself doesn't do any scurbbing of data. However when a non-integer value is input the cin statement will fail because it can't perform the assignment. But the cin (ACCEPT in the case of Cobol) would not fail in and of itself. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello Satish(?),
Do you have a resolution to your question?
As someone already asked, where are you running this program?
Is there some reason you are using ACCEPT to get data into your code? Most sites do not permit ACCEPT - especially to "retry" a bad entry.
How big is the field you are "accepting" - WS-ACCNO? You need to specify what is an acceptable and what should be an error. Please post some samples of various values and tell us which are "good" and which should be rejected. Keep in mind things like leading or trailing spaces. What about punctuation (dash or comma or . . .)? Once you tell us the rules, we can help on what you might do to validate your field is acceptable. |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Dick,
Doesn't the code originally posted ensure the field holds numeric data? I read the question as how can I remove checking for numeric and make ACCEPT only take in numeric values. I think the orignal poster doesn't want to do the validataion and thinks ACCEPT should take care of it for him. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Steve,
Quote: |
I think the orignal poster doesn't want to do the validataion and thinks ACCEPT should take care of it for him. |
Quite possibly. Maybe we will get more definition today.
Quote: |
Doesn't the code originally posted ensure the field holds numeric data? |
Depends on how this case defines "numeric". For example, some people/situations want 123,456 to be numeric. Time permitting, i'll try to put together a few examples later and run them thru code. |
|
Back to top |
|
|
hello2satish
New User
Joined: 21 Jul 2007 Posts: 5 Location: Mumbai
|
|
|
|
Yes i am writing this code in MS COBOL
my acc-no field is like PIC 9(15)
One thing i must admit that i am not very expert in COBOL like you people
The problem i am facing is like this..
If i enter the acc-no field as 1234abcd then it accept 1234 and truncate abcd and not throwing any error like invalid account number
and if i enter acc-no as abcd then only i am getting the above mentioned error
So my quetion is that it should accept numeric field only and should throw me the error like INVALID ACCOUNT NUMBER if accept anything except numeric value |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
You are not likely to find many MS COBOL experts on a mainframe web site. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
We had to write our own validation routines (this was with MicroFocus COBOL on unix - not MS-COBOL, but also non-mainframe).
Depending on user requirements, the definition of what was a valid numeric changed from case to case. For example, if we had to validate your acc-no, leading spaces would have become zeros and trailing spaces would have been truncated - embedded spaces would have been invalid. If a $ field was being validated, we had to accept numbers, commas, one decimal point, only the proper number of digits after the decimal, a minus-sign at the beginning or end of the value, possibly a currency-sign, and no embedded spaces. We also had to make sure that the "number" would fit in the receiving field.
Quote: |
So my quetion is that it should accept numeric field only and should throw me the error like INVALID ACCOUNT NUMBER if accept anything except numeric value |
To comletely do this, you will probably need to define your "rules" and implement code to enforce your rules.
You will want to look at the product documentation to see if there are other built-in functions that will give the results you want. If you want complete control, you will need to write routines that both validate the "input" and reformat it to what is acceptable for processing (like filling the left-most bytes with zeros if the numbers entered are not enough to fill the acc-no). |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Try this-
Declare the variable as alphanumeric so that it will accept alphanumeric input. Redefine that variable with numeric definition.
Code: |
01 WS-ALPHA-ACC PIC X(10).
01 WS-ACCNO REDEFINES WS-ALPHA-ACC PIC 9(10).
DISPLAY "ACCOUNT NUMBER".
ACCEPT WS-ALPHA-ACC.
IF WS-ACCNO IS NUMERIC
..... |
I havent worked in MS COBOL but still, do let us know the results. |
|
Back to top |
|
|
Help-Me-Out
New User
Joined: 09 Dec 2006 Posts: 56 Location: Pune
|
|
|
|
Hi,
I don't know MS-COBOL really.
But why don't you try this.
1.Accept the account no in PIC X(15).
2.Check the variable for spaces &/or characters.
3.If not present then valid otherwise invalid.
This is what we do in VS-COBOL II. correct me if wrong.
Thanks.
Sandy |
|
Back to top |
|
|
|