Solved

Cobol Q - Inspect part 2

Posted on 2001-06-08
10
501 Views
Last Modified: 2008-03-06
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
Comment
Question by:Paurths
  • 6
  • 4
10 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 200 total points
ID: 6171585
How about a different approach using UNSTRING instead of INSPECT


  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
         ADD 1 TO RESULT-CNT
         MOVE TALL-FLD TO PNTR
      END-IF
      ADD 1 TO PNTR
  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
 
LVL 12

Author Comment

by:Paurths
ID: 6171668
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.
        READ KK-file NEXT
           AT END
               SET einde-tel-zoeken TO TRUE;
        END-READ.

        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

         READ KK-file NEXT

           AT END

               SET einde-tel-zoeken TO TRUE;

         END-READ

        END-PERFORM.
0
 
LVL 12

Author Comment

by:Paurths
ID: 6171673
forgot a little part there :

thanx,
Ricky


ps: can u help me understand what is exactly happening using this method?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6171725
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

Anything more you need to know about it just ask.

Thanks for the A.  :^)

Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6171737
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
 
LVL 12

Author Comment

by:Paurths
ID: 6172030
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
 
LVL 12

Author Comment

by:Paurths
ID: 6173540
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
 
LVL 12

Author Comment

by:Paurths
ID: 6173549
Hi Cd&,

its ok, i just had a blackout...

Counter2    PIC Z9.

cheers
Ricky
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6178144
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
 
LVL 12

Author Comment

by:Paurths
ID: 6179087
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.
Stress is gone about exam.
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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
word0 challenge 4 68
wordcount challenge 11 121
firstswap challenge 20 77
creating threads in delphi 1 101
This article will show, step by step, how to integrate R code into a R Sweave document
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question