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

Changing Perform N times


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Senior Member


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

PostPosted: Fri Jun 17, 2011 8:14 am
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

Moderator Emeritus


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

PostPosted: Fri Jun 17, 2011 8:38 am
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Fri Jun 17, 2011 2:52 pm
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

Superior Member


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

PostPosted: Fri Jun 17, 2011 4:52 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Jun 17, 2011 5:02 pm
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: 121
Location: Puerto Rico

PostPosted: Fri Jun 17, 2011 7:46 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Jun 17, 2011 8:09 pm
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: 121
Location: Puerto Rico

PostPosted: Sat Jun 18, 2011 12:56 am
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Jun 18, 2011 1:07 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts changing defaults in db2 admin - Unlo... DB2 0
No new posts Use of Perform Thru Exit COBOL Programming 6
No new posts Build a record in output file and rep... DFSORT/ICETOOL 11
No new posts Updating a 1 byte thats in occurs mul... DFSORT/ICETOOL 6
No new posts Tilde Characters Changing to COLONs i... CLIST & REXX 22
Search our Forums:

Back to Top