How to have Multiple Line Condition in a routine?
Moderators: chulett, rschirm, roy
How to have Multiple Line Condition in a routine?
Hi,
I have a routine which has multiple If statement like given below
eg: If (condition1 and Condition2... ) OR (condition3... And condition4....)
Then Ans = 'ZZZ'
Else (condition5.... and Condition6....)
When I put the conditions in a single line then my routine works. If I put them in multiple lines, It gives "End of Line unexpected" Error.
How do I write a multi line if statement in a routine?
I tried using semi colon and comma as well.
Cheers
I have a routine which has multiple If statement like given below
eg: If (condition1 and Condition2... ) OR (condition3... And condition4....)
Then Ans = 'ZZZ'
Else (condition5.... and Condition6....)
When I put the conditions in a single line then my routine works. If I put them in multiple lines, It gives "End of Line unexpected" Error.
How do I write a multi line if statement in a routine?
I tried using semi colon and comma as well.
Cheers
Victor Auxilium
Hi,
the if syntax you need is:
though you don't always need this format, it is more clear and readable plus there is litle chance you'll get compilation errors that you don't understand.
IHTH
the if syntax you need is:
Code: Select all
If expr1 And expr2 Or ... Then
...
...
End
Else
If .... Then
...
End
...
...
End
IHTH
Roy R.
Time is money but when you don't have money time is all you can afford.
Search before posting:)
Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Time is money but when you don't have money time is all you can afford.
Search before posting:)
Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
-
- Premium Member
- Posts: 39
- Joined: Tue May 20, 2003 3:36 am
- Location: Singapore
Re: How to have Multiple Line Condition in a routine?
victor,
if i remember it correctly, there's no line continuation character in DS Basic (search this forum; it's been discussed before) so that if your condition becomes too long, you'll just have to logically split them into either
1. a nested if, or
regards,
vladimir
if i remember it correctly, there's no line continuation character in DS Basic (search this forum; it's been discussed before) so that if your condition becomes too long, you'll just have to logically split them into either
1. a nested if, or
2. use a case statementif condition1 and condition2 then
...
end else
if condition3 and condition4 then
end else
...
i always prefer the case statement over nested if because of it's more readable.begin case
case condition1 and condition2
...
case condition3 and condition4
...
[add more cases]
...
case @TRUE
...
end case
regards,
vladimir
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Any statement that has THEN or ELSE (or ON ERROR or LOCKED) clauses can use "single-line format" or "multi-line format". Here is a formal statement of the syntax rule.
The other format is driven by the same rule, expressed here negatively.
Multiple statements can appear in single-line format, separated by semi-colons. For example:
This is legal, but not recommended practice. Prefer multi-line format when there is more than one statement subject to the test condition.
This is multi-line format. Here are two examples of multi-line format.If the keyword that introduces the clause (THEN, ELSE and so on) is the last word on the line on which it appears, then there must be a corresponding END statement.
Code: Select all
IF condition THEN
statements
END ELSE
statements
END
IF condition
THEN
statements
END
ELSE
statements
END
This is single-line format. Here are two examples of single-line format.If the keyword that introduces the clause is not the last word on the line on which it appears, then there must not be a corresponding END statement.
Code: Select all
IF condition THEN statement ELSE statement
IF condition
THEN statement
ELSE statement
Code: Select all
IF condition THEN statement1; statement2
Last edited by ray.wurlod on Thu Nov 27, 2003 5:17 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 133
- Joined: Wed Mar 05, 2003 4:19 pm
- Location: Lima - Peru. Sudamerica
- Contact:
Re: How to have Multiple Line Condition in a routine?
Saludos,
Miguel Seclén
Lima - Peru
Miguel Seclén
Lima - Peru
My Routine is like this. Can someone help?
Hi,
My Routine is like this.
IF ((CD_FORM1 = 300 And YR_RECEIVED1 = CY)
And (CD_FORM2 = 393 And DT_RECEIVED2 > DT)
And (CD_FORM3 = 990 And DT_RECEIVED3 > DT))
OR ((CD_FORM1 = 300 And DT_RECEIVED1 > DT)
And (CD_FORM2 = 393 And DT_RECEIVED2 > DT)
And (CD_FORM3 = 990 And YR_RECEIVED3 = CY))
OR ((CD_FORM1 = 300 And DT_RECEIVED1 > DT)
And (CD_FORM2 = 393 And YR_RECEIVED2 = CY)
And (CD_FORM3 = 990 And DT_RECEIVED3 > DT))
Then Ans = '6A' Else Ans = '6B'
IF I compile like this then I get error. If I put the condition in a single line, then No errors.
IS there any way I can put in multiple lines?
Cheers
My Routine is like this.
IF ((CD_FORM1 = 300 And YR_RECEIVED1 = CY)
And (CD_FORM2 = 393 And DT_RECEIVED2 > DT)
And (CD_FORM3 = 990 And DT_RECEIVED3 > DT))
OR ((CD_FORM1 = 300 And DT_RECEIVED1 > DT)
And (CD_FORM2 = 393 And DT_RECEIVED2 > DT)
And (CD_FORM3 = 990 And YR_RECEIVED3 = CY))
OR ((CD_FORM1 = 300 And DT_RECEIVED1 > DT)
And (CD_FORM2 = 393 And YR_RECEIVED2 = CY)
And (CD_FORM3 = 990 And DT_RECEIVED3 > DT))
Then Ans = '6A' Else Ans = '6B'
IF I compile like this then I get error. If I put the condition in a single line, then No errors.
IS there any way I can put in multiple lines?
Cheers
Victor Auxilium
NO.
You could write it like this for clarity:
You could write it like this for clarity:
Code: Select all
X=((CD_FORM1 = 300 And YR_RECEIVED1 = CY) And (CD_FORM2 = 393 And DT_RECEIVED2 > DT) And (CD_FORM3 = 990 And DT_RECEIVED3 > DT))
Y=((CD_FORM1 = 300 AndDT_RECEIVED1 > DT) And (CD_FORM2 = 393 And DT_RECEIVED2 > DT) And (CD_FORM3 = 990 And YR_RECEIVED3 = CY))
Z=((CD_FORM1 = 300 And DT_RECEIVED1 > DT) And (CD_FORM2 = 393 And YR_RECEIVED2 = CY) And (CD_FORM3 = 990 And DT_RECEIVED3 > DT))
IF X OR Y OR Z Then Ans = '6A' Else Ans = '6B'
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
While noting your original post that you are doing this in a Routine, note also the fact that if you're doing it in an Expression (or, by extension, in a Transform), it must all be on one line.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Premium Member
- Posts: 51
- Joined: Tue Feb 05, 2002 3:06 pm
One technique I've used it to create an array and then use a For - Next loop to do the if condition in. If I have more than one type of value I would make a corresponding second one dimensional array and use it as well. Also, if we find that the values change periodically, we have used text files to hold the values and then read these text files in to populate the array(s). Each month we email these text files (that we call "profiles") to the users for them to review. We apply any changes to the text files so that we don't have to change our DataStage code.
Scott
Scott