x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 545

# Cobol Q - Inspect part 2

hi,

well, i'm having trouble using the inspect method.

I have a field in a record where the user can enter keywords, and later on it should be possible to retrieve the correct records using an inspect on that field.

example:

fieldname is : KKKeys   PIC X(25).
searchstring is : Find-word    PIC X(10).

suppose i have 4 records like these:

SCORE WHY NOTHING
WHY NOTHING REGARDS
PLEASURE WITHIN WITHOUT
NOTHING HERE SCORE

Find-word = SCORE
Result = 1 (last record)

Find-word = WHY
Result = 0 (none found)

i guess the trouble is with spaces.
Is there an approach to get the 'perfect' results, or does one need to settle for a solution 'in the middle'?

cheers
Ricky

0
Paurths
• 6
• 4
1 Solution

Commented:

01 TARGETS.
05 TARGET-1         PIC X(10).
05 TARGET-2         PIC X(10).
05 TARGET-3         PIC X(10).
05 TARGET-4         PIC X(10).
05 TARGET-5         PIC X(10).
05 TARGET-6         PIC X(10).
05 TARGET-7         PIC X(10).
05 TARGET-8         PIC X(10).
05 TARGET-9         PIC X(10).
05 TARGET-10        PIC X(10).

01 TARGETS-R REDEFINES TARGETS.
05 THETARGET        PIC X(10)    OCCURS 10.

01 TALL-FLD           PIC 9(2).
01 PNTR               PIC 9(2).

Then for each record:

INITIALIZE TARGET TALLY-FLD PNTR

UNSTRING KKeys DELIMITED BY ALL SPACE INTO
TARGET-1 TARGET-2 TARGET-3 TARGET-4 TARGET-5 TARGET-6
TARGET-7 TARGET-8 TARGET-9 TARGET-10
TALLYING IN TALLY-FLD

MOVE 1 TO PNTR
PERFORM UNTIL PNTR > TALLY-FLD
IF THETARGET (PNTR) = FIND-WORD
THEN
MOVE TALL-FLD TO PNTR
END-IF
END-PERFORM

That breaks the word out into an array for straight comparison

If you have to use INSPECT, post the code you are using, but its
a lot tougher to get it reliable.

Cd&

0

Author Commented:
Cd&,

u are amazing !

I can't believe this.
All i had to do was change the names to the real names i am using, implemented it and... voila , the correct results are shown.

I was thinking about the unstring-method, but to tell the truth, i could not manage to handle what was happening inside the procedure.

In fact i am still trying to figure out what exactly happens now, in your code.

this is the complete code i use now.

Telling-KK.
*----------------------

MOVE 0 TO Teller-gevonden.
MOVE LOW-VALUE TO KKnr.

START KK-file KEY >= KKnr
INVALID KEY
SET einde-tel-zoeken TO TRUE;

END-START.
AT END
SET einde-tel-zoeken TO TRUE;

PERFORM UNTIL einde-tel-zoeken;

INITIALIZE TARGETS TALL-FLD PNTR

UNSTRING KKSleutels DELIMITED BY ALL SPACE INTO
TARGET-1 TARGET-2 TARGET-3 TARGET-4 TARGET-5
TARGET-6 TARGET-7 TARGET-8 TARGET-9 TARGET-10
TALLYING IN TALL-FLD

MOVE 1 TO PNTR
PERFORM UNTIL PNTR > TALL-FLD
IF THETARGET (PNTR) = Zoek-woord THEN
DISPLAY kknr AT ROW-COLUMN;
ADD 1 to RIJ GIVING RIJ;
ADD 1 TO Teller-gevonden GIVING Teller-gevonden
MOVE TALL-FLD TO PNTR
END-IF

DISPLAY "aantal gevonden : " AT 0702;
DISPLAY Teller-gevonden AT 0720;
ADD 1 TO PNTR GIVING PNTR

END-PERFORM

AT END

SET einde-tel-zoeken TO TRUE;

END-PERFORM.
0

Author Commented:
forgot a little part there :

thanx,
Ricky

ps: can u help me understand what is exactly happening using this method?
0

