cancel
Showing results for 
Search instead for 
Did you mean: 

Find a String inside another string in BODS /SAP Data services

malinisomu
Explorer
0 Kudos

Hi ,

I need to search a string value inside another string and if its exist i have to have a column with the value 'YES' or 'No'

in the below example I have to search UNSPSC_DESCRIPTION1 in COMMPODITY ASSIGNMENTS

Since there is no built in functions available.If anyone come up with some custom function that would be great help for me.

Thanks,

Malini

0 Kudos

On a Query transform use ifthenelse(substr(COMMPODITY ASSIGNMENTS, UNSPSC_DESCRIPTION1,len(COMMPODITY ASSIGNMENTS) is null, 'NO','YES')

Accepted Solutions (1)

Accepted Solutions (1)

jmuiruri
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi malinisomu,

You can create a custom script if you wish but the logic would be like shown below.

1. Use SAP Data Services in-built index(<input_string>, <index_string>, <start>) function.

a. This function returns the index of a given character sequence in a string.

b. Specifies the first location of the indicated character sequence.

c. Index

d. Basically, if the value we are looking for is present we will get its index otherwise we will get NULL.

e. The only problem with the above function is that if the value we are searching for is present in the lookup column but with a different case e.g uppercase/lowercase there will be inconsistencies.

2. To by pass the uppercase/lowercase issue with the index function we first need to convert both columns to lowercase using the lower() function.

3. Now that the index correctly matches the values and returns the index, we can then use the ifthenelse() function to return the desired result based on the condition. In our case the index will return null if the value we are looking for is not present, so our condition could look something like below.

##ifthenelse( index(lower(Query."Commodity Assignments"), lower(Query.UNSPSC_DESCRIPTION1),1 ) > 0, 'YES', 'NO')
ifthenelse( index(lower(Query."Commodity Assignments"), lower(Query.UNSPSC_DESCRIPTION1),1 ) IS NOT NULL, 'YES', 'NO')

4. Please do note that you can also put the above code as a custom script. It could look something like shown below.

begin
        $col_y = lower($col_y); # Change to lowercase
	$col_x = lower($col_x); # Change to lowercase
    if(index($col_y, $col_x,1) IS NOT NULL )
        begin
            $is_col_x_in_col_y = 'YES';
        end
    else 
        begin
            $is_col_x_in_col_y = 'NO'; 
        end
   Return $is_col_x_in_col_y ; 
end

References

Best Regards,

Joseph

Answers (1)

Answers (1)

malinisomu
Explorer
0 Kudos

joseph_muiruri Thank you very much for your elaborate answer. It works.

Thanks,

Malini