View previous topic :: View next topic
|
Author |
Message |
SSR Warnings : 1 New User
Joined: 26 Feb 2006 Posts: 38
|
|
|
|
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 |
|
|
sandeep1dimri
New User
Joined: 30 Oct 2006 Posts: 76
|
|
|
|
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 |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
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 |
|
|
SSR Warnings : 1 New User
Joined: 26 Feb 2006 Posts: 38
|
|
|
|
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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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 |
|
|
|