Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Checking with data entry

Status
Not open for further replies.

gonzilla

Programmer
Apr 10, 2001
125
US
Hey all,

Well, all is going well with the customer add\update\delete program...thanks for the help. I have a question about error checking.

My 800-Validate-Fields-rtn checks for many things like no leading spaces, numeric phone and zip code and no special charcters. This is all entered interactively by a user. It doesn't copy and past too well - sorry.

What I was wondering - is there a better way to check for special characters? I tryed defining it in the working storage

01 ws-spec-char pic x(n) value '$#^...etc'.

and checking for all ws-spec-char but it was looking for the whole literal '&*^()...etc'

Also, I'd like to make sure that the first letter of the first name, last name, city, address and if possible the first characters of an address and city with more than one word to it. It seems almost not worth it to go to all of that trouble, but there must be a somewhat easy way. Or do all customer records look like...

joHnSmitH 1888 STREET NAME city IL 60551

Thanks for the help.

-Tyler

800-VALIDATE-FIELDS-RTN.
INITIALIZE OPTION-SWITCHES
INITIALIZE ERROR-COUNTERS
INSPECT N-CUST-F-NAME TALLYING SPACES-CT FOR LEADADING SPACES
INSPECT N-CUST-F-NAME TALLYING SPECIAL-CT FOR ALL '*' '(' ')'
'!' '@' '^' '$' '#' '&' '+' '=' '{' '}' '[' ']' ':' ';' '/' '\'
'?' '>' '<' '%' '`' '_' '|'
IF SPACES-CT > 0
MOVE 'Y' TO ANY-ERRORS
MOVE '*LEADING SPACES NOT ALLOWED IN FIRST NAME' TO
ERROR-FNAME
ELSE
IF SPECIAL-CT > 0
MOVE 'Y' TO ANY-ERRORS
MOVE '*NO SPECIAL CHARACTERS ALLOWED' TO ERROR-FNAME
ELSE
MOVE '-OK' TO ERROR-FNAME
END-IF
END-IF
INITIALIZE ERROR-COUNTERS
INSPECT N-CUST-L-NAME TALLYING SPACES-CT FOR LEADING SPACES
INSPECT N-CUST-L-NAME TALLYING SPECIAL-CT FOR ALL '*' '(' ')'
'!' '@' '^' '$' '#' '&' '+' '=' '{' '}' '[' ']' ':' ';' '/' '\'
'?' '>' '<' '%' '`' '_' '|'
IF SPACES-CT > 0
MOVE 'Y' TO ANY-ERRORS
MOVE '*LEADING SPACES NOT ALLOWED IN LAST NAME' TO
ERROR-LNAME
ELSE
IF SPECIAL-CT > 0
MOVE 'Y' TO ANY-ERRORS
MOVE '*NO SPECIAL CHARACTERS ALLOWED' TO ERROR-LNAME
ELSE
MOVE '-OK' TO ERROR-LNAME
END-IF
END-IF
INITIALIZE ERROR-COUNTERS
INSPECT N-CUST-ADDRESS TALLYING SPACES-CT FOR LEADING SPACES
INSPECT N-CUST-ADDRESS TALLYING SPECIAL-CT FOR ALL '*' '(' ')'
'!' '@' '^' '$' '#' '&' '+' '=' '{' '}' '[' ']' ':' ';' '/' '\'
'?' '>' '<' '%' '`' '_' '|'
IF SPACES-CT > 0
MOVE 'Y' TO ANY-ERRORS
MOVE '*LEADING SPACES NOT ALLOWED IN ADDRESS' TO
ERROR-ADDRESS
ELSE
IF SPECIAL-CT > 0
MOVE 'Y' TO ANY-ERRORS
MOVE '*NO SPECIAL CHARACTERS ALLOWED' TO
ERROR-ADDRESS
ELSE
MOVE '-OK' TO ERROR-ADDRESS
END-IF
END-IF
INITIALIZE ERROR-COUNTERS
INSPECT N-CUST-CITY TALLYING SPACES-CT FOR LEADING SPACES
INSPECT N-CUST-CITY TALLYING SPECIAL-CT FOR ALL '*' '(' ')'
'!' '@' '^' '$' '#' '&' '+' '=' '{' '}' '[' ']' ':' ';' '/' '\'
'?' '>' '<' '%' '`' '_' '|'
IF SPACES-CT > 0
MOVE 'Y' TO ANY-ERRORS
MOVE '*LEADING SPACES NOT ALLOWED IN CITY' TO ERROR-CITY
ELSE
IF SPECIAL-CT > 0
MOVE 'Y' TO ANY-ERRORS
MOVE '*NO SPECIAL CHARACTERS ALLOWED' TO ERROR-CITY
ELSE
MOVE '-OK' TO ERROR-CITY
END-IF
END-IF
MOVE FUNCTION UPPER-CASE (N-CUST-STATE) TO N-CUST-STATE
SET STATE-SUB TO 1
SEARCH STATES-ALL
AT END
MOVE 'Y' TO ANY-ERRORS
MOVE '*STATE ENTERED DOES NOT EXIST' TO ERROR-STATE
WHEN N-CUST-STATE = STATES-ALL (STATE-SUB)
MOVE '-OK' TO ERROR-STATE
END-SEARCH
IF N-CUST-ZIP IS NOT NUMERIC
MOVE '*ZIP CODE MAY ONLY BE NUMBERS' TO ERROR-ZIP
ELSE
MOVE '-OK' TO ERROR-ZIP
END-IF
IF WS-NEW-PHONE IS NOT NUMERIC
MOVE 'Y' TO ANY-ERRORS
MOVE '*PHONE NUMBER MAY ONLY BE NUMBERS' TO ERROR-PHONE
ELSE
MOVE '-OK' TO ERROR-PHONE
END-IF
IF ERRORS
DISPLAY ERROR-SCREEN
ACCEPT GO-ON AT LINE 1 COL 1 WITH SECURE AUTO
ELSE
MOVE 'N' TO ANY-ERRORS
END-IF.
 
