Multiple Conditions

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
New2DS
Participant
Posts: 33
Joined: Sat Jun 26, 2004 9:58 am

Multiple Conditions

Post by New2DS »

Which is the best way to implement the below conditions in the routine.

Code: Select all

If PROGRM = 999 AND 

	Not (CODE[1,3] >= 551 and CODE[1,3] <= 562) AND 
	Not (CODE[1,3] >= 890 and CODE[1,3] <= 889 AND 
	((CODE2[1,3] >= 581 AND CODE2[1,3] <= 591 ) OR 
	( CODE2[1,3] >= 641 AND CODE2[1,3] <= 645 ) OR 
	( CODE3[1,3] >= 581 AND CODE3[1,3] <= 591 ) OR 
	( CODE3[1,3] >= 641 AND CODE3[1,3] <= 645 ))
  AND  REC_CD IN ( '925', '926', '928','929','930')
THEN
	DAY = '210'
ELSE
	DAY = '221'
I read some of the posts about the nested if statements. Is it like taking out the 'and' and 'or' conditions and appending them with 'if' and 'then'?

I mean like

Code: Select all

If PROGRM = 999 THEN
 IF Not ((CODE[1,3] >= 551 and CODE[1,3] <= 562)) THEN
 IF Not ((CODE[1,3] >= 960 and CODE[1,3] <= 979) THEN 
 IF (CODE2[1,3] >= 581 AND CODE2[1,3] <= 591 ) THEN
  DAY = '210'
 END END END END

ELSE '221'
I didn't validated the nested if but I did validated the above code and i have to type everything in single line but it worked. Will my routine fail if I don't use the nested if conditions if I have large amount of data?

I hope I will get helped to figure out the best way.

thanks
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There is no IN operator, so you probably need explicit equality tests for REC_CD, or a range test and an exclusion for '927'.

A neat way to do range checking in server jobs (incidentally you posted in the wrong forum) is Oconv with an "R" conversion. This allows multiple range checks in a single function. Read the help topic "R Code". For example:

Code: Select all

Oconv(CODE2[1,3],"R;551,562;641,645")
Oconv(REC_CD,"R926,926;928,930")
Pre-evaluate your substring expressions into local variables, otherwise you're performing the substring operation too many times.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

You could write your own INLIST type function, such as one posted here:
viewtopic.php?t=85440&highlight=inlist
to simplify some of what you're doing. Ray's suggestion to use a stage variable to hold the 3 char substring you're using over and over is another good idea. You may consider writing a BETWEEN type function so that you can simply state something like: BETWEEN(stagevar, 551, 562).

You could simplify your statement down to:

Code: Select all

If PROGRM = 999 AND 
   Not(BETWEEN(CODEsv3,551,562)) AND 
   Not(BETWEEN(CODEsv3,890,889)) AND 
blah
blah
blah
   AND INLIST(REC_CD, '925,926,928,929,930') 
THEN 
   DAY = '210' 
END ELSE 
   DAY = '221'
END
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Post Reply