How to have Multiple Line Condition in a routine?

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
asvictor
Participant
Posts: 31
Joined: Tue Sep 02, 2003 3:06 am
Location: Singapore
Contact:

How to have Multiple Line Condition in a routine?

Post by asvictor »

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
Victor Auxilium
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
the if syntax you need is:

Code: Select all

If expr1 And expr2 Or ... Then
  ...
  ...
End
Else
  If .... Then
    ...
  End
  ...
  ...
End
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
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
Image
degraciavg
Premium Member
Premium Member
Posts: 39
Joined: Tue May 20, 2003 3:36 am
Location: Singapore

Re: How to have Multiple Line Condition in a routine?

Post by degraciavg »

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
if condition1 and condition2 then
...
end else
if condition3 and condition4 then
end else
...
2. use a case statement
begin case
case condition1 and condition2
...
case condition3 and condition4
...
[add more cases]
...
case @TRUE
...
end case
i always prefer the case statement over nested if because of it's more readable.

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

Post by ray.wurlod »

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.
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.
This is multi-line format. Here are two examples of multi-line format.

Code: Select all

IF condition THEN
   statements
END ELSE
   statements
END

IF condition
THEN
   statements
END
ELSE
   statements
END
The other format is driven by the same rule, expressed here negatively.
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.
This is single-line format. Here are two examples of single-line format.

Code: Select all

IF condition THEN statement ELSE statement

IF condition
   THEN statement
   ELSE statement
Multiple statements can appear in single-line format, separated by semi-colons. For example:

Code: Select all

IF condition THEN statement1; statement2
This is legal, but not recommended practice. Prefer multi-line format when there is more than one statement subject to the test condition.
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.
jseclen
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?

Post by jseclen »

Hi

THis is a last post in the forum,

viewtopic.php?t=85440&highlight=condition+lines

:lol:
Saludos,

Miguel Seclén
Lima - Peru
asvictor
Participant
Posts: 31
Joined: Tue Sep 02, 2003 3:06 am
Location: Singapore
Contact:

My Routine is like this. Can someone help?

Post by asvictor »

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
Victor Auxilium
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

NO.


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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

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.
Teej
Participant
Posts: 677
Joined: Fri Aug 08, 2003 9:26 am
Location: USA

Post by Teej »

That is a pretty nasty limitation for BASIC. Yeah, Ken's workaround is neater, but it still is a nasty limitation.

-T.J.
Developer of DataStage Parallel Engine (Orchestrate).
scottopizza
Premium Member
Premium Member
Posts: 51
Joined: Tue Feb 05, 2002 3:06 pm

Post by scottopizza »

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
Post Reply