Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I just wanted to say THANKS for the forum. The knowledge I gain from your site is invaluable..."

Geography

Where in the world do Tek-Tips members come from?
jiruld (Programmer)
12 Dec 07 22:35
Hi,

Can you help me come up with a code or routine that will check if the string has in-between spaces or space(s) in front?

Example:
Input PIC X(12)

The following case is considered INVALID:
1. ' Testing    '
2. '  Testing   '
2. 'T esting    '
3. 'Te sting    '
4. 'Testin     g'

Thanks,
Jerold :)
Glenn9999 (Programmer)
13 Dec 07 0:54
Try:

CODE

UNSTRING INPUT-VAR
     DELIMITED BY ALL SPACES
          INTO OUTPUT-TABLE (1) OUTPUT-TABLE (2)
      TALLYING PART-COUNT
END-UNSTRING.

And then you should be able to tell by the results it produces.
razalas (Programmer)
13 Dec 07 16:14
Jerold,

if the "4" (5) samples you gave are truly all examples of invalid data, then I would suggest something like the following:

CODE

MOVE ZERO TO SPACE-COUNT
INSPECT INPUT-FIELD (1:INPUT-LENGTH)
        TALLYING SPACE-COUNT FOR ALL SPACES
IF  SPACE-COUNT > ZERO
    DISPLAY "Input is Invalid!"
ELSE
    DISPLAY "Input is Valid"
END-IF

The hard part is knowing truly how long your input data is!

Code what you mean,
and mean what you code!
But by all means post your code!

Razalas

webrabbit (MIS)
13 Dec 07 17:37
Ok, this is ridiculous.

CODE

77 x1 binary.
77 x2 binary.
. . .
if input-var not = space
    perform varying x1 from length of input-var by -1 until input-var(x1:1) not = space
        continue
    end-perform
    move zero to x2
    inspect input-var(1:1) tallying x2 for all spaces
    if x2 > zero
        result is bad
    end-if
end-if
Some people suggest using the REVERSE function and INSPECT to find the length of the text, but unless it has hardware support, the REVERSE function is expensive.  Many years ago I was reviewing the new hardware functions for our new IBM mainframe.  I found a REVERSE function and wondered what it was for.  In my 45 year's of programming, I have needed to reverse a field once!
Glenn9999 (Programmer)
14 Dec 07 6:38
I don't think anyone is suggesting to reverse the text.  Besides for mine (which was tested), I don't think knowing the input length is too necessary.  Of course, efficiency is another matter for all these varied solutions, but that's a whole other topic.
mrregan (MIS)
14 Dec 07 6:53
input   pic x(12)
text1   pic x(12) value spaces
text2   pic x(12) value spaces

unstring input delimited by " " into text1, text2.
if input = spaces or text2 not = spaces display "input is invalid"
COBOLKenny (Programmer)
14 Dec 07 8:15
mrregan:
Your solution is similar to Glenn9999 except he delimited by All SPACE which is what is needed.  If the input has 2 leading spaces, with your delimiter, each space is a delimiter and both receiving fields end up with spaces.
ALL will treat both spaces as one delimiter.

A combination of Glenn's UNSTRING and your IF looks like the simplest solution.
jmanj (Programmer)
14 Dec 07 10:20
If I have to parse the question the need is to find:
"in-between spaces or space(s) in front?"

Then sample #1 is a valid assumption.
webrabbit (MIS)
14 Dec 07 10:27
No one has addressed the question of whether a completly bank input field is valid.
Glenn9999 (Programmer)
14 Dec 07 10:38
Since a question is coming up of a best solution, etc, etc here's what I coded when I originally posted to this thread:

CODE

 IDENTIFICATION DIVISION.
 PROGRAM-ID. TEST1.
 ENVIRONMENT DIVISION.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  PROC-VARS.
     05  INPUT-VAR                  PIC X(12).
     05  OUTPUT-TABLE               PIC X(12) OCCURS 2.
     05  PART-COUNT                 PIC S9(4) BINARY.
 PROCEDURE DIVISION.
     PERFORM UNTIL INPUT-VAR = "QUIT"
       DISPLAY "ENTER VALUE: "
       ACCEPT INPUT-VAR FROM CONSOLE
       MOVE 0 TO PART-COUNT
       MOVE SPACES TO OUTPUT-TABLE (1) OUTPUT-TABLE (2)
       UNSTRING INPUT-VAR
         DELIMITED BY ALL SPACES
            INTO OUTPUT-TABLE (1) OUTPUT-TABLE (2)
         TALLYING PART-COUNT
       END-UNSTRING
       IF (PART-COUNT > 1) OR (OUTPUT-TABLE (1) = SPACES)
         DISPLAY "HAS SPACES"
       ELSE
         DISPLAY "DOES NOT HAVE SPACES"
       END-IF
       DISPLAY "PART COUNT: " PART-COUNT
       DISPLAY "1: " OUTPUT-TABLE (1)
       DISPLAY "2: " OUTPUT-TABLE (2)
     END-PERFORM.
     GOBACK.

Quote:


No one has addressed the question of whether a completly bank input field is valid.

If I recall in my testing, all spaces was considered invalid.  But the OP hasn't stated that, indeed.
webrabbit (MIS)
14 Dec 07 15:17
Well, Glenn, your solution is the simplest to code, and considering the speed of today's computers, probably the best.

I think the OP has left the room.

I learned computers when the speed of an instruction was measured in many milliseconds.  One problem involving calulations of 200 digits.  Multiply was faster than Divide, so we precalculated the inverse of the divisor and used a Multiply.  Only problem, the time for Multiply was a small factor times the square of the number of digits.  The time for Divide was a large factor times the (number of digits + the sum of the digits in the quotient)  Multiply timeing: several hours per instruction.  Divide timing: about a second per instruction.  We reconverted the problem back to using a Divide.
mrregan (MIS)
14 Dec 07 15:43
(one less instruction than above)

input   pic x(12)
text1   pic x(12) value spaces

unstring input delimited by " " into text1.
if input = spaces or text1 not = input
   display "input is invalid" .

 
 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close