cancel
Showing results for 
Search instead for 
Did you mean: 

Eliminating Leading Zeros for Input

paul_gloede
Participant
0 Kudos

Hello,

I am very new to the world of Netweaver Portals and Web Dynpro, so please have some patience.

I have created an application in Web Dynpro which will display the Stock Requirements for a Material. Everything is working fine with the exception that the User needs to enter 10 leading zeros before they enter the material number. Is this something that I can correct in Web Dynpro, or is there something I need to do on the R/3 side?

In R/3, the user can simply type in the 7 digit material number, but in my Web Dynpro App, they need to enter a 17 digit number (10 leading zeros and the 7 digit mat number).

I have checked other topics, but couldn't find where this exact issue has been addressed. Thanks for your help.

Paul

Accepted Solutions (0)

Answers (3)

Answers (3)

paul_gloede
Participant
0 Kudos

Thanks for your input Sebastian and Armin. I am that "Newbie" that you are talking about and this forum does help out greatly. I will award points accordingly.

Paul

Former Member
0 Kudos

1)If you bind you inputfield to context node directly, the webdynpro itself convert it into 17 digit number.

2)if you are using Jco you have to append the leading zero's.

if satement 1 is wrong, you can do the following.

you can calculate string length of input field before executing the bapi and append leading zeros and set the attribute with new string.

Thanks,

Damodhar.

Former Member
0 Kudos

Paul,

one possible solution for this issue might be to write some code to add the missing zeros. For example you can put the coding in a action method.

Please take a look at the following snippet:

// get the material number from context (this is the number entered by the user)

String id = wdThis.wdGetWelcomeComponentController().wdGetContext().currentContextElement().getMaterialID();

if(id.length() < 17) {

for(int i = 0; i < 17 - id.length(); i++) {

id = "0" + id;

}

}

// your id is now a 17 digit number

I that helps you.

Sebastian

Former Member
0 Kudos

This is not really an elegant way of doing it.

What about

static final String Z17 = "00000000000000000";
if (id == null)
{
  id = Z17;
}
else if (17 - id.length() > 0)
{
  id = Z17.substring(0, 17 - id.length()) + id; 
}

Armin

Former Member
0 Kudos

Armin,

yes you are right. This is a little bit more elegant. But if you want to do it the elegant way you can reduce this to only two lines of code:


/* note that you cannot declare a static variable inside a method, only use final or declare it as attribute of the class */
final String Z17 = "00000000000000000"; 
id = Z17.substring(0, id == null ? 0 : 17 - id.length()) + id;

regards

Sebastian

Former Member
0 Kudos

sorry...this is the right one:


final String Z17 = "00000000000000000"; 
id = (id == null) ? Z17 : Z17.substring(0, Math.max(0, 17 - id.length())) + id;

Sebastian

Former Member
0 Kudos

Try your (original) code (fixing it silently does not count with a string longer than 17.

(And yes, I know that static constants cannot be defined inside a method. I expect the reader to understand this nevertheless, aka "Transferleistung" in german

Armin

Message was edited by: Armin Reichert

Former Member
0 Kudos

Armin,

yes your are right of course. Sorry for the silent fix :-). It's quite plain to me that you know where to define a static constant, the remark was targeted at the readers who are no experts on java

Sebastian

Former Member
0 Kudos

No problem. I absolutely agree with you that we must be very careful when posting code snippets because many readers take them very literally.

Regards, Armin

Former Member
0 Kudos

Hi Armin,

I have used your code and I am still not able to change the value of the input field by adding Zeros infront of it. Could help me to resolve this issue. I would appreciate your help.

Regards,

Gopal