View previous topic :: View next topic |
Author |
Message |
jim haire Beginner
Joined: 30 Dec 2002 Posts: 140 Topics: 40
|
Posted: Thu Jun 14, 2012 10:48 am Post subject: Nested IF logic |
|
|
I am reviewing some JCL which was coded by another group. I have never written multiple IF/END IF conditions like this and wonder if it would work?
Code: |
//STEP010 (Checks to see if file 1 is empty)
//STEP020 (IF STEP010.RC EQ 0) THEN
//STEP030 (Checks to see if file 2 is empty)
//STEP040 (Checks to see if file 3 is empty)
//STEP050 (IF STEP030.RC EQ 0 or STEP040.RC EQ 0) THEN
//STEP060-STEP130 other JCL steps
//STEP140 ENDIF
//STEP150 ENDIF
|
The logic is that if file 1 is empty, go to the associated ENDIF and don't do any more processing. If file 1 contains at least 1 record, check to see if file2 or file 3 contains at least one record. if one of those files contains at least one record, process through the rest of the steps. Otherwise, go the end without processing any more steps.
Is JCL able to tie an ENDIF to its associated IF like COBOL does (First IF goes with the last ENDIF, 2nd IF goes with the 2nd to the last ENDIF)?
[/code] |
|
Back to top |
|
|
papadi Supermod
Joined: 20 Oct 2009 Posts: 594 Topics: 1
|
Posted: Thu Jun 14, 2012 11:51 am Post subject: |
|
|
Suggest you look in the JCL Reference manual which among lots of other good stuff says:
Quote: |
You can nest IF/THEN/ELSE/ENDIF statement constructs up to a maximum of 15 levels. The steps that execute in a THEN clause and an ELSE clause can be another IF/THEN/ELSE/ENDIF statement construct.
|
You'd have saved time if you'd simply tried it on your system or looked in the manual . . . _________________ All the best,
di |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12370 Topics: 75 Location: San Jose
|
Posted: Thu Jun 14, 2012 12:06 pm Post subject: |
|
|
jim haire,
Chapter 17 in the JCL reference manual gives a detailed explanation of nested IF/THEN statement with examples
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IEA2B680/17.1
jim haire wrote: |
The logic is that if file 1 is empty, go to the associated ENDIF and don't do any more processing. If file 1 contains at least 1 record, check to see if file2 or file 3 contains at least one record. if one of those files contains at least one record, process through the rest of the steps. Otherwise, go the end without processing any more steps. |
Ideally I would club these into a single Step using IDCAMS .something like this
Code: |
//STEP0100 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//INP1 DD DISP=SHR,DSN=Your Input file1
//INP2 DD DISP=SHR,DSN=Your Input file2
//INP3 DD DISP=SHR,DSN=Your Input file3
//SYSIN DD *
PRINT INFILE(INP1) CHARACTER COUNT(1)
IF LASTCC = 0 THEN DO
PRINT INFILE(INP2) CHARACTER COUNT(1)
IF LASTCC = 4 THEN DO
SET LASTCC = 0
PRINT INFILE(INP3) CHARACTER COUNT(1)
IF LASTCC = 4 THEN DO
SET MAXCC = 4
END
END
END
//* |
_________________ Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
jim haire Beginner
Joined: 30 Dec 2002 Posts: 140 Topics: 40
|
Posted: Thu Jun 14, 2012 12:53 pm Post subject: |
|
|
Thanks for your input.
I did look in the reference manual first, however they don't have examples where there are nested IFs with only ENDIFs and no ELSE clauses.
If File 1 does not have any records or there are no records in File 2 or File 3 does not have any records, no other steps are to be performed, so there is really no "ELSE" condition. |
|
Back to top |
|
|
|
|