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
 

 

problem on perform statement

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

New User


Joined: 07 Jan 2006
Posts: 4

PostPosted: Sat Jan 07, 2006 3:44 pm    Post subject: problem on perform statement
Reply with quote

perform varying i from -2 by 1 until i>2
display 'A'
add 2 to i
end-perform.

how many times 'A' will be displayed.
i tried this program, but it is displaying 'A' only one time why it is showing 'A' only one time.
Back to top
View user's profile Send private message

manjinder

New User


Joined: 04 Dec 2005
Posts: 45
Location: pune

PostPosted: Sat Jan 07, 2006 4:07 pm    Post subject: hi dipti
Reply with quote

it wont show A once it will show A 2 times first for ->-2
second for -> 1
Back to top
View user's profile Send private message
rajesh_1183

Active User


Joined: 24 Nov 2005
Posts: 121
Location: Tadepalligudem

PostPosted: Mon Jan 09, 2006 11:22 am    Post subject:
Reply with quote

it will display A for 5 times...

*** looping variables(ie; i) will not be modified inside the loop...


correct me if i am wrong.....


Thanks,
Rajesh.
Back to top
View user's profile Send private message
gowtham_1982
Warnings : 1

Active User


Joined: 02 Dec 2005
Posts: 109

PostPosted: Mon Jan 09, 2006 12:03 pm    Post subject:
Reply with quote

rajesh_1183 wrote:
it will display A for 5 times...

*** looping variables(ie; i) will not be modified inside the loop...


correct me if i am wrong.....


Thanks,
Rajesh.



hai rajesh,

we can modify the subscript or index within a loop. it is possible.

and the solution to the query, the display will be 2 times.


corrections welcomed..

gowtham
Back to top
View user's profile Send private message
rajesh_1183

Active User


Joined: 24 Nov 2005
Posts: 121
Location: Tadepalligudem

PostPosted: Mon Jan 09, 2006 12:07 pm    Post subject:
Reply with quote

hi gowtham,

But dipti hasn't metioned that it is a subscript ot index variable.......

Thanks,
Rajesh
Back to top
View user's profile Send private message
gowtham_1982
Warnings : 1

Active User


Joined: 02 Dec 2005
Posts: 109

PostPosted: Mon Jan 09, 2006 1:57 pm    Post subject:
Reply with quote

rajesh_1183 wrote:
hi gowtham,

But dipti hasn't metioned that it is a subscript ot index variable.......

Thanks,
Rajesh



rajesh,

that does not matter. all i wanted to clear was that we can modify the variable depending on which the loope executes, with in the perform loop.


corrections welcomed.

gowtham
Back to top
View user's profile Send private message
rajesh_1183

Active User


Joined: 24 Nov 2005
Posts: 121
Location: Tadepalligudem

PostPosted: Mon Jan 09, 2006 2:05 pm    Post subject:
Reply with quote

Goutham,

In one of the faqs, i read like..we can't modify the looping-variable inside a loop..i am not sure abt this stmt whther it will work for only inline performs or all types of performs......

If it is a subscript or index..we can modify....

Thanks,
rajesh
Back to top
View user's profile Send private message
vinodmaanju

New User


Joined: 10 May 2005
Posts: 28
Location: Pune

PostPosted: Mon Jan 09, 2006 11:08 pm    Post subject: Re: problem on perform statement
Reply with quote

I CHKED IT ON MY SYSTEM WITHOUT USING SUBSCRIPT AND INDEX AND I GOT THE RESULT THAT I CAN MODIFY LOOPING VARIABLE IN LOOP. BUT IN CASE OF PERFORM N TIMES WE CAN NOT CHANGE THE EXECUTION OF LOOP.


I USED THIS :
PROCEDURE DIVISION.
PERFORM VARYING C FROM 1 BY 2 UNTIL C > 10
SUBTRACT 1 FROM C
DISPLAY ' C ' C
END-PERFORM.

AND MY LOOP WAS EXECUTED 10 TIMES.

EXAMPLE 2:
PROCEDURE DIVISION.
MOVE 5 TO C.
PERFORM C TIMES
SUBTRACT 1 FROM C
DISPLAY ' C : ' C
END-PERFORM.
STOP RUN.
WILL EXECUTE 5 TIMES AND VALUE OF C WILL GIVE 04,03,02,01,00

IN SATYAM ONE OF MY INTERVIEWERS WHO ASKED ME SAME QUESTION.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Fri Jan 20, 2006 7:59 pm    Post subject:
Reply with quote

Hi,
It has to be dispaly A twice
I think deepti has given picture clause for i like
01 i pic 9.
it should be
01 i pic s9.

regards,
chandan
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Jan 21, 2006 11:09 pm    Post subject:
Reply with quote

Rajesh said:
Quote:
But dipti hasn't metioned that it is a subscript ot index variable.......

If INDEX was used the pgm wouldn't compile.
Quote:
add 2 to i

wouldn't be accepted as a valid COBOL stmt in that context. You must use "set i up by 2".
Back to top
View user's profile Send private message
pa1chandak
Currently Banned

New User


Joined: 31 Jan 2006
Posts: 55

PostPosted: Thu Feb 02, 2006 3:00 pm    Post subject:
Reply with quote

IF YOU ARE SPECIGING MOVE 2 TO A THEN IT WILL PERFORM THE LOOP 5 TIMES

BUT IF SPECIFY ADD 2 TO A THEN IT SHOULD HAVE PERFORMED THE LOOP 2 TIMES ONLY

IF I AM WRONG SOMEWHERE PLEASE CORRECT ME

THANK YOU

DO SEND ME THE REPLY

PAWAN

09822546416

// THE ONE I LOVE , I SHALL NEVER BLAME //
Back to top
View user's profile Send private message
sudheer_kumar

New User


Joined: 27 Dec 2005
Posts: 16

PostPosted: Thu Feb 02, 2006 4:03 pm    Post subject:
Reply with quote

1)
01 I PIC [b]S9 VALUE 1[/b]
PERFORM VARYING I FROM -2 BY 1 UNTIL I > 2
DISPLAY 'A'
ADD 2 TO I
END-PERFORM.

For the above code , A will be displayed twice. Because for the first time
I=-2 , A is displayed and 2 will be added to I . The value of I becomes zero. For the second time I is increased to 1(I FROM -2 BY 1). The condition will be satisfied and the again A will be displayed.

2)
01 I PIC 9 VALUE 1 ---- > No sign field
PERFORM VARYING I FROM -2 BY 1 UNTIL I > 2
DISPLAY 'A'
ADD 2 TO I
END-PERFORM.

For the above code , A will be displayed only once. Because for the first time the value of I is 2 not -2 since I is not decalred as sign field.
Therefore only once will displayed.

I think dipti has declared I has PIC 9.


Correct me If I am wrong
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Fri Feb 03, 2006 3:26 pm    Post subject:
Reply with quote

Hi Dipti,

A will be displayed 2 times.
Since initially i is -2, A wil be displayed.
then added 2 to i, i now becomes 0, then thru perfrom again added 1 to i
now i is 1, one more A is displayed
add 2+ 1 to i, i becomes 4
end-perform is executed.
ie A is displayed 2 times.
if i is declared without s ( i pic s9), initial value of i will be 0.
only one a will be displayed.

Regards

Aji Cherian
Back to top
View user's profile Send private message
mijanurit
Currently Banned

New User


Joined: 26 Aug 2005
Posts: 33
Location: bangalore

PostPosted: Mon Feb 06, 2006 4:16 pm    Post subject: Re: problem on perform statement
Reply with quote

hi all!

it will show 'A' two times.
because
1.first time control comes to the loop when i's value is -2 and display A.
within loop i's value become 0.
then perform statement itself increament the value of i by 1.
now the value of i become 1.
2. second time control will come to loop and display A.
same thing will happen and i's value will be 4.
now perform condition will not be satisfied.
control will come out of the loop.

thanks and regards
mijanurit
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 Strings with double quotes having pro... raja Arumugam All Other Mainframe Topics 11 Thu Mar 30, 2017 10:34 am
No new posts Problem reading GTF trace output danik56 ABENDS & Debugging 7 Thu Mar 16, 2017 1:02 pm
No new posts ROUNDED Problem with COMPUTE statement shalem COBOL Programming 11 Thu Feb 09, 2017 8:16 pm
No new posts VALIDATE NULL VALUE IN DB2 CASE STATE... useit DB2 5 Thu Feb 09, 2017 4:34 pm
No new posts SYMNAMES problem jacobdng DFSORT/ICETOOL 7 Thu Dec 22, 2016 7:47 am


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