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
 

 

Changing Perform N times

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
mambopras

New User


Joined: 11 Nov 2008
Posts: 52
Location: Hyderabad

PostPosted: Fri Jun 17, 2011 7:43 am    Post subject: Changing Perform N times
Reply with quote

Hi,
Recently I have tried a PERFORM code in a program.

WORKING STORAGE SECTION.
01 WS-TIME PIC 9 VALUE 7.

PROCEDURE DIVISION.
PERFORM WS-TIME TIMES
Statement 1...........
Statement 2...........
MOVE 4 TO WS-TIME
END-PERFORM.

The loop got executed 7 times even after changing the value of WS-TIME to 4. So, does this happen by the virtue of the PERFORM type we are using - Any other reason ?
Is there a way that this PERFORM type can be made to execute just 4 times by using any other option (not with a different PERFORM type though) ?
Back to top
View user's profile Send private message

Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Fri Jun 17, 2011 8:14 am    Post subject:
Reply with quote

Just in case the COBOL manual does not address this issue, you can always generate the compiled code (procedure map I think) and see what is happening.
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: Fri Jun 17, 2011 8:38 am    Post subject:
Reply with quote

Hello,

At the top of the page is a link to "IBM Manuals". The first group of manuals is for COBOL.

Suggest you read all about the variations of the PERFORM. If you find something that is not clear in the documentation, post what you found and your doubt. Someone will be able to clarify.
Back to top
View user's profile Send private message
Dsingh29

Active User


Joined: 16 Dec 2008
Posts: 132
Location: IBM

PostPosted: Fri Jun 17, 2011 10:43 am    Post subject: Reply to: Perform N times
Reply with quote

No, this is not possible in this variant of PERFORM.

Looks to me, a simple interview question. icon_razz.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Fri Jun 17, 2011 2:52 pm    Post subject:
Reply with quote

Quote:
The loop got executed 7 times even after changing the value of WS-TIME to 4. So, does this happen by the virtue of the PERFORM type we are using - Any other reason ?
You need to learn to read manuals -- link at the top of the page. The COBOL Language Reference manual clearly and explicitly describes your code in section 6.2.27.3 and if you had bothered to read it, you would not even have needed to post anything.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Fri Jun 17, 2011 4:52 pm    Post subject:
Reply with quote

Well, the format of the PERFORM, you've used, will execute a block of code WS-TIME number of times before returning control to the statement following the PERFORM.

Try this,
Code:
WORKING-STORAGE SECTION.
      01 WS-TIME PIC 9 VALUE 7.
      01 WS-NO   PIC 9 VALUE 0.
.
.
PROCEDURE DIVISION.
.
.

PERFORM WS-TIME TIMES     
        DISPLAY'>'WS-NO'<'
        MOVE 4 TO WS-TIME 
        ADD +1 TO WS-NO   
END-PERFORM               
you'll find that, WS-NO has the values 0, 1, 2, 3, 4, 5, 6 irrespective of that you move 4 to WS-TIME in between. COBOL is not looking at that, per the definition of in-line PERFORM, the bold text above.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7233

PostPosted: Fri Jun 17, 2011 5:02 pm    Post subject: Reply to: Perform N times
Reply with quote

If you peform N times, Cobol will establish its' own little piece of storage to manage the counting to N. It does this before any of the statements within the PERFORM itself are actioned. Since you don't have any access to Cobol's little counter, you will be unable to affect the number of TIMES the thing is performed after it has already started.

And why would you want to? If you find yourself wanting to do that, it just means you've chosen the wrong sort of PERFORM control.

As Ph... Phil said, get the compiler to list the generated "pseudo assembler" code and it will all be there.

Every time, it will do it however many times you asked it to be done with the PERFORM and when that is all done, will continue with the next statement after the PERFORM statement as a whole.
Back to top
View user's profile Send private message
Jose Mateo

Active User


Joined: 29 Oct 2010
Posts: 110
Location: Puerto Rico

PostPosted: Fri Jun 17, 2011 7:46 pm    Post subject:
Reply with quote

Good day to all!

Like everyone has mention that this is a in-lin perform and it will perform the block code the number of time from the initial value taken, is like if you had specified PERFORM 7 TIMES. Now if you want this block of code to be executed 4 time then you would use PERFORM UNTIL WS-TIME LESS THAN 0 and in your block code you would replace the 'MOVE 4 TO WS-TIME' with 'SUBTRACT 2 FROM WS-TIME'.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7233

PostPosted: Fri Jun 17, 2011 8:09 pm    Post subject:
Reply with quote

Jose Mateo wrote:
Good day to all!

Like everyone has mention that this is a in-lin perform and it will perform the block code the number of time from the initial value taken, is like if you had specified PERFORM 7 TIMES. Now if you want this block of code to be executed 4 time then you would use PERFORM UNTIL WS-TIME LESS THAN 0 and in your block code you would replace the 'MOVE 4 TO WS-TIME' with 'SUBTRACT 2 FROM WS-TIME'.


Whether the PERFORM is inline or not is irrelevant. It works exactly the same with PERFORM para/section. First time I've mentioned anything about that. Can't remember much mention from others either.

Code:
PERFORM write-seperator-line number-of-seperators TIMES.


The PERFORM... TIMES is designed to work when you know outside the body of the perform exactly the number of iterations you want.

Why you'd code your example, Jose, I don't know. There is nothing magic about 7 that you have to use it. If you want it four times, you can perform it four times.

If you don't know how many times you want to perform it, and you want it from zero to "a condition" times, then you use one of the other PERFORM formats as appropriate, with appropriate additional control clauses.
Back to top
View user's profile Send private message
Jose Mateo

Active User


Joined: 29 Oct 2010
Posts: 110
Location: Puerto Rico

PostPosted: Sat Jun 18, 2011 12:56 am    Post subject:
Reply with quote

Bill,
You are right and I won't disagree with you. Mambopras asked if there's another perform given the variable ws-time = 7, which would execute his block of code 4 times and I suggested PERFORM UNTIL.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7233

PostPosted: Sat Jun 18, 2011 1:07 am    Post subject: Reply to: Perform N times
Reply with quote

OK, Jose.

It's the weekend already, so enjoy it :-)
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 How to calculate an specific transact... lind sh CICS 2 Tue Sep 13, 2016 9:20 pm
No new posts changing z/os unicode conversion service meykh2014 All Other Mainframe Topics 0 Tue Jul 12, 2016 10:49 am
No new posts How to perform Digest Access Authenti... vasanthz All Other Mainframe Topics 0 Tue Mar 15, 2016 4:47 pm
No new posts OMEGAMON to see In-DB2 times and Wait... Archana89 IBM Tools 4 Fri Mar 04, 2016 11:28 am
This topic is locked: you cannot edit posts or make replies. Executing JCL specific steps at speci... Shruti Takkar JCL & VSAM 6 Mon Feb 22, 2016 12:39 pm


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