Commented:
Sure enough
Just incase you didn't understand the redefinition, that creates two different definition for the same
area of memory which allows the same locations to be reference in more than one way a common
way to handle string problems.

PERFORM UNTIL einde-tel-zoeken;
* Set all the targets tto spaces so nothing gets carried over an set the two numeric fields to zero
* for the same reason
INITIALIZE TARGETS TALL-FLD PNTR
*input the string KKSleutels and out put to the target fields by breaking into sub-string at any
*point in the string where there is one or more spaces or end of string for each target populated
*add 1 to the tallying field TALL-FLD

UNSTRING KKSleutels DELIMITED BY ALL SPACE INTO
TARGET-1 TARGET-2 TARGET-3 TARGET-4 TARGET-5
TARGET-6 TARGET-7 TARGET-8 TARGET-9 TARGET-10
TALLYING IN TALL-FLD
* set the subscript to point at the first entry in the array

MOVE 1 TO PNTR
* if the string was empty the TALL-FLD will be zero and the loop will execute zero times
PERFORM UNTIL PNTR > TALL-FLD
*each element fo the array get compared to the search argument Zoek-woord
IF THETARGET (PNTR) = Zoek-woord THEN
* when the fields match process the hit
DISPLAY kknr AT ROW-COLUMN;
ADD 1 to RIJ GIVING RIJ;
ADD 1 TO Teller-gevonden GIVING Teller-gevonden
*Once there is a hit there is no need to continue through the array, so set the subscript to the
*maximum value and the increment will cause the loop to terminate -- more efficient that way
MOVE TALL-FLD TO PNTR
END-IF

DISPLAY "aantal gevonden : " AT 0702;
DISPLAY Teller-gevonden AT 0720;
*increment the subscript to point to the next element in the array.  If the value is greater than
*the number of entries in the array, the loop will terminate
ADD 1 TO PNTR GIVING PNTR

END-PERFORM
*now you can go to the next record

Thanks for the A.  :^)

Cd&
0

Commented:
Ricky,

I just noticed you puts the points up to 200.  You don't need to do that.  The Qs are not that hard and you made need points to ask more Qs before you finish learning COBOL.

Cd&
0

Author Commented:
Hi Cd&,

i give u those points with the most pleasure, for helping me understand what i have so far learned about Cobol.

This will probably be my last Q for a little while.
My program is just about finished , it needs the 'beauty touch' and a little debugging.

Also for this last Q, i'm figuring out what to do when the result of the search returns like 35 articles or so.
I guess when the counter moves over 10, stop " "; and ask the user to press enter to view the next series.

This program should have been finished next thursday, but the way it is going at the moment (real smooth :-) i'll have it finished last on sunday evening.

lol, in fact i'd better, b/c my girlfriend is just about to explode.
She's due for june 20, but i think the baby might pop-out a little sooner.

cheers
Ricky
0

Author Commented:
Hi CD&,

got a small problem.
When i use the counter and i show it on the screen it will show 01, 02, 03, 04, ....

How do i get rid of the zeros?

cheers
Ricky
0

Author Commented:
Hi Cd&,

its ok, i just had a blackout...

Counter2    PIC Z9.

cheers
Ricky
0

Commented:
LOL @ its ok, i just had a blackout...

That is normal for COBOL programmers.  You solve something complex and then go blank on a no-brainer.

I think the solution of giving them 10 at a time is a good approach and probably what a user would expect.

I also assume you are giving them some type of message when there are zero hits, so they know what is going on.

Good luck with the baby. :^)

Cd&
0

Author Commented:
Hi Cd&,

i always show the total that is found.
When this is 0, i also show the message 'Press enter to continue'.
When it is more then 10 , show first 10, 'Press enter to view next'. I used this in ASP also to show results of a query and it works in both as a charm.

thanx ,
lol, it seems the baby is stoburn.
I think it (no gender told, my girlfriend would kill me :-)
will come on thursday.
The programm is not perfect, but for 3 weeks of work it is more than 60% of what the rest of the class can show (they did in 6 weeks)

thanx again Cd&,

cheers
Ricky
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.