Hi Tyler,

Yuk. Here's a few hints/tips. Check out the CLASS clause of the SPECIAL-NAMES SECT. Then you can say &quot;IF SCR-FLD-1 HAS-INVALID-CHARS PERFORM 200-THIS-IS-A-NO-NO, instead of all that messy logic.

For numerics look at the NUMVAL-C function. Also look at STRING/UNSTRING to string 1st, mid, last etc. with one separating space.
 
Slade,

I feel that I should know about the SPECIAL-NAMES SECTION...but I've never heard about it and I can't find a reference to it in my book. Where can I find out about it? Or, do you have an example I can see?

The NUMVAL-C is covered in my book, but we didn't cover the functions too well in class. How does that help when checking for numeric? Right now, I just have it as:

IF N-CUST-ZIP IS NOT NUMERIC...

Is the NUMVAL-C better in some way?

The string/unstring is familiar to me. I was just checking to see if there was a way not as apparent to me. I just don't like missing things, you know?

Thank you for your help.

-Tyler
 
Hi Tyler,

Sorry, but it's not a SECT, it's a pgraph. It looks like this (abbrevs are mine):
Code:
ENVIR DIV.
CONFIG SECT.
SPECIAL-NAMES. CLASS HAS-INVALID-CHARS   
   '*' '(' ')' '!' '@' '^' '$' '#' '&' '+' '=' '{' '}' '['     ']' ':' ';' '/' '\' '?' '>' '<' '%' '`' '_' '|'.
           
PROC DIV.

Instead of this:

INITIALIZE OPTION-SWITCHES
INITIALIZE ERROR-COUNTERS
INSPECT N-CUST-F-NAME TALLYING SPACES-CT FOR LEADING SPACES
INSPECT N-CUST-F-NAME TALLYING SPECIAL-CT FOR ALL 
'*' '(' ')' '!' '@' '^' '$' '#' '&' '+' '=' '{' '}' '[' ']' ':' ';' '/' '\' '?' '>' '<' '%' '`' '_' '|'
IF SPACES-CT > 0
   MOVE 'Y' TO ANY-ERRORS
   MOVE '*LEADING SPACES NOT ALLOWED IN FIRST NAME' TO
        ERROR-FNAME
ELSE
   IF SPECIAL-CT > 0
      MOVE 'Y' TO ANY-ERRORS
      MOVE '*NO SPECIAL CHARACTERS ALLOWED' TO ERROR-FNAME
   ELSE
      MOVE '-OK' TO ERROR-FNAME
   END-IF
