OR logic: How do you code for multiple conditions ?

Formally known as "Mercator Inside Integrator 6.7", DataStage TX enables high-volume, complex transactions without the need for additional coding.

Moderators: chulett, rschirm

Post Reply
jazzer1
Participant
Posts: 37
Joined: Mon Mar 20, 2006 10:26 am

OR logic: How do you code for multiple conditions ?

Post by jazzer1 »

How would you code something like this in TX ?

IF CODE = 1, WRITE A REC
OR IF CODE = 2 WRITE B REC
OR IF CODE = 3 WRITE C REC
OR IF.... ETC
jgibby
Participant
Posts: 42
Joined: Thu Dec 16, 2004 8:48 am

Re: OR logic: How do you code for multiple conditions ?

Post by jgibby »

jazzer1 wrote:How would you code something like this in TX ?

IF CODE = 1, WRITE A REC
OR IF CODE = 2 WRITE B REC
OR IF CODE = 3 WRITE C REC
OR IF.... ETC
DatastageTX's If/Then does not have an ElseIF component common to many traditional languages. Also, it does not have true Case statement. What it does have is the EITHER function. Although not the same as a case statement, it can perform in a similar fashion. The premise behind it is to return the first non-null result. Here's one such use:

Code: Select all

=EITHER(
    Field1:Record:File
    ,Field2:Record:File
    ,Field3:Record:File
)
This would return the first field with a value. To use it in the way you are wanting, I would assume, make use of the PUT function. Here's how I would construct it.

Code: Select all

=PUT(
    "FILE"
    ,EITHER(
        IF(CODE = 1,"ARecFileName")
        ,IF(CODE = 2,"BRecFileName")
        ,IF(CODE = 3,"CRecFileName")
    )
    ,EITHER(
        IF(CODE = 1,ARec)
        ,IF(CODE = 2,BRec)
        ,IF(CODE = 3,CRec)
    )
)
The reason I would put the EITHER inside the FileName & FileContents arguments of the PUT function is that the PUT function does not return anything, thus if I constructed the statement like this,

Code: Select all

=EITHER(
    IF(CODE = 1,PUT("FILE","ARecFileName",ARec))
    ,IF(CODE = 2,PUT("FILE","BRecFileName",BRec))
    ,IF(CODE = 3,PUT("FILE","CRecFileName",CRec))
)
...then this might have the effect of writing all three records, since each PUT doesn't return anything, causing the EITHER to execute the next argument.
jazzer1
Participant
Posts: 37
Joined: Mon Mar 20, 2006 10:26 am

Post by jazzer1 »

This is great. Thanks very much.
Post Reply