Five Stars

Use case for marital status

Hello,

 

I have one column for marital status having value:

 

Marital_status

M

S

D

 

and now i want,

 

Marital_status

married                           for M

single                              for S

Divorce                           for D 

1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: Use case for marital status

row1.MaritalStatus.equals("M")?
"Married":
row1.MaritalStatus.equals("S")?
"Single":
row1.MaritalStatus.equals("D")?
"Divorced":
"NA"

7 REPLIES
Six Stars

Re: Use case for marital status

Use ternary operator.. Below is logic like: (Add null check , if the Marital status column is nullable )

 

Note: I assumed the datatype for the column MaritalStatus is character so i used equality operator, if the MaritalStatus is string use equals method(String handling ).. 

 

row1.MaritalStatus=='M'?
"Married":
row1.MaritalStatus=='S'?
"Single":
row1.MaritalStatus=='D'?
"Divorced":
"NA"

Five Stars

Re: Use case for marital status

Hello ,

 

 

It is "String" 

 

 

Thanks

Six Stars

Re: Use case for marital status

row1.MaritalStatus.equals("M")?
"Married":
row1.MaritalStatus.equals("S")?
"Single":
row1.MaritalStatus.equals("D")?
"Divorced":
"NA"

Five Stars

Re: Use case for marital status

Hello ashifa,

 

i tried that but its not workin, i have attached the screenshot of the function and the output of that.

Seven Stars sgv
Seven Stars

Re: Use case for marital status

Are you sure about your Source Data ?

it's "M" or "M   " or "m"

you have to trim your data before, and i think there is a function like equalsIgnoreCase, or something like that.

 

Edit : Other thing : i see that your data is entoured by this character : '

Take Care ! You have to define in your tFileInputDelimited (Check CSV option), the entourage of your text. I think your String value must be like : "'M'" instead of "M"


Good luck,

 

SGV

Five Stars

Re: Use case for marital status

Thank you so much ...it's working 

Five Stars

Re: Use case for marital status

Looks like you're happy using Java code for this, but the tReplace component is often a much better choice for such things:

 

 

tReplace.png

 

By default you don't need to worry about case sensitivity, but can enable it for each search/replace line if required, and it keeps the logic for your job visible, rather than hidden within more general components. It also has an advanced mode which allows the use of Regular Expressions, which are incredibly powerful should you need them.

 

Whenever possible, you should use components with specific functionality like this, rather than adding complex expressions in a tMap or code in a tJava component, as doing so means your job is largely self documenting, or at least much easier for someone new picking it up to read and understand the process you're automating. Good, well laid out and labelled jobs can also be useful when discussing things with non-technical people.