View previous topic :: View next topic
|
Author |
Message |
vrakeshmbt
New User
Joined: 17 Aug 2005 Posts: 30
|
|
|
|
Code: |
//JOBNAME JOB NOTIFY=&SYSUID
//IFNAME IF RC NE 0 THEN
//STEP1 EXEC PGM=CBL1,COND=(0,GT)
//STEPLIB DD DSN=BPMAIN.PUNE.APPL.LOADLIB,DISP=SHR
// ELSE
//STEP2 EXEC PGM=CBL1
//STEPLIB DD DSN=BPMAIN.PUNE.APPL.LOADLIB,DISP=SHR
// ENDIF |
when i have ececuted this JCL, both the steps have been executed.
What would be the reason. Can anyone please help me ?? |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi vrakeshmbt,
Try replacing RC >0 instead of specifying RC NE 0.
NOTE
I think as per the syntax IF....THEN does not recognize NE/EQ etc.
Hope this helps. |
|
Back to top |
|
|
vrakeshmbt
New User
Joined: 17 Aug 2005 Posts: 30
|
|
|
|
Hi iknow,
I have done as u said but again same is the case. |
|
Back to top |
|
|
vrakeshmbt
New User
Joined: 17 Aug 2005 Posts: 30
|
|
|
|
The only reason i have found is that there should be atleast a EXEC statement before an IF statement or else the IF is not considered
Please correct me if I am wrong....
Any way thanks iknow. |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
In that case reverse the order of the steps as well as IF cond.
Make it like...
Code: |
//IFNAME IF (RC = 0) THEN
Second Step
//ELSE
First Step
//ENDIF |
Regards,
Priyesh. |
|
Back to top |
|
|
pankajayee
New User
Joined: 20 Sep 2005 Posts: 26
|
|
|
|
Hi vrakeshmbt,
You are absolutely correct. At least you should have one step for using if statement. Otherwise the condition is not applicable. In the above code the first is going to execute anyway and the second step is again not conditional (No if statement prior to it). so that both the steps are anyway executed.
Please let me know if u can find any other reason.
Thanx,
Pankaj. |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
Yeah That is ...
from the manual....
Quote: |
An IF statement specified before the first EXEC statement in a job is not evaluated before the first step executes. If the IF statement applies to later steps in the job, the statement will be evaluated when the system decides whether to process the later steps. |
Regards,
Priyesh. |
|
Back to top |
|
|
vrakeshmbt
New User
Joined: 17 Aug 2005 Posts: 30
|
|
|
|
PRIYESH,
Its working fine as you said for EQ condition, whereas if i specify GT or LT in the place of EQ i has to process only step2 but it is processing both the steps.
If u find the reason please let me know
Thanks a lot for ur reply. |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
ikumar quoted.
Quote: |
NOTE
I think as per the syntax IF....THEN does not recognize NE/EQ etc. |
This is not correct. It does recognize.
Quote: |
Its working fine as you said for EQ condition, whereas if i specify GT or LT in the place of EQ i has to process only step2 but it is processing both the steps. |
Yeah, I too find the same results. As quoted from manual above, if the IF...stmt is given before first EXEC stmt, it isn't evaluated before the first step executes.
Note : RC is set to zero in the starting of the job.
Not sure, may be thats why it is working in the case of ZERO.
Regards,
Priyesh. |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi Priyesh,
Thanks for your valuable information. |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi vrakeshmbt,
As a follow up to the previous post let me just add some more points on the above topic.
IF/THEN/ELSE/ENDIF STATEMENT
The IF/THEN/ELSE/ENDIF statement construct is used to conditionally execute one or more job steps within a job. The IF construct functions as follows: the IF statement contains a relational expression which is evaluated; if the expression is TRUE, the JCL statements associated with the THEN clause are executed; if the expression evaluates as FALSE, the statements associated with the ELSE statement are executed. If no ELSE statement is specified when the expression evaluates as FALSE, the next JCL statement after the ENDIF that terminates the IF construct is executed.
If both an IF/THEN/ELSE/ENDIF construct and the EXEC statement COND parameter are used to conditionally execute a job step, both must evaluate with a result that causes the job step to execute before it will actually execute. IBM recommends that you use the IF/THEN/ELSE/ENDIF construct instead of the COND parameter on the EXEC statement to conditionally execute job steps.
The IF/THEN/ELSE/ENDIF statement can be nested to a depth of up to 15 levels by including an IF construct within the JCL statements associated with a THEN clause or an ELSE statement.
The IF/THEN/ELSE/ENDIF statement can appear anywhere in a job after the JOB statement. Do not specify the JOB, JCLLIB, JOBCAT or STEPCAT statements following JCL statements within the THEN or ELSE scope of an IF/THEN/ELSE/ENDIF statement:
Notes:
This construct replaces the confusing conditional step processing provided by the COND= keyword. Perhaps the best thing is that the logic is intuititive:
Code: |
// COND=(#,oper) TRUE step does not run
// IF (RC oper #) THEN… TRUE step runs!
|
COND xx-Mnemonic IF xx-Mnemonic or Character
EQ Equal EQ Equal =
GT Greater Than GT Greater Than >
GE Greater or Equal GE Greater or Equal >=
LT Less Than LT Less Than <
LE Less or Equal LE Less or Equal <=
NE Not Equal NE Not Equal ^=
AND logical AND &
NOT logical NOT ^
OR logical OR |
Mnemonic – code a blank before and after
Character – blanks not needed
Code one way for consistency – the mnemonic is easier to read
Avoid using NOT, as it is confusing
You cannot select individual DD statements, only entire job steps
ELSE provides an explicit means to specify an alternative step (more concise and readable than a second IF/ENDIF with reverse logic).
IF/THEN/ELSE/ENDIF statements can have optional labels beginning in position three. If used, they follow the rules for a member name. They are only for documentation. The manual specifies that they “should” be unique in the job, but tests show this is not enforced at this time. These statements can be continued on a following line that begins with // and a space in columns 1-3; do not break a word or symbol.
The following example shows the use of the alphabetic characters rather than special characters for comparison operators.
Quote: |
//IFBAD IF (ABEND | STEP1.RC > 8) THEN
or
//IFBAD IF (ABEND OR STEP1.RC GT 8) THEN
.
.
//IFTEST2 IF (RC > 4 & RC < 8) THEN
or
//IFTEST2 IF (RC GT 4 AND RC LT 8) THEN
|
IF ABEND is equivalent to COND=ONLY, and IF ABEND OR ^ABEND to COND=EVEN.
This example shows nested IF/THEN/ELSE/ENDIF statement constructs with ELSE clauses. The nested statements are indented so that they are easier to read.
Code: |
//JOBD JOB ...
//PROC1 PROC
//PSTEPONE EXEC PGM=...
//PSTEP11 EXEC PGM=...
//PSTEP12 EXEC PGM=...
// PEND
//PROC2 PROC
//PSTEPTWO EXEC PGM=...
// PEND
//EXP1 EXEC PROC=PROC1
//EXP2 EXEC PROC=PROC2
//IFTEST3 IF (RC > 12) THEN
//STEP1BAD IF (EXP1.PSTEP11.RC > 12 OR EXP1.PSTEP12.RC > 12) THEN
//STEP1ERR EXEC PGM=ERRTN,PARM=(EXP1)
// ELSE
//STEP2ERR EXEC PGM=ERRTN,PARM=(EXP2)
//END1BAD ENDIF
// ELSE
//NOPROB EXEC PROC=RUNOK
//ENDTEST3 ENDIF
//NEXTSTEP EXEC ...
|
Hope this helps. |
|
Back to top |
|
|
vrakeshmbt
New User
Joined: 17 Aug 2005 Posts: 30
|
|
|
|
Thanks a lot iknow |
|
Back to top |
|
|
|