Transformer logic: How to mark a record within a group once?

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
DS-mate
Participant
Posts: 2
Joined: Mon Apr 30, 2018 2:19 am

Transformer logic: How to mark a record within a group once?

Post by DS-mate »

Hi folks,

I might have a simple question regarding transformer logic. My challenge is to determine if an error within a group occured once. If the first data in a group represents an error (marked as 1) for the first time, then the counter (AmountOfWrongGroup) should be set to 1 for the record. But if there are following erros within the group it should be set to 0.

For example:

Group-ID --- Error --- AmountOfWrongGroup
A 0 0
A 1 1
A 1 0
B 1 1
B 0 0
C 0 0
C 0 0

I tried by working with stage variables and building a search string per group, but I didn't get it work correctly :(

Do you have a clue? Thanks a lot!
Cheers,
DS-mate
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Welcome aboard.

The trick is to set the stage variable to itself when you don't need to change it. For example, initialize svTest to 0.
Derive svTest as

Code: Select all

If <<error occurred>> And svTest = 0 Then 1 Else 0
You don't actually need the If..Then..Else. This Boolean logic will also work:

Code: Select all

<<error occurred>> And svTest = 0
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DS-mate
Participant
Posts: 2
Joined: Mon Apr 30, 2018 2:19 am

Post by DS-mate »

Wow thanks for the fast response.

But what is if the data comes like:

Group-ID --- Error
B ------------- 1
B ------------- 1
B ------------- 1


Using the if clause you mentioned would return: 1,0,1 wouldn't it?

Thank you very much!
Cheers,
DS-mate
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

svErrorsFound = IF In.Group-ID=svLastGroup THEN IF In.Error=1 THEN svErrorsFound+1 ELSE SvErrorsFound ELSE IF In.Error=1 THEN 1 ELSE 0
svErrorState = IF SvErrorsFound=1 THEN 1 ELSE 0
svLastGroup = In.Group-ID

The first stage variable Counts the number of "Errors" up, resetting when the Group Change occurs. The second stage variable, "svErrorState" is your Output column Derivation and the last stage variable defines your last record Group-ID value.
Post Reply