on 01-12-2009 3:27 PM
Hi all
I'm working with an RFC that have a table structure Foo_Item that contains the field Postion. This field has ABAP component type BUZEI and data type NUMC.
This is represented in Java as a String. My problem is that it displays as "000" when the value of the field is null. I would like it to display "" (the empty string).
Consider this code (in the component controller):
Foo_Item oldItem = <some instance of Foo_Item>
Foo_Item.setPostion(null);
if (Foo_Item != null) {
Foo_Item newItem = new Foo_Item();
// Here, newItem.getPostion() -> null
WDCopyService.copyCorresponding(oldItem, newItem);
// Now, newItem.getPostion() -> "000"
newItem().setPostion(null);
// Mindblowingly, newItem.getPostion() -> "000" still!
}
Now, something strange is going on behind the scenes here. Can anyone point me in the right direction?
-martin
Hi Martin,
There is a class behind the scenes that returns a String but internally represents a NUMC.
You will have to copy your value in a normal String and remove the leading zeros (If you do not want any leading zeros that is)
//@@begin javadoc:removeLeadingZeros()
/** Declared method. */
//@@end
public java.lang.String removeLeadingZeros( java.lang.String inString )
{
//@@begin removeLeadingZeros()
String outString = "";
if (inString != null) {
int length = inString.length();
for (int i = 0; i < length; i++) {
char s = inString.charAt(i);
if (s == '0') {
//do nothing here
} else {
outString = inString.substring(i);
break;
}
}
}
return outString;
//@@end
}
Regards,
Jeschael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Jeschael, that did the trick for me.
I've added a call to this in my view controller's doModifyView, iterating over the elements in the node. There's a small performance penalty for this, I know. I first tried doing it with a getter method for the context attribute, but this only works for the lead selection.
-martin
You can add an extra node in your original node of the type 1..1 and selection 1..1. and put a calculated field in that. This way it will work for all your rows automatically, not only the selected. You can use the parameter that you will get to know which elemtn you need to read.
J
Edited by: J.V. Lebbink on Jan 13, 2009 3:35 PM
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.