END-IF
           

It would look like this:

IF N-CUST-F-NAME(1:1) = SPACE
   MOVE 'Y' TO ANY-ERRORS
   MOVE '*LEADING SPACES NOT ALLOWED IN FIRST NAME' TO
        ERROR-FNAME
ELSE   
   IF N-CUST-F-NAME HAS-INVALID-CHARS 
      MOVE 'Y' TO ANY-ERRORS
      MOVE '*NO SPECIAL CHARACTERS ALLOWED' TO ERROR-FNAME
   ELSE
      MOVE '-OK' TO ERROR-FNAME
   END-IF
END-IF

Call it pride of ownership, but I think mine reads better. And that's the important part; both will yield the same results. You'll find that I talk more about reading than writing.

I'll let you chew on this a while. In the meantime, I'll work on the other two.

Regards, Jack.
 
Hey Jack,

I agree. I think it will make the whole routine read much nicer since I won't have to repeat the special characters over and over for each field.

I've never heard of or seen the CLASS clause like that. Is it perhaps not covered in my COBOL course? It seems very useful. So, the SPECIAL-NAMES is a paragraph in the CONFIG SECTION? Are there others that might be useful to know about? I think my last term skipped this! :)I

Thanks again.

-Tyler
 
Hi Tyler,

Don't feel bad, there are a lot of people out here who haven't heard of or used it. One can't know everything, but it's always a good idea to try.

As I've said before, I'm a mainframe guy, so keep that in mind whenever I suggest anything. What may work for me may not for you. Have you tried the CLASS trick yet? I suggest that you try it with 1 or 2 lits at first; no sense of doing all that code if you can't use it.

Re. your ques about COBOL reading you can look at mainframe manuals at Just select the COBOL manuals. Then select the &quot;reference&quot; manual for detailed code syntax and the &quot;programmers (or ing) giude for &quot;COBOL MVS and VM&quot;

Regards, Jack.

P.S. I've had 2nd thoughts about NUMVAL-C, I'll let you know later.
 
All,

i'd like to add something that is applicable to all similar situations, not just the specail char thing:
I you have a certain action, i.e. a validation, a piece of processing, etc, which is used at a number of different places look if it can be made into a standard piece of coding and stuff it in its own paragraph. Every time you'll need to perform this action, you actually will (performing, that is):

...
MOVE SOME-FIELD TO CHECK-FIELD
PERFORM CHECK-FOR-SPEC-CHARS
IF NO-SPEC-CHARS
do the right thing
ELSE
scream murder.

or somthing like that.

Regards,
Ronald.
 
Unless I misunderstand the CLASS construct, to evaluate to true in a class test, the field must contain ONLY characters that are members of the class. If the character set you're working with is ASCII, you might reverse your logic replace slade's CLASS with:

CLASS VALID-NAME-CHARS IS &quot;A&quot; THRU &quot;Z&quot;
&quot;a&quot; THRU &quot;z&quot;
&quot; &quot; &quot;'&quot; &quot;-&quot;.

Note this approach must be modified somewhat if the letters don't occur in an uninterrupted sequence (e.g. EBCDIC).

You may also consider using an 88-level if your compiler doesn't support CLASSes:

05 WS-TEST-CHAR PIC X.
88 TEST-CHAR-IS-VALUE VALUES &quot;A&quot; THRU &quot;Z&quot; etc.

Good luck!

Glenn Mitchell
Brainbench MVP for COBOL II
 
Tyler,

if it's just characters and spaces you want to allow, you can use the ALPHABETIC test, which works similar to the well known NUMERIC test.

Regards,
Ronald.

 
Thanks for all of the suggestions!

I did a combination of some of them so far. I have the CLASS clause (which works great) and I have it so it only is written once. To do this, I move the field I'm checking to a holding area and perform a routine that checks the hold. It also blanks out the hold area after checking and the next field is moved to hold. It shortens everything up and makes it easier to read.

Thanks again everybody! Let me know if you think of anything else.

-Tyler
 
Hi Glenn,

You're right, of course. It's funny, I know how the CLASS function works; I must have had another brain cramp. Thanks for finding the error.

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top