Cobol Search statement optimization? 
Author Message
 Cobol Search statement optimization?

I am in an IBM TSO  Cobol MVS environment and am writing a program to
match on two sets of 200 byte fields.

here is the code:

SET ENG-INDEX TO 1.

SEARCH CUST-CD-ENG-BITS-TBL-3801
       AT END
          MOVE 'N' TO ANSWER-3801
       WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
        AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
             PART-ENG-BITS-TBL-3801 (ENG-INDEX) )
          MOVE 'Y'  TO ANSWER-3801
          MOVE '00' TO STATUS-CODE-3801.

This sub-program will run about 70,000 or 80,000 times a run.  I am
wondering if anyone has any experience with code optimization in cobol.
Is the search function the fastest way to do this or would a perform
varying be faster or maybe just unrolling the loop with if /or
statements.

I know in C the compilers optimize the code for the programmer (not
always, obviously).  Most loops get unrolled.  Are the cobol MVS
compilers smart enough to do this?  I have heard they are quite good but
could find nothing on the web concerning this.

thanks for your input.

mark juchems



Sat, 10 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?
1.  Does it make any sense to sort your table in this case?
2.  Do you really want to know when both table elements = 1?
        WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
         AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
              PART-ENG-BITS-TBL-3801 (ENG-INDEX) )
Quote:

> I am in an IBM TSO  Cobol MVS environment and am writing a program to
> match on two sets of 200 byte fields.

> here is the code:

> SET ENG-INDEX TO 1.

> SEARCH CUST-CD-ENG-BITS-TBL-3801
>        AT END
>           MOVE 'N' TO ANSWER-3801
>        WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
>         AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
>              PART-ENG-BITS-TBL-3801 (ENG-INDEX) )
>           MOVE 'Y'  TO ANSWER-3801
>           MOVE '00' TO STATUS-CODE-3801.

> This sub-program will run about 70,000 or 80,000 times a run.  I am
> wondering if anyone has any experience with code optimization in cobol.
> Is the search function the fastest way to do this or would a perform
> varying be faster or maybe just unrolling the loop with if /or
> statements.

> I know in C the compilers optimize the code for the programmer (not
> always, obviously).  Most loops get unrolled.  Are the cobol MVS
> compilers smart enough to do this?  I have heard they are quite good but
> could find nothing on the web concerning this.

> thanks for your input.

> mark juchems



Sat, 10 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?
Yes! It is pretty complicated but the two tables indicate which engine a part
fits on and which engine model a dealer can get a kickback from us for.  if
the part is used on an engine that a dealer can service, he gets the
kickback.  a '1' signifies he can.

(this might be greek but it works great, we hope...)

thanks.
mark

Quote:

> 1.  Does it make any sense to sort your table in this case?
> 2.  Do you really want to know when both table elements = 1?
>         WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
>          AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
>               PART-ENG-BITS-TBL-3801 (ENG-INDEX) )


> > I am in an IBM TSO  Cobol MVS environment and am writing a program to
> > match on two sets of 200 byte fields.

> > here is the code:

> > SET ENG-INDEX TO 1.

> > SEARCH CUST-CD-ENG-BITS-TBL-3801
> >        AT END
> >           MOVE 'N' TO ANSWER-3801
> >        WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
> >         AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
> >              PART-ENG-BITS-TBL-3801 (ENG-INDEX) )
> >           MOVE 'Y'  TO ANSWER-3801
> >           MOVE '00' TO STATUS-CODE-3801.

> > This sub-program will run about 70,000 or 80,000 times a run.  I am
> > wondering if anyone has any experience with code optimization in cobol.
> > Is the search function the fastest way to do this or would a perform
> > varying be faster or maybe just unrolling the loop with if /or
> > statements.

> > I know in C the compilers optimize the code for the programmer (not
> > always, obviously).  Most loops get unrolled.  Are the cobol MVS
> > compilers smart enough to do this?  I have heard they are quite good but
> > could find nothing on the web concerning this.

> > thanks for your input.

> > mark juchems



Sat, 10 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?
No problem Mark.  Simply put your two fields in the table under a group
item, and define a similar group in Working Storage, then be sure your
table is in sequence by that group item.  When you want to search, move
the two values you are looking for into the Working Storage fields and
SEARCH ALL for EQUAL TO the group item.  Assuming your compiler generates
a binary search for SEARCH ALL (almost certain), you're not going to get
much faster than that.  If it doesn't, then code a binary search. :-)
--

Sun Valley Systems    http://personal.bhm.bellsouth.net/~judmc
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."

