on ‎2019 Sep 19 10:45 AM
Hi all,
I'm looking for any helps, tips or advices for my current problem:
I have a function that is written in Java and I'm trying to replace this with GroovyScript. I have some trouble of handle the SUPPRESS from the ResultList class in Groovy.
Is there another way to implement a suppres in Groovy?
There is a good example by 7a519509aed84a2c9e6f627841825b5a in Groovy Script to remove Suppress and Null in SAP Cloud Platform but I couldn't figure it out how to realise this.
Here is my coding:
JAVA CODE:
public void foo(String[] cv, ResultList r, Container c) {
if (cv != null && cv.length > 0) {
for (int y = 0; y < cv.length; y++) {
String s = cv[i];
if (s != null && s.trim().length() > 0
&& !ResultList.SUPPRESS.equalsIgnoreCase(s)) {
r.addValue("");
} else {
r.addSuppress();
}
}
} else {
r.addSuppress();
}
}
GROOVY CODE:
import com.sap.it.api.mapping.*
def void foo(String[] cv, ResultList r, Container c, Output output, MappingContext context) {
if (cv != null && cv.length > 0) {
for (int y = 0; y < cv.length; y++) {
def s = cv[i];
if (s != null && s.trim().length() > 0
&& !ResultList.SUPPRESS.equalsIgnoreCase(s)) {
output.addValue("");
} else {
output.addSuppress();
}
}
} else {
output.addSuppress();
}
}
Many thanks in advance for your help
Regards
Timo
Request clarification before answering.
Hi Timo
Everything you require is in the Output interface. Specifically, you need the isSuppress method.
I believe the following code implements your logic in Groovy:
import com.sap.it.api.mapping.*
def void handleSuppress(String[] values, Output output, MappingContext context) {
if (values.length > 0) {
values.each { s ->
if (s != null && s.trim().length() > 0 && !output.isSuppress(s)) {
output.addValue("")
} else {
output.addSuppress()
}
}
} else {
output.addSuppress()
}
}
Now, whether that logic actually solves your real problem, I cannot possibly say 🙂 But since you asked specifically about converting to Groovy, that's what I did.
Regards,
Morten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Morten,
thank you for your response.
Your code is working pretty fine and I really appreciate your help!
Regards,
Timo
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.