While condition in Loop statement

Archive of postings to DataStageUsers@Oliver.com. This forum intended only as a reference and cannot be posted to.

Moderators: chulett, rschirm

Locked
admin
Posts: 8720
Joined: Sun Jan 12, 2003 11:26 pm

While condition in Loop statement

Post by admin »

Hi,


Could I put more than one condition in the "While" in this loop statement?
I want the program exit the loop (with a warn message) if Left(Ligne,1) =
< in the ptfile.

That is, if readseq begun at the A label, the program have to exit (stop
seq reading) when he encounter the B label, and if it begun at the B label,
exit at the end of the file.


*** The file ptfile is :


file1=toto
file2=titi


file1=tata

*** The loop statement :

Loop
While ReadSeq Ligne from ptfile

If Trim(Field(Ligne,=,1)) = NomParam
Then ValParam = Trim(Field(Ligne,=,2))

Exit
End
Repeat

Ans=ValParam

**

Thanks,


Kasia
admin
Posts: 8720
Joined: Sun Jan 12, 2003 11:26 pm

Post by admin »

You need to structure your logic differently. Setup your loop to process until the condition Done is TRUE. If you exhaust the number of lines in your file Done will be set to TRUE. If you encounter a condition in your loop where you wish to set Done to TRUE, this logic works the same. This is a very good structure to use in coding LOOPs, as it handles almost every situation.

Done = @FALSE
LOOP
Readseq line from FILE Else Done = @TRUE
UNTIL Done DO
If (your condition for exiting loop) Then
Done = @TRUE
End Else
(Logic to be processed if youre not at your exit condition)
End
REPEAT








katarzyna.lewicka@cgey.com on 17-Sep-2001 08:11



Please respond to datastage-users@oliver.com

To: datastage-users
cc:
Subject: While condition in Loop statement


Hi,


Could I put more than one condition in the "While" in this loop statement? I want the program exit the loop (with a warn message) if Left(Ligne,1) = < in the ptfile.

That is, if readseq begun at the A label, the program have to exit (stop seq reading) when he encounter the B label, and if it begun at the B label, exit at the end of the file.


*** The file ptfile is :


file1=toto
file2=titi


file1=tata

*** The loop statement :

Loop
While ReadSeq Ligne from ptfile

If Trim(Field(Ligne,=,1)) = NomParam
Then ValParam = Trim(Field(Ligne,=,2))

Exit
End
Repeat

Ans=ValParam

**

Thanks,


Kasia
Locked