Mark Juchems wrote

Quote:
>Yes! It is pretty complicated but the two tables indicate which engine a part
>fits on and which engine model a dealer can get a kickback from us for.  if
>the part is used on an engine that a dealer can service, he gets the
>kickback.  a '1' signifies he can.

>(this might be greek but it works great, we hope...)

>thanks.
>mark


>> 1.  Does it make any sense to sort your table in this case?
>> 2.  Do you really want to know when both table elements = 1?
>>         WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
>>          AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
>>               PART-ENG-BITS-TBL-3801 (ENG-INDEX) )


>> > I am in an IBM TSO  Cobol MVS environment and am writing a program to
>> > match on two sets of 200 byte fields.

>> > here is the code:

>> > SET ENG-INDEX TO 1.

>> > SEARCH CUST-CD-ENG-BITS-TBL-3801
>> >        AT END
>> >           MOVE 'N' TO ANSWER-3801
>> >        WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
>> >         AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
>> >              PART-ENG-BITS-TBL-3801 (ENG-INDEX) )
>> >           MOVE 'Y'  TO ANSWER-3801
>> >           MOVE '00' TO STATUS-CODE-3801.

>> > This sub-program will run about 70,000 or 80,000 times a run.  I am
>> > wondering if anyone has any experience with code optimization in cobol.
>> > Is the search function the fastest way to do this or would a perform
>> > varying be faster or maybe just unrolling the loop with if /or
>> > statements.

>> > I know in C the compilers optimize the code for the programmer (not
>> > always, obviously).  Most loops get unrolled.  Are the cobol MVS
>> > compilers smart enough to do this?  I have heard they are quite good but
>> > could find nothing on the web concerning this.

>> > thanks for your input.

>> > mark juchems



Sat, 10 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?
Mark,

Create a table that contains ONLY the ones where the flag is 1.
This will reduce the search over head at the cost of some setup.

The second thing is

 WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
         AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =

Howard pointed out that the nett effect is a check of the
  PART-ENG-BITS-TBL-3801 (ENG-INDEX) )
is '1' meaning that there is no need for the search at all.  I
would assume this is a typo though.

Third thing (just in case) load you table once into working
storage and then reference the working storage version from then
on.  I assume that you are doing this anyway but just for
completeness ie:

procedure division using parameters

if cust-cd-eng-bits-tbl (1) = zero
   perform create-table
end-if

(I am assuming that zero is NOT a valid value for the entry and
the table is intialised to this with a value statement).

HTH
Ken



Sun, 11 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?

Quote:

>Mark,

>Create a table that contains ONLY the ones where the flag is 1.
>This will reduce the search over head at the cost of some setup.

If Mark is *always* searching for CUST-CD-ENG-BITS-TBL-3801 = 1, that
would work fine.  But what if he needs to also search the table for 0,
2, 3, 999, etc?  Quadrupling the table size takes more memory, but it
only adds two more loops to the binary search, a negligible overhead.
He may also have other uses for that table in the program. :-)
--

Sun Valley Systems    http://personal.bhm.bellsouth.net/~judmc
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."


Sun, 11 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?

Thanks for all of the help, guys.

I am only looking for 1's.  A 1 indicates that the part fits on the
engine, a zero that it does not.

The idea from Ken about creating a table that only contains the ones is
intriguing because we are only setting the first 40 spaces in our table
right now and I was wondering how I can eliminate searching the rest of
the table.  However, that would take two additional perform untils and
might eliminate any speed gain.  Maybe I could set the final used space in
the table to a '2' and add that in my search.

SET ENG-INDEX TO 1.

SEARCH CUST-CD-ENG-BITS-TBL-3801
       AT END
          MOVE 'N' TO ANSWER-3801
       WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
        AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
             PART-ENG-BITS-TBL-3801 (ENG-INDEX) )
        OR (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 2)
          MOVE 'Y'  TO ANSWER-3801
          MOVE '00' TO STATUS-CODE-3801.

also, our search must be in order!  no binary searches.  we need to find
the first time a '1' is in both tables at the same location.
that is the problem in a nutshell.

mark juchems

Quote:


> >Mark,

> >Create a table that contains ONLY the ones where the flag is 1.
> >This will reduce the search over head at the cost of some setup.

> If Mark is *always* searching for CUST-CD-ENG-BITS-TBL-3801 = 1, that
> would work fine.  But what if he needs to also search the table for 0,
> 2, 3, 999, etc?  Quadrupling the table size takes more memory, but it
> only adds two more loops to the binary search, a negligible overhead.
> He may also have other uses for that table in the program. :-)
> --

> Sun Valley Systems    http://personal.bhm.bellsouth.net/~judmc
> "For God so loved the world that He gave His only begotten Son, that
> whoever believes in Him should not perish but have everlasting life."



Sun, 11 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?

Quote:
> The idea from Ken about creating a table that only contains the ones
> is intriguing because we are only setting the first 40 spaces in our
> table right now and I was wondering how I can eliminate searching the
> rest of the table.  However, that would take two additional perform
> untils and might eliminate any speed gain.  Maybe I could set the
> final used space in the table to a '2' and add that in my search.

Why would it add PERFORM UNTILs?  What do the PERFORM UNTILs do?

If that were a possibility, I would probably use a utility to create a
file with only '1's in it as the job step before your COBOL program.
Then you search for the first match of your two fields.

I'm still confused though:
  SEARCH CUST-CD-ENG-BITS-TBL-3801
       AT END
          MOVE 'N' TO ANSWER-3801
      WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
        AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
             PART-ENG-BITS-TBL-3801 (ENG-INDEX) )

Are those two fields in the same table?
     WHEN field1 = field2 = 1 ???    I'm trying to picture your business
requirements for this table but failing.

What does your working-storage look like?



Sun, 11 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?
I just pulled out the language reference manual to look at something
with the SEARCH command and noticed something I've never used:

SEARCH identifier-1 VARYING identifier-2
SEARCH identifier-2 VARYING index-name-1

How do you (I tried to write you'all but not being a southerner, I don't
know how to spell it) use this option?



Sun, 11 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?


:>Yes! It is pretty complicated but the two tables indicate which engine a part
:>fits on and which engine model a dealer can get a kickback from us for.  if
:>the part is used on an engine that a dealer can service, he gets the
:>kickback.  a '1' signifies he can.

:>(this might be greek but it works great, we hope...)

:>> 1.  Does it make any sense to sort your table in this case?
:>> 2.  Do you really want to know when both table elements = 1?
:>>         WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
:>>          AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
:>>               PART-ENG-BITS-TBL-3801 (ENG-INDEX) )

I believe that Howards issue is that as your first condition is  

         WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)

Then the second condition of

          AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
               PART-ENG-BITS-TBL-3801 (ENG-INDEX) )

as

          CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1

can be rewritten as

          AND (1 = PART-ENG-BITS-TBL-3801 (ENG-INDEX))

   [ snipped ]

--


http://www.dissensoftware.com

Director, Dissen Software, Bar & Grill - Israel



Sun, 11 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?
Yes, this would be better...
SET ENG-INDEX TO 1.

SEARCH CUST-CD-ENG-BITS-TBL-3801
       AT END
          MOVE 'N' TO ANSWER-3801
       WHEN    (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
           AND    PART-ENG-BITS-TBL-3801 (ENG-INDEX)= 1 )
          MOVE 'Y'  TO ANSWER-3801
          MOVE '00' TO STATUS-CODE-3801.

But my main question is speed!  Is the search function Fast or would it be better
to do it another way?  Is there another way?

mark juchems

Quote:



> :>Yes! It is pretty complicated but the two tables indicate which engine a part
> :>fits on and which engine model a dealer can get a kickback from us for.  if
> :>the part is used on an engine that a dealer can service, he gets the
> :>kickback.  a '1' signifies he can.

> :>(this might be greek but it works great, we hope...)


> :>> 1.  Does it make any sense to sort your table in this case?
> :>> 2.  Do you really want to know when both table elements = 1?
> :>>         WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
> :>>          AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
> :>>               PART-ENG-BITS-TBL-3801 (ENG-INDEX) )

> I believe that Howards issue is that as your first condition is

>          WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)

> Then the second condition of

>           AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
>                PART-ENG-BITS-TBL-3801 (ENG-INDEX) )

> as

>           CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1

> can be rewritten as

>           AND (1 = PART-ENG-BITS-TBL-3801 (ENG-INDEX))

>    [ snipped ]

> --


> http://www.dissensoftware.com

> Director, Dissen Software, Bar & Grill - Israel



Sun, 11 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?
This appears to be a function which you do once per program.  If so,
then speed isn't important.  Also, if so, why read in the whole table
file?

If it is done many times, why?  It will always find the same record.

Quote:

> Yes, this would be better...
> SET ENG-INDEX TO 1.

> SEARCH CUST-CD-ENG-BITS-TBL-3801
>        AT END
>           MOVE 'N' TO ANSWER-3801
>        WHEN    (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
>            AND    PART-ENG-BITS-TBL-3801 (ENG-INDEX)= 1 )
>           MOVE 'Y'  TO ANSWER-3801
>           MOVE '00' TO STATUS-CODE-3801.

> But my main question is speed!  Is the search function Fast or would it be better
> to do it another way?  Is there another way?

> mark juchems




> > :>Yes! It is pretty complicated but the two tables indicate which engine a part
> > :>fits on and which engine model a dealer can get a kickback from us for.  if
> > :>the part is used on an engine that a dealer can service, he gets the
> > :>kickback.  a '1' signifies he can.

> > :>(this might be greek but it works great, we hope...)


> > :>> 1.  Does it make any sense to sort your table in this case?
> > :>> 2.  Do you really want to know when both table elements = 1?
> > :>>         WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
> > :>>          AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
> > :>>               PART-ENG-BITS-TBL-3801 (ENG-INDEX) )

> > I believe that Howards issue is that as your first condition is

> >          WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)

> > Then the second condition of

> >           AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
> >                PART-ENG-BITS-TBL-3801 (ENG-INDEX) )

> > as

> >           CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1

> > can be rewritten as

> >           AND (1 = PART-ENG-BITS-TBL-3801 (ENG-INDEX))

> >    [ snipped ]

> > --


> > http://www.dissensoftware.com

> > Director, Dissen Software, Bar & Grill - Israel



Sun, 11 Nov 2001 03:00:00 GMT  
 Cobol Search statement optimization?
If you are using one of IBM's "strategic" mainframe COBOLs, e.g. IBM COBOL
for OS/390 & VM (and the original note did indicate that you were running on
MVS or OS/390) then their optimization is HIGHLY efficient.  If you compile
with the "LIST" compiler option, you can see the actual generated assembler
code - but I strongly doubt that you will come up with a more efficient set
of code than they do.

--
Bill Klein
    wmklein <at> ix dot netcom dot com

Quote:
> Yes, this would be better...
> SET ENG-INDEX TO 1.

> SEARCH CUST-CD-ENG-BITS-TBL-3801
>        AT END
>           MOVE 'N' TO ANSWER-3801
>        WHEN    (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
>            AND    PART-ENG-BITS-TBL-3801 (ENG-INDEX)= 1 )
>           MOVE 'Y'  TO ANSWER-3801
>           MOVE '00' TO STATUS-CODE-3801.

> But my main question is speed!  Is the search function Fast or would it be
better
> to do it another way?  Is there another way?

> mark juchems




> > :>Yes! It is pretty complicated but the two tables indicate which engine
a part
> > :>fits on and which engine model a dealer can get a kickback from us
for.  if
> > :>the part is used on an engine that a dealer can service, he gets the
> > :>kickback.  a '1' signifies he can.

> > :>(this might be greek but it works great, we hope...)


> > :>> 1.  Does it make any sense to sort your table in this case?
> > :>> 2.  Do you really want to know when both table elements = 1?
> > :>>         WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)
> > :>>          AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
> > :>>               PART-ENG-BITS-TBL-3801 (ENG-INDEX) )

> > I believe that Howards issue is that as your first condition is

> >          WHEN (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1)

> > Then the second condition of

> >           AND (CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) =
> >                PART-ENG-BITS-TBL-3801 (ENG-INDEX) )

> > as

> >           CUST-CD-ENG-BITS-TBL-3801 (ENG-INDEX) = 1

> > can be rewritten as

> >           AND (1 = PART-ENG-BITS-TBL-3801 (ENG-INDEX))

> >    [ snipped ]

> > --


> > http://www.dissensoftware.com

> > Director, Dissen Software, Bar & Grill - Israel



Sun, 11 Nov 2001 03:00:00 GMT  
 
 [ 45 post ]  Go to page: [1] [2] [3] [4]

 Relevant Pages 

1. Array optimization questions - order of statements for asm

2. Cobol-search the web quickly with Search Spaniel

3. Optimization help needed: Search and Replace using dictionary of parameters

4. help!: optimization of search problem (example code)

5. Search in Fujitsu Cobol Power Cobol

6. Search statement

7. Search order for USE statement

8. Help with syntax on an IF statement that searches a string

9. COBOL (lack of) optimization question

10. Microfocus Cobol, Optimization?

11. COBOL II optimization

12. copy statement in fujitsu's cobol.net

 

 
Powered by phpBB® Forum Software