cancel
Showing results for 
Search instead for 
Did you mean: 

Strange RFC model field behavior

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Answers (0)