Six Stars

Flag changing in tmap

Hi All,

I have a requirement where I need to change flag from y to n based on a condition.my data looks like below
Id;flag
1;y
2;y
1;
My output should be
Id;flag
1;n
2;y
1;y
If ids are same and have a flag value as y then it has to change to n and if the flag is null it has to change to y

Can anyone Suggest a solution, if so would be a great help.

Thanks in advance,
Lmit

1 ACCEPTED SOLUTION

Accepted Solutions
Twelve Stars

Re: Flag changing in tmap

please give kudos and Accept the solution when you think you're good with it.
Manohar B
21 REPLIES
Moderator

Re: Flag changing in tmap

Hello,

 You can use ternary operator for if-else scenario in tMap or join your two tables.

 Condition?value if true:value if false

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Six Stars

Re: Flag changing in tmap

Hi Sabrina,,

 

Thanks for your reply . but can you be little bit clear about what you said??

 

Thanks in advance,

lmit

Twelve Stars

Re: Flag changing in tmap

First sort the data based on Id and create create a Var for current Id and Previous Id and compare the Prevous Var with Current Var equls then y else n. use this way.
Manohar B
Six Stars

Re: Flag changing in tmap

Hi,

 

Thanks manohar for the reply.

 

the data in file can have n number of rows with same id and other ids which are not same like

 

id,flag

1,Y

2,Y

3,Y

1,

1,Y

 

both the id's 1 with flag Y should be become N and with null should become N

but id's 2 with flag Y should be Y only

 

Thanks,

lmit

 

 

Twelve Stars

Re: Flag changing in tmap

since you can sort the data based on Id Asc and Flag Asc order in tSortrow,you wil lget in required way and then you can compare in tmap and derive new flag.

 

Manohar B
Twelve Stars

Re: Flag changing in tmap

If this help please give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

Manohar B
Twelve Stars

Re: Flag changing in tmap

still you have issue?

Manohar B
Six Stars

Re: Flag changing in tmap

Yes Manohar,

 

Flag still not changing, after sorting and comparing also the flag is not changing.

 

for both values its changing, i mean for all values where Y is there is getting changed to N

 

Thanks,

Lmit

Twelve Stars

Re: Flag changing in tmap

Can you show your job design?
Manohar B
Six Stars

Re: Flag changing in tmap

screenshot is not allowed to take,jib flow is as below

 

inputfile --> tuniqrow --> tmap --> outputfile

 

i appiled uniqrow on both columns id and flag

 

the output is :

1,N

1,Y

2,N

thanks,

lmit

Twelve Stars

Re: Flag changing in tmap

why you used tuniqrow?i asked you to do sort using tSortrow

Manohar B
Six Stars

Re: Flag changing in tmap

sorry , my mistake i used tsortrow only

Six Stars

Re: Flag changing in tmap

row2.flag.equals("Y") ? "N": StringHandling.LEN(row2.flag)==0 ? "Y": row2.flag

 

use this expression

Twelve Stars

Re: Flag changing in tmap

Could you please let me know the conditions and variable port in tMap

Manohar B
Six Stars

Re: Flag changing in tmap

hi pls find the attachment.

 

Thanks

Venkata Kiran

Twelve Stars

Re: Flag changing in tmap

Please find the attahced code.

Manohar B
Six Stars

Re: Flag changing in tmap

thats a good one bro

Twelve Stars

Re: Flag changing in tmap

If this help please give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

Manohar B
Twelve Stars

Re: Flag changing in tmap

@lmit still you have issue?

Manohar B
Six Stars

Re: Flag changing in tmap

hi Manohar,

 

its working fine with some other changes as per requirements, thanks a lot for your time and support

 

Thanks,

Lmit 

Twelve Stars

Re: Flag changing in tmap

please give kudos and Accept the solution when you think you're good with it.
Manohar B