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

doubt in PERFORM VARYING...


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

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Mon Dec 24, 2007 6:29 pm
Reply with quote

I have a doubt in PERFORM VARYING...

Does changing the counter variable inside the execution range affect the no of the iterations?

Code:

PERFORM 0100-PARA VARYING K FROM 1 BY 1 UNTIL K > 10.

.
.
.
0100-PARA.
    ADD 2 TO K.


Does changing K in the para range affect the no of iterations?

I am currently not having access to mainframe. Otherwise I would have tested it myself.

Thanks,
Ajay
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 631
Location: Wisconsin

PostPosted: Mon Dec 24, 2007 6:34 pm
Reply with quote

Don't mess with your look varbiables outside of the control statement if you can help it. Otherwise use a continue/no continue flag and just set to no when you want to stop. But adding different values than the BY 1 statement makes for crappy tracing when someone else tries to figure out what is going on.
Back to top
View user's profile Send private message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Mon Dec 24, 2007 6:41 pm
Reply with quote

I know it is not a good way of programming. But I had taken one test and these type of questions were there.

Thanks,
Ajay
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Mon Dec 24, 2007 7:11 pm
Reply with quote

Ajay,

Quote:
But I had taken one test and these type of questions were there.

Good to you had agreed the fact. Many of the programmers overlook the add statement and chooses option which has 10 value. Just to confuse you, they will provide such questions.

As suggested, dont mess with the control variables.
Back to top
View user's profile Send private message
abhishekmdwivedi

New User


Joined: 22 Aug 2006
Posts: 95
Location: india

PostPosted: Wed Dec 26, 2007 9:46 am
Reply with quote

Ajay,

The variables used under loops for iteration purpose when manipulated under the performing para or statements are not reflected in the no. of iterations performed.
As the loop doesn't allow the control of the iteration variable to be used under the looped statements or para.

So,
Code:

PERFORM 0100-PARA VARYING K FROM 1 BY 1 UNTIL K > 10.

.
.
.
0100-PARA.
    ADD 2 TO K.


will iterate 9 times irrespective of the value assigned to variable K.
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Wed Dec 26, 2007 2:47 pm
Reply with quote

Hi Abhishe,

9 is wrong if K wil not be affected by the the ADD statment.
Back to top
View user's profile Send private message
abhishekmdwivedi

New User


Joined: 22 Aug 2006
Posts: 95
Location: india

PostPosted: Wed Dec 26, 2007 3:01 pm
Reply with quote

Well KSK,

if you check.

Quote:
variables used under loops for iteration purpose when manipulated under the performing para or statements are not reflected in the no. of iterations performed.
As the loop doesn't allow the control of the iteration variable to be used under the looped statements or para.

VARYING K FROM 1 BY 1 UNTIL K > 10


That's what I have written.
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Wed Dec 26, 2007 4:35 pm
Reply with quote

Hi Abhishek,

You are right. K starts from 1 and increments by 1.

When K value becomes 10, conditon becomes false, so it would be executed. when K becomes 11, i.e. 10 times, condition becomes true and control comes out of the perform.

So, it perfroms 10 times.

That's what I have thought and written.
Back to top
View user's profile Send private message
abhishekmdwivedi

New User


Joined: 22 Aug 2006
Posts: 95
Location: india

PostPosted: Wed Dec 26, 2007 4:44 pm
Reply with quote

KSK,

You are right man for
Quote:
So, it perfroms 10 times.


Probably would have misread it.
My Actual focus was on the part
Quote:

variables used under loops for iteration purpose when manipulated under the performing para or statements are not reflected in the no. of iterations performed.
As the loop doesn't allow the control of the iteration variable to be used under the looped statements or para.

Thanks man.
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Wed Dec 26, 2007 5:15 pm
Reply with quote

Abhishek,

Quote:

Probably would have misread it.
My Actual focus was on the part


No problem. Just I wanted to write the correct number of times.

KSK
Back to top
View user's profile Send private message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Wed Dec 26, 2007 6:55 pm
Reply with quote

Quote:

variables used under loops for iteration purpose when manipulated under the performing para or statements are not reflected in the no. of iterations performed.
As the loop doesn't allow the control of the iteration variable to be used under the looped statements or para.



Code:
0100-PARA.
    ADD 2 TO K



Does it mean ADD 2 TO K does not change the control variable K in the 0100-PARA, or the compiler neglects this statement ?


Thanks,
Ajay

[/code]
Back to top
View user's profile Send private message
rahul.banik

New User


Joined: 23 Jan 2007
Posts: 16
Location: Mysore

