IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Is "PERFORM "para-name" possible?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Deepakboopathy

New User


Joined: 15 Apr 2009
Posts: 2
Location: Chennai

PostPosted: Wed Apr 15, 2009 9:54 pm
Reply with quote

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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 15, 2009 10:14 pm
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Apr 15, 2009 10:41 pm
Reply with quote

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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 15, 2009 10:46 pm
Reply with quote

go to depending on....
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Wed Apr 15, 2009 11:13 pm
Reply with quote

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

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Apr 15, 2009 11:55 pm
Reply with quote

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

New User


Joined: 15 Apr 2009
Posts: 2
Location: Chennai

PostPosted: Thu Apr 16, 2009 12:04 am
Reply with quote

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

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Apr 16, 2009 1:21 am
Reply with quote

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.... icon_rolleyes.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Apr 16, 2009 2:24 am
Reply with quote

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

New User


Joined: 11 Aug 2005
Posts: 85
Location: England

PostPosted: Thu Apr 16, 2009 6:54 pm
Reply with quote

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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Apr 16, 2009 7:03 pm
Reply with quote

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

Active User


Joined: 20 Feb 2009
Posts: 108
Location: Kansas City

PostPosted: Thu Apr 16, 2009 8:15 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts PuTTY - "User is not a surrogate... IBM Tools 5
No new posts Use of Perform Thru Exit COBOL Programming 6
This topic is locked: you cannot edit posts or make replies. Programa para Realiza Operaciones sob... JCL & VSAM 3
No new posts Newbie Stuck on "Duplicate Datas... TSO/ISPF 5
No new posts data moved using MVI on para-name. PL/I & Assembler 4
Search our Forums:

Back to Top