View previous topic :: View next topic
|
Author |
Message |
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
I got the following code to print out data set name that meet the condition, if not ,it will print out "NOT FOUND' . Because of the loop ,everytime it not meet the condition, it will print one "NOT FOUND". eg, if A=4 , all four date set are not meet the condition , it print :
Code: |
NOT FOUND
NOT FOUND
NOT FOUND
NOT FOUND |
if thrid one meet the condition , it print
Code: |
NOT FOUND
NOT FOUND
CPM.GCICS.BATCH.DB2SUMM.BKUP.G4300V00
NOT FOUND |
How to correct this code to print only one "NOT FOUND" when condition not meet and only date set name when it meet the condition?
Thank you !
Code :
Code: |
WHEN FOUND='DEC' THEN DO
DAY= INPUT_DAY+335 /* CHECK FOR DAY */
DO L=1 TO A
SELECT
WHEN DEC.L /='' & DS_D.L= DAY THEN
SAY DEC.L
WHEN DEC.L /='' & INPUT_DAY=0 THEN
SAY DEC.L
OTHERWISE
SAY 'NOT FOUND'
END
END
END |
|
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
I think it should be simple enough. Just use an indicator (FILE_FOUND)
Code: |
WHEN FOUND='DEC' THEN DO
DAY= INPUT_DAY+335 /* CHECK FOR DAY */
FILE_FOUND = 'N'
DO L=1 TO A
SELECT
WHEN DEC.L /='' & DS_D.L= DAY THEN
DO
FILE_FOUND = 'Y'
SAY DEC.L
END
WHEN DEC.L /='' & INPUT_DAY=0 THEN
DO
FILE_FOUND = 'Y'
SAY DEC.L
END
OTHERWISE
END
END
IF FILE_FOUND = 'N'
THEN DO
SAY 'NOT FOUND'
END
END |
|
|
Back to top |
|
|
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
Thank you ! I should think about this |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3073 Location: NYC,USA
|
|
|
|
Is that what you expect? just to print only 1 'NOT FOUND' if A=p?
p= any number
Code: |
WHEN FOUND='DEC' THEN DO
DAY= INPUT_DAY+335 /* CHECK FOR DAY */
n = 1
m= 0
DO L=1 TO A
SELECT
WHEN DEC.L /='' & DS_D.L= DAY THEN
SAY DEC.L
WHEN DEC.L /='' & INPUT_DAY=0 THEN
SAY DEC.L
OTHERWISE
m = n+1
if m=2
SAY 'NOT FOUND'
end
END
END
END
|
RahulG31, in your case (if I get him correctly), it will still print 'NOT FOUND' 4 times if none of the dataset condition is meet when say A= 4.
Also, check if you can club (DS_D.L= DAY or INPUT_DAY=0) & DEC.L /='' together instead of two separate hence simple if else will do instead of select when. |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
No. The following condition is outside the DO loop, so only 1 'NOT FOUND':
Code: |
IF FILE_FOUND = 'N'
THEN DO
SAY 'NOT FOUND'
END |
There will be multiple File Names that will be printed (if multiple are found) but if none is found then only one 'NOT FOUND'.
. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3073 Location: NYC,USA
|
|
|
|
so if A=4 and first 3 are FILE_FOUND = N and last one is FILE_FOUND ='Y' then it will never print 'NOT FOUND' or I am mistaken? |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
Yes, that's what it should be.
Quote: |
How to correct this code to print only one "NOT FOUND" when condition not meet |
Quote: |
and only date set name when it meet the condition?
|
I believe, print 'NOT FOUND' when none is found and If even a single one is found then print the file name and then No need to print 'NOT FOUND'.
. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3073 Location: NYC,USA
|
|
|
|
if what you believe is true then it should work otherwise he have another choice. |
|
Back to top |
|
|
|