MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Search Vs Conditional Variables.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
ayush
Beginner


Joined: 26 Feb 2004
Posts: 20
Topics: 14

PostPosted: Fri Feb 24, 2006 2:01 pm    Post subject: Search Vs Conditional Variables. Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger
Mervyn
Moderator


Joined: 02 Dec 2002
Posts: 415
Topics: 6
Location: Hove, England

PostPosted: Sat Feb 25, 2006 6:04 am    Post subject: Reply with quote

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
View user's profile Send private message
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Sun Feb 26, 2006 10:16 am    Post subject: Reply with quote

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
View user's profile Send private message
Mervyn
Moderator


Joined: 02 Dec 2002
Posts: 415
Topics: 6
Location: Hove, England

PostPosted: Sun Feb 26, 2006 6:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
Jaya
Beginner


Joined: 02 Sep 2005
Posts: 77
Topics: 10
Location: Cincinnati

PostPosted: Sun Feb 26, 2006 11:38 pm    Post subject: Reply with quote

Quote:
Why is the list of values having embedded comas ? Smile


Hope, it is to avoid selecting other combination of the listed values. Smile

Thanks,
Jaya.
_________________
"Great spirits have always encountered violent opposition from mediocre minds."
-Albert Einstein
Back to top
View user's profile Send private message
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Mon Feb 27, 2006 1:00 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group