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

REGARDING IF STATEMENT


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vrakeshmbt

New User


Joined: 17 Aug 2005
Posts: 30

PostPosted: Mon Dec 12, 2005 3:13 pm
Reply with quote

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
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Mon Dec 12, 2005 3:26 pm
Reply with quote

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
View user's profile Send private message
vrakeshmbt

New User


Joined: 17 Aug 2005
Posts: 30

PostPosted: Mon Dec 12, 2005 3:41 pm
Reply with quote

Hi iknow,

I have done as u said but again same is the case.
Back to top
View user's profile Send private message
vrakeshmbt

New User


Joined: 17 Aug 2005
Posts: 30

PostPosted: Mon Dec 12, 2005 4:00 pm
Reply with quote

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
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Mon Dec 12, 2005 4:06 pm
Reply with quote

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
View user's profile Send private message
pankajayee

New User


Joined: 20 Sep 2005
Posts: 26

PostPosted: Mon Dec 12, 2005 4:20 pm
Reply with quote

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
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Mon Dec 12, 2005 4:31 pm
Reply with quote

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
View user's profile Send private message
vrakeshmbt

New User


Joined: 17 Aug 2005
Posts: 30

PostPosted: Mon Dec 12, 2005 5:04 pm
Reply with quote

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
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Mon Dec 12, 2005 6:13 pm
Reply with quote

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
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Mon Dec 12, 2005 7:04 pm
Reply with quote

Hi Priyesh,


Thanks for your valuable information.
Back to top
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Mon Dec 12, 2005 7:41 pm
Reply with quote

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
View user's profile Send private message
vrakeshmbt

New User


Joined: 17 Aug 2005
Posts: 30

PostPosted: Tue Dec 13, 2005 2:54 pm
Reply with quote

Thanks a lot iknow
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 -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
No new posts Relate COBOL statements to EGL statement All Other Mainframe Topics 0
No new posts process statement for SUPREC, CMPCOLM... TSO/ISPF 4
No new posts SYNCSORT/ICETOOL JOINKEYS SORT Statem... DFSORT/ICETOOL 13
No new posts DFDSS COPY using Filter REFDT statement JCL & VSAM 2
Search our Forums:

Back to Top