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
 

 

doubt in PERFORM VARYING...
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 205
Location: Bangalore

PostPosted: Mon Dec 24, 2007 6:29 pm    Post subject: doubt in PERFORM VARYING...
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: 632
Location: Wisconsin

PostPosted: Mon Dec 24, 2007 6:34 pm    Post subject:
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: 205
Location: Bangalore

PostPosted: Mon Dec 24, 2007 6:41 pm    Post subject: Reply to: doubt in PERFORM VARYING...
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: 1439
Location: Bangalore,India

PostPosted: Mon Dec 24, 2007 7:11 pm    Post subject:
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    Post subject: Reply to: doubt in PERFORM VARYING...
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: 356
Location: New York

PostPosted: Wed Dec 26, 2007 2:47 pm    Post subject:
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    Post subject: Reply to: doubt in PERFORM VARYING...
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: 356
Location: New York

PostPosted: Wed Dec 26, 2007 4:35 pm    Post subject:
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    Post subject:
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: 356
Location: New York

PostPosted: Wed Dec 26, 2007 5:15 pm    Post subject:
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: 205
Location: Bangalore

PostPosted: Wed Dec 26, 2007 6:55 pm    Post subject: Reply to: doubt in PERFORM VARYING...
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    Post subject:
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    Post subject:
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    Post subject: Reply to: doubt in PERFORM VARYING...
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: 632
Location: Wisconsin

PostPosted: Thu Dec 27, 2007 11:56 pm    Post subject:
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: 356
Location: New York

PostPosted: Fri Dec 28, 2007 10:20 am    Post subject:
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    Post subject:
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: 356
Location: New York

PostPosted: Fri Dec 28, 2007 12:22 pm    Post subject:
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    Post subject: Reply to: doubt in PERFORM VARYING...
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    Post subject:
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Doubt in MFS abdulrafi IMS DB/DC 2 Fri Oct 21, 2016 3:09 pm
No new posts How can we have the varying lenth of ... Gunapala CN DFSORT/ICETOOL 6 Fri Oct 14, 2016 7:31 pm
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 Doubt on GETMAIN, FREEMAIN behaviour Arunkumar Chandrasekaran CICS 3 Sun Aug 30, 2015 9:22 pm


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