View previous topic :: View next topic
|
Author |
Message |
Deepakboopathy
New User
Joined: 15 Apr 2009 Posts: 2 Location: Chennai
|
|
|
|
Hi,
I am new to this community. Please let me know if you do not understand this problem.
Assume there are 1000 values, out of which some x numbers is stored in the table. Based on the value present in the table i need to perform a particular paragraph.
right now we are using the following solution.
If table[1] = a
perform a.
if table[2] = b
perform b.
.
.
.
.
if table[1000] = xxx
perform xxx.
i feel this implementation is time consuming, because if there are only 2 numbers stored in the table, then we need check all the 1000 values.
If we can use dynamic paragraph name in perform then it can be solved easily, but i think it is impossible. Please let me know if there are any efficient way to handle this problem. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
If table[1] = a
perform a.
if table[2] = b
perform b. |
what if table(1) = b ?
your example does not provide any insight into your problem,
other than (as you have described it) it is poor design.
provide a little more explanation of your table:- what values can the first item contain
- why or how is the table loaded
- you speak of numbers yet, your code indicates alpha
be a little less theoretical and a little more exact, you will receive more help.
and no, there is no thing as 'dynamic' paragraph names in cobol. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
I thought ALTER had been safely nailed into its coffin, a stake through its heart, lo these many moons ago. And now somebody is trying to resurrect the corpse! |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
go to depending on.... |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Code: |
Perform varying I from 1 by 1 until I > 1000
If table[I] = a
perform a
else
if table[I] = b
perform b
else
display error
end-if
end-if
end-perform |
|
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
CICS GUY's code you will either have to get a match with I = 1 or you will display an error.
Code: |
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 1000
EVALUATE TABLE[I]
WHEN 'A' PERFORM PARA-A
MOVE 1001 TO I
WHEN 'B' PERFORM PARA-B
MOVE 1001 TO I
WHEN 'C' PERFORM THIS-IS-TERRIBLE-CODE
MOVE 1001 TO I
END-EVALUATE
IF I = 1000
DISPLAY ERROR
END-IF
END-PERFORM.
|
|
|
Back to top |
|
|
Deepakboopathy
New User
Joined: 15 Apr 2009 Posts: 2 Location: Chennai
|
|
|
|
Let me state the problem once again..
There are some x number of possible codes (code-1 to code-x), out of which only some of the codes will be used at a time, which is stored in a table. Based on the codes, the corresponding paragraphs are performed. Currently the implementation is as follows.
If table(var1) = code-1
perform para-1.
if table(var1) = code-2
perform para-2.
.
.
.
.
.
if table(var1) = code-x
perform para-x.
where var1 varies from 1 to the number of codes present at a time.
I think evaluate will perform better than if's here. Please give your suggestions. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Craq Giegerich wrote: |
CICS GUY's code you will either have to get a match with I = 1 or you will display an error. |
Just trying to get some feedback about what the OP wants.
Judging from the last post, I guess it didn't really work.... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Quote: |
Judging from the last post, I guess it didn't really work.... |
And this is surprising because. . . ?
Quote: |
I think evaluate will perform better than if's here. |
Why do you believe this? It might perform better than the "if's" as coded. . .
To reduce the number of compares and possibly "perform better", placing the codes most likely to "hit" at the front of the literals to be compared would help. |
|
Back to top |
|
|
leo_sangha
New User
Joined: 11 Aug 2005 Posts: 85 Location: England
|
|
|
|
Deepakboopathy wrote: |
I think evaluate will perform better than if's here. Please give your suggestions. |
Definitely in these situations evaluate is the way to go to avoid executing multiple IF statements before you hit the concerned condition. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
Definitely in these situations evaluate is the way to go to avoid executing multiple IF statements before you hit the concerned condition.
|
what do you think an evaluate is? |
|
Back to top |
|
|
mtaylor
Active User
Joined: 20 Feb 2009 Posts: 108 Location: Kansas City
|
|
|
|
dbzTHEdinosauer wrote: |
Quote: |
Definitely in these situations evaluate is the way to go to avoid executing multiple IF statements before you hit the concerned condition.
|
what do you think an evaluate is? |
An optimizing compiler will create a 'jump table' from an evaluate (switch in other languages) that's basically a bunch of static gotos as opposed to calculated branches that generated when if/evaluates are directly converted to machine code. Seems like most Cobol shops don't have the optimizer turned on though so for all practical purposes, a sequence of if's/evaluate are the same thing.
The other option is to create a 'decision tree' in the code that's basically like a binary search tree in code:
Code: |
if code >= 1 and code < 100
if code >= 1 and < 10
evaluate true
when code = 1
...
when code = 2
...
when code = 3
...
etc...
end-evaluate
end-if
if code >= 10 and < 20
evaluate true
when code = 10
...
when code = 11
...
when code = 12
...
etc...
end-evaluate
end-if
... etc ...
end-if. |
You can get a lot of speed up this way. |
|
Back to top |
|
|
|