Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Is "PERFORM <<dynamic para-name" possible??

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Is "PERFORM <<dynamic para-name" possible??
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    Post subject:
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: 7931
Location: Bellevue, IA

PostPosted: Wed Apr 15, 2009 10:41 pm    Post subject:
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    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Wed Apr 15, 2009 11:13 pm    Post subject: Re: Is "PERFORM <<dynamic para-name" possibl
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    Post subject:
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    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Thu Apr 16, 2009 1:21 am    Post subject:
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

Site Director


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

PostPosted: Thu Apr 16, 2009 2:24 am    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts REXX DB2: Dynamic allocation of DB2.D... BHAS CLIST & REXX 3 Mon Dec 19, 2016 8:26 pm
No new posts Amount field is getting corrupted whe... thesumitk SYNCSORT 5 Tue Oct 18, 2016 8:20 pm
No new posts hot to get details when "EXEC CI... Andi1982 CICS 11 Tue Sep 20, 2016 5:01 pm
No new posts Easytrieve - Report writing - Only 1 ... Abhi Nature CA Products 2 Wed Sep 14, 2016 11:40 am
No new posts Multi row fetch - "for read only... Nileshkul DB2 3 Sun Aug 14, 2016 12:52 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us