View previous topic :: View next topic |
Author |
Message |
ayush Beginner
Joined: 26 Feb 2004 Posts: 20 Topics: 14
|
Posted: Fri Feb 24, 2006 2:01 pm Post subject: Search Vs Conditional Variables. |
|
|
Hi,
I have to use a condition in my program where in
an input variable is compared with a list of values around 50 of them.
I can either have these values loaded in a table and search the table
for matches with this input variable, or
use a 88 level variable for these values and use an IF condition
for the input variable.
Condition 1:
Load the values of ABCD, EFGH,1234, PQRS, IKJH into a table reading from an input file.
Search the variable WS-SCREEN for matches in the table
and if any match found, perform LOGIC1 else LOGIC2.
Condition 2:
EG:
In working storage:
01 WS-HI-RISK PIC X(4) VALUE SPACES.
88 HI-RISK-YES VALUES 'ABCD' 'EFGH' '1234' 'PQRS' 'IJKH'
MOVE WS-SCREEN TO WS-HI-RISK
IF HI-RISK-YES
LOGIC 1
ELSE
LOGIC 2
END-IF.
My question:
What would be better, if I have 1400 such input variables WS-SCREEN for each record read in the program. So if there are 50 records, it'll be 40 *1400 * 50 (nbr of table variables),
or
Should I use the condition variables as I mentioned in option2.
Please suggest.
Thankyou.
Ayush |
|
Back to top |
|
|
Mervyn Moderator
Joined: 02 Dec 2002 Posts: 415 Topics: 6 Location: Hove, England
|
Posted: Sat Feb 25, 2006 6:04 am Post subject: |
|
|
Ayush, make sure your table is in sequence, then use SEARCH ALL. This will perform a binary search, which is very efficient.
With only 1400 input records, of course, it may be difficult to detect a difference in run time! _________________ The day you stop learning the dinosaur becomes extinct |
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Sun Feb 26, 2006 10:16 am Post subject: |
|
|
There is another technique that I use sometimes. I do not know, how it looks on performance scale. But, here it is anyway.
Code: |
IDENTIFICATION DIVISION .
PROGRAM-ID. SRCHSTR .
AUTHOR. Nagesh .
*
DATA DIVISION.
*
WORKING-STORAGE SECTION.
*
01 W001-VALUES-LIST PIC X(24)
VALUE 'ABCD,EFGH,1234,PQRS,IJKH' .
01 W001-TEST-STR PIC X(04) VALUE SPACE .
01 W001-NUM-POS PIC 9(04) VALUE ZERO .
*
PROCEDURE DIVISION .
Move '1234' To W001-TEST-STR .
Inspect W001-VALUES-LIST Tallying
W001-NUM-POS For All
W001-TEST-STR
.
Display 'Count for 1234: ' W001-NUM-POS .
Move Zero To W001-NUM-POS .
Move 'XXXX' To W001-TEST-STR .
Inspect W001-VALUES-LIST Tallying
W001-NUM-POS For All
W001-TEST-STR
.
Display 'Count for XXXX: ' W001-NUM-POS .
STOP RUN .
|
Output:
Code: |
----+----1----+----2--
Count for 1234: 0001
Count for XXXX: 0000
|
Why is the list of values having embedded comas ? 8) _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
Mervyn Moderator
Joined: 02 Dec 2002 Posts: 415 Topics: 6 Location: Hove, England
|
Posted: Sun Feb 26, 2006 6:31 pm Post subject: |
|
|
That's a useful technique. I haven't used it in Cobol before, but I've found it very handy in Selcopy, for example.
I'll let someone else tell you why you put the commas in! _________________ The day you stop learning the dinosaur becomes extinct |
|
Back to top |
|
|
Jaya Beginner
Joined: 02 Sep 2005 Posts: 77 Topics: 10 Location: Cincinnati
|
Posted: Sun Feb 26, 2006 11:38 pm Post subject: |
|
|
Quote: | Why is the list of values having embedded comas ? |
Hope, it is to avoid selecting other combination of the listed values.
Thanks,
Jaya. _________________ "Great spirits have always encountered violent opposition from mediocre minds."
-Albert Einstein |
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Mon Feb 27, 2006 1:00 am Post subject: |
|
|
Yes, Jaya. That is correct ! _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
|
|