cancel
Showing results for 
Search instead for 
Did you mean: 

Removing leading zeros in a column

Former Member
0 Kudos

Hi,

I would like to remove leading zeros of a column in a table. My Questions :

1. Is it possible?

2. Where is it better to truncate, in RFC or Web Dynpro?.

3. If Possible, How can I do that.

I appreciate your input.

Thanks,

Sunita.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

For a read-only table cell, you could create a calculated attribute "TruncatedValue" in the context that returns the truncated value. ("Value" denotes the original attribute)

Example:

/* getter of calculated attribute */
String get<Node>TruncatedValue(I<Node>Element element)
{
  return removeLeadingZeroes(element.getValue());
}

/* Utility method */
static String removeLeadingZeroes(String s)
{
  if (s == null) return null;
  int i = 0;
  int n = s.length();
  while (i < n)
  {
    if (s.charAt(i) != '0') break;
    ++i;
  }
  return s.substring(i);
}

Armin

Answers (3)

Answers (3)

Former Member
0 Kudos

hi

good

use this function module

CONVERSION_EXIT_ALPHA_OUTPUT converts any number with zeroes right into a simple integer

Example:

input = 00000000000123

output = 123

thanks

mrutyun^

Former Member
0 Kudos

Hi,

I think it's better to do the truncation in WD. Assuming that you are using WD java, you can use a code like:


public void removeLeadingZeroes(IWDNode tableData,String attribute)
{
   for(int i = 0; i < tableData.size(); i++){
      IWDNodeElement tableDataElement = tableData.getElementAt(i);
      String rfcData = tableDataElement.getAttributeAsText(attribute);
      tableDataElement.setAttribute(attribute,Integer.toString(Integer.parseInt(rfcData)));
   }
}

Regards,

Satyajit.

Former Member
0 Kudos

Hi Sunita,

Please specify the datatype of the column that contains leading zeros, because if the data type of the column is integer then the leading zeros are automatically taken care.

If your RFC return you int and you are assigning it to a String then the leading zeros will appear.

For example, see the below simple ABAP Program. Just copy and execute it. You will see the difference.


data: a type mara-matnr,
      str type string.
select single matnr from mara into a.
write a.
str = a.
write / str.

Hope it helps you.

Regards,

Maheswaran.B

Message was edited by: Maheswaran B