cancel
Showing results for 
Search instead for 
Did you mean: 

Append The 0000 to Sales order number

Former Member
0 Kudos

Hi Experts,

suppose its 10 digit sales order .E.g 0000013225

I need to enter only 13225 so how i will append 00000 in above case. Numbers of 0 also varies.e.g 0000121135

Thanks

Nityanand Arya

Accepted Solutions (1)

Accepted Solutions (1)

chander_kararia4
Contributor
0 Kudos

Hi

Its a total programming logic. Here is the logic:-

ex.

If your sales order is of 10 digits (mandatory), say 0000012345, then

- In your input field, you enter only 12345

- Now count the number of characters in the above string, in above case it is 5.

- So, to make it a 10 digit number, you need to append 5 Zeros,

It will look like this....

String orderNum = wdContext.current........getX();

int count = orderNum.length();

if(count==5)

{

//Append 5 leading zeros.

orderNum = "00000"+orderNum;

}

like this way, you can solve your issue.

Best Regards

Chander Kararia

Edited by: Chander Kararia on Sep 29, 2009 11:32 AM

Former Member
0 Kudos

Thanks a lot ,

But where to add the code or shall i create one java file and add it there.I am bit new to this framework.

chander_kararia4
Contributor
0 Kudos

Hi Nitya,

This is also very simple.

- No need to create any Java file for this code.

- In your view, You are taking Input(Order Number) from the User. After that, You must be having something like,

  • Submit Button Click, OR

  • Link Action, etc.

  1. In short, there must be an Action on that page where you will be doing some processing on the Order Number.

- In the same method, where you are Getting the Order Number, just write the logic below that.

#Important Note -> In case you are using this modified order number many places, make sure you do either of the following steps to get the correct value every-time.

1. After setting the value to 10 digits, set the value in Context. OR

2. Create a Global variable (define it in 'Other' section, you may see it at the end of implementation tab, just scroll down) and set it only once the value.

NO NEED TO REPEAT THE CODE IN EACH & EVERY METHOD.

This will solve your issue. Still problem? Please let me know your application functionality.

Thanks.

Best Regards

Chander Kararia

Edited by: Chander Kararia on Sep 29, 2009 1:50 PM

Answers (3)

Answers (3)

former_member40425
Contributor
0 Kudos

You want to add zeros in your sales order number because You must be sending this sales order number to any BAPI And that bapi will be taking only if it is full 10 digits value.

If BAPI can be modified then you can use Function module CONVERSION_EXIT_ALPHA_INPUT in your BAPI. Send your value without zeros BAPI will take care automatically.

I hope it helps.

Regards,

Rohit

Former Member
0 Kudos

Hi,

>suppose its 10 digit sales order

Can this be statically determined during development? More often than not (at least in R/3) number ranges and lengths are part of the customisation that will differ from customer to customer. Customer A can use 10 digit long SO numbers while customer B can use 25 digit long SO numbers.

Even if you know the length, say 25 then it is easy to see that the code posted in the first reply will become cumbersome. It would look like:


if(length == 1)
   salesOrder = "000000000000000000000000" + salesOrder;
else if(length == 2)
   salesOrder = "00000000000000000000000" + salesOrder;
//and so forth for all the 25 cases

This is not very elegant, isn't it (with all due respect to the poster of the reply). What if someone uses a 40 digit long SO number? A more elegant solution is to use string formatting. If you are on Java 5 (and above), you can try this:


int salesOrder = 12345;
/**
 * Assuming the SO number has 10 digits. Replace 10 with as many
 * digits the SO number has. Example, for 25 digits use "%025d" 
 * keeping the leading 0 intact.
 */
String r3SalesOrder = String.format("%010d", salesOrder);

If you are not on Java 5 at least, then try this:


long salesOrder = 12345;
String r3Format = "0000000000"; //for 10 digit numbers
String soString = Long.toString(salesOrder); 

String r3SalesOrder = r3Format.substring(0 , r3Format.length() - soString.length()) + soString;

By way this post is not meant to downplay anyone else's post.

Regards,

Satyajit

Former Member
0 Kudos

I agree with Satyajit, we should always try to avoid hardcode to a specific number...

If you don't have the latest java and String.format is not available...you can create the following method and call it for any width...

public java.lang.String ZeroPad( int num, int width )
  {
    //@@begin ZeroPad()
	StringBuffer result = new StringBuffer("");      
	for( int i = 0; i < width-Integer.toString(num).length(); i++ )
	result.append( "0" );      
	result.append( Integer.toString(num) 
	);      
	return result.toString();
    //@@end
  }

ex: you have Sales Order number "12345" and you want to pad it to make it 10 digit with leading 0's..

salesorderno = Zeropad( "12345", 10)

the result will be "0000012345"

If the sales order is only 4 digits ..it will put six leading 0's .

Hope this gives another option based on your need

Former Member
0 Kudos

Nitya,

you might be having some action performed based on the input sales order number. You need to modify your input sales order number in all those actions to your required 10 digit number.

Hope it helps.