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

How does Perform With Test After work


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
SSR
Warnings : 1

New User


Joined: 26 Feb 2006
Posts: 38

PostPosted: Wed Dec 27, 2006 6:32 pm
Reply with quote

Hi,

Could anyone please explain me what does the below code does.

PERFORM WITH TEST AFTER
UNTIL SQLCODE NOT = -911
EXEC SQL
Query.
END-EXEC

How does 'PERFORM WITH TEST AFTER' work?

Regards
SSR
Back to top
View user's profile Send private message
sandeep1dimri

New User


Joined: 30 Oct 2006
Posts: 76

PostPosted: Wed Dec 27, 2006 7:42 pm
Reply with quote

Perform the statement first
EXEC SQL
Query.
END-EXEC

Then check the condition
SQLCODE NOT = -911
In any case the statements get executed once.

Sandeep
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Dec 27, 2006 8:36 pm
Reply with quote

Hi SSR,

To Add to ?Sandeep?s? post.

The normal (default) mode for PERFORMs is ?WITH TEST BEFORE? and works like this:

Code:

PERFORM
  Test conditions, exit Perform loop if true
    :
    Perform statements   
    :
  Increment variables
  Go to top of Perform Loop


This is why, if you want to perform the loop 10 times, you would code
?VARYING SUB FROM 1 BY 1 UNTIL SUB > 10?
because the 10th time through the perform loop ?SUB? has a value of 10 when the condition is tested at the top of the Perform loop and you would exit after performing the loop only 9 times if you coded SUB = 10

The optional mode for PERFORMs is ?WITH TEST AFTER? and works like this:

Code:

PERFORM
    :
    Perform statements
    :
  Test condition, exit Perform loop if true
  Increment variables
  Go to top of perform Loop


In this case, if you want to perform the loop 10 times, you would code
?VARYING SUB FROM 1 BY 1 UNTIL SUB = 10?
because the test for conditions is done at the bottom of the perform loop, just before the variables are incremented and you have already executed the PERFORM loop where SUB = 10.

In the example you gave at the top, if SQLCODE = 000 at the start of the PERFORM loop, and you used the default (?WITH TEST BEFORE?), you could never execute your SQL, the condition would be true the first time through. With the optional ?WITH TEST AFTER? the test is done at the end of the PERFORM loop, and as ?Sandeep? stated your SQL is executed at least one time
Back to top
View user's profile Send private message
SSR
Warnings : 1

New User


Joined: 26 Feb 2006
Posts: 38

PostPosted: Fri Dec 29, 2006 2:08 pm
Reply with quote

Hi,

Thank you,

Is PERFORM WITH TEST BEFORE EQUIVALENT TO PERFORM UNTIL OPTION, OR THE PERFORM WITH TEST BEFORE/AFTER NEEDS TO BE USED ALONG WITH UNTIL OPTION.

Regards
SSR
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Dec 29, 2006 3:04 pm
Reply with quote

Hi SSR,

Quote:
Is PERFORM WITH TEST BEFORE EQUIVALENT TO PERFORM UNTIL OPTION, OR THE PERFORM WITH TEST BEFORE/AFTER NEEDS TO BE USED ALONG WITH UNTIL OPTION.


You need to specify the UNTIL condition also along with the PERFORM WITH TEST AFTER phrase.PERFORM WITH TEST BEFORE UNTIL 'condn' is equivalent to PERFORM UNTIL 'condn'.You should not omit the UNTIL phrase in either case.

Thanks
Arun
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 isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
No new posts Use of Perform Thru Exit COBOL Programming 6
No new posts Zunit Test case editor error Testing & Performance 4
No new posts Copying GDG version(all/few) from pro... CLIST & REXX 13
No new posts REXX Test under Mask??? CLIST & REXX 3
Search our Forums:

Back to Top