on 07-06-2023 1:58 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
joseph_muiruri Thank you very much for your elaborate answer. It works.
Thanks,
Malini
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.