How to remove leading zeroes from a list filter to display data without the zeroes?

Hi all,

I have a list filter which is getting data from an SAP Bapi. In this list filter there is a material number that I want to display on my screen. The data coming from SAP has 10 leading zeros in front of the material number but I don't want it to show those zeroes on my screen.
I tried using the trim function but that doesn't work. How can I get this to work? How do I crop/trim/remove the zeroes in front of this material number which I am assigning to a variable called processorderinfo_record?

Hi ZK,

apparently this piece of data is defined as a text in either only the api, or maybe even in SAP itself.

What you are saying is "i know it is numeric, even if the type is text, so all leading zeroes can be ignored, so i don't want to display them".

You could apply some string functions to remove the leading zeroes but still keep it as a text, or you could convert it to a long integer.

The first has the disadvantage of not being able to sort afterwards (unless you like seeing the 10 before the 2) (you could mitigate that by also keeping the original value in your list and sort on that)

The second has the disadvantage that your code will break if at the other end of the api somebody decides to put non numeric values in this field at some later time.

If I were you, I would try to understand why the leading zeros are there in the first place, i.e. why is it not simply an integer in the api ??  It could be bad api design, or it could be for a good reason, and then it might be worth respecting this design decision in your application.

Dorine

see attached oml for an example, I'm not sure regex replace is really necessary, but i just like it.

QDRStringNumeric.oml

Hi Dorine!

Thanks so much for taking the time to explain this to me. I used the Regex_Replace function to make it work. As you said, I know this is a number but in SAP it actually shows as text. I will be getting in touch with some ABAP developers in my team to understand why this was coded that way.

Also, for my understanding, that pattern you use in the Regex_Replace function "^0+" what is it actually doing? Do you always use this particular pattern whenever using a regex_replace function?

Thanks again.
ZK

Hi ZK,

the pattern is a description of what piece of text you are looking for.  There´ s a lot of options, you can google it, for this particular pattern :

- the ^ says i´ m only considering it a match if it is at the start of the string

- the 0 says i´ m only considering it a match if is the character 0

- the + says that i´  m considering any number 1 or more of that character a match

There are regex parsers available online for free where you can try this stuff out, and some give good explanation about what you are doing.

Dorine

Thanks for breaking it down and explaining in a very simplified manner. I am new to outsystems and all this is really helping me get the hang of it. Will definitely try out the regex parsers available online.

ZK

Hello Marcio,

Please note that replace will replace all instances of 0's including those that occur after the first 10 zeroes. So for e.g. '0000000000349010330' will end up like this '349133' and what ZK wants is this '349010330'

Hello @ZK 

Another option for you, if the leading zeroes will always be 10 in length, you could simply use the 'Substr' built-in function for e.g. as shown below:

Substr(Input,10,20)

Regards,

AJ

Yes, you're right!!! Thanks, I didn't know that!! I wasn't aware of it. I have put just the link now, and ZK maybe can find his(one of) answers also with the answers on the link. That is talking about leading zeros too.!! :)

Kind Regards,

Márcio

Hi ZK,

apparently this piece of data is defined as a text in either only the api, or maybe even in SAP itself.

What you are saying is "i know it is numeric, even if the type is text, so all leading zeroes can be ignored, so i don't want to display them".

You could apply some string functions to remove the leading zeroes but still keep it as a text, or you could convert it to a long integer.

The first has the disadvantage of not being able to sort afterwards (unless you like seeing the 10 before the 2) (you could mitigate that by also keeping the original value in your list and sort on that)

The second has the disadvantage that your code will break if at the other end of the api somebody decides to put non numeric values in this field at some later time.

If I were you, I would try to understand why the leading zeros are there in the first place, i.e. why is it not simply an integer in the api ??  It could be bad api design, or it could be for a good reason, and then it might be worth respecting this design decision in your application.

Dorine

see attached oml for an example, I'm not sure regex replace is really necessary, but i just like it.

QDRStringNumeric.oml

Hi Dorine!

Thanks so much for taking the time to explain this to me. I used the Regex_Replace function to make it work. As you said, I know this is a number but in SAP it actually shows as text. I will be getting in touch with some ABAP developers in my team to understand why this was coded that way.

Also, for my understanding, that pattern you use in the Regex_Replace function "^0+" what is it actually doing? Do you always use this particular pattern whenever using a regex_replace function?

Thanks again.
ZK

Hi ZK,

the pattern is a description of what piece of text you are looking for.  There´ s a lot of options, you can google it, for this particular pattern :

- the ^ says i´ m only considering it a match if it is at the start of the string

- the 0 says i´ m only considering it a match if is the character 0

- the + says that i´  m considering any number 1 or more of that character a match

There are regex parsers available online for free where you can try this stuff out, and some give good explanation about what you are doing.

Dorine

Thanks for breaking it down and explaining in a very simplified manner. I am new to outsystems and all this is really helping me get the hang of it. Will definitely try out the regex parsers available online.

ZK

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.