PostPosted: Thu Dec 27, 2007 11:07 am
Reply with quote

Hi Ajay,

Better way to check this is just display the 'k' within the 0100-PARA and
after the Perform stament.I think ADD 2 TO K will affect the no. of iterations.
Back to top
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Thu Dec 27, 2007 9:59 pm
Reply with quote

The best way to know the answer is to test it.

Code:
********************************* TOP OF DATA **********************************
AFTER ADD K = 003                                                               
AFTER ADD K = 006                                                               
AFTER ADD K = 009                                                               
AFTER ADD K = 012                                                               
******************************** BOTTOM OF DATA ********************************


Just as I thought, the add does modify the counter and the perform is done 4 times.
Back to top
View user's profile Send private message
akkireddy

New User


Joined: 13 Jul 2007
Posts: 1
Location: hyd

PostPosted: Thu Dec 27, 2007 10:52 pm
Reply with quote

no change in that itterations...
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 631
Location: Wisconsin

PostPosted: Thu Dec 27, 2007 11:56 pm
Reply with quote

This is flat out wrong.... did you even test this?
[quote]
The variables used under loops for iteration purpose when manipulated under the performing para or statements are not reflected in the no. of iterations performed.
As the loop doesn't allow the control of the iteration variable to be used under the looped statements or para.
[/code]

Douglas is correct as he shows with his test restuls. It does change the number of iterations. Cobol by default treats all working storage fields as global. Since K is a global working storage field, any modification of it will affect another part of the program.

Instead of 10 iterations, you will see only 4 iterations.
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Fri Dec 28, 2007 10:20 am
Reply with quote

Hi,

Yes, douglas is correct. Perform is done only 4 times. Modifying the counter afftected the number of iterations.

Code:

IN 0100-PARA AFTER ADD K=03 
IN 0100-PARA AFTER ADD K=06 
IN 0100-PARA AFTER ADD K=09 
IN 0100-PARA AFTER ADD K=12 
Back to top
View user's profile Send private message
JAGAN_SRIRAM

New User


Joined: 21 Jul 2007
Posts: 4
Location: INDIA

PostPosted: Fri Dec 28, 2007 12:12 pm
Reply with quote

no the value of the variable will not be changed until the perform is completed. explanation for this question is available in ibm interview questions
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Fri Dec 28, 2007 12:22 pm
Reply with quote

Hi,

Following is the code:

Code:

PROCEDURE DIVISION.                                     
    PERFORM 0100-PARA VARYING K FROM 1 BY 1 UNTIL K > 10.
    DISPLAY 'AFETR PERFORM K1=' K1.                     
    STOP RUN.                                           
                                                         
0100-PARA.                                               
    ADD 1 TO K1.                                         
    ADD 2 TO K.                                         
    DISPLAY 'IN 0100-PARA AFTER ADD K=' K.               


Following is the result:
Code:

IN 0100-PARA AFTER ADD K=03
IN 0100-PARA AFTER ADD K=06
IN 0100-PARA AFTER ADD K=09
IN 0100-PARA AFTER ADD K=12
AFETR PERFORM K1=04       


KSK
Back to top
View user's profile Send private message
ahalyah

New User


Joined: 13 Dec 2007
Posts: 25
Location: india

PostPosted: Fri Dec 28, 2007 2:56 pm
Reply with quote

Hi,
i also agree with Douglas
Back to top
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Fri Dec 28, 2007 9:58 pm
Reply with quote

JAGAN_SRIRAM, Do you believe ANY Web sight more than what the computer acutlly does? Try it yourself! What does the computer actually do? I already took the few minute to test it and posted my results.

If you provide a link we can check if you are misunderstanding the interview question or answer or if the question or answer is actualy wrong.

Of course, if that is the answer the interviewer is looking for, you can decide for yourself if you want to give the interviewer the correct answer or the answer they are looking for. It is not always a good idea to try to educate an interviewer during the interview, even if they are wrong.
Back to top
View user's profile Send private message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Sat Dec 29, 2007 3:52 pm
Reply with quote

Thanks everybody for such a prompt discussion.

As mentioned in my original message, i don't have access... so i could not test it.

I conclude from the test results that :

"Changing the iteration variable within the range of PERFORM does affect the final no of iterations. Also the iteration variable gets modified."

Thanks.
Ajay
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 Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Use of Perform Thru Exit COBOL Programming 6
No new posts Synctool-dynamic split job for varyin... JCL & VSAM 7
No new posts Doubt about pl/1 (job offer) General Talk & Fun Stuff 5
No new posts doubt when executing a file when logg... TSO/ISPF 2
Search our Forums:

Back to Top