cancel
Showing results for 
Search instead for 
Did you mean: 

Alphanumeric to Numeric..

former_member223432
Participant
0 Kudos

Hi Guys,

I am passing PI message ID to one of the field...but i need to pass only the numbers and it should be only 7 digits..

how can i convert the alphanumeric to only numeric number in PI and truncate to only 7.

your reply would really be appreciated.

Regards

Edited by: ayrahcaanilan on Feb 15, 2012 4:22 PM

Accepted Solutions (0)

Answers (2)

Answers (2)

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Ayrahcaanilan,

You can use

public static void main(String[] args) {
        Random random = new Random();
        String myRandomNo = "";
        for (int i = 0; i < 7; i++) {
            myRandomNo = myRandomNo + random.nextInt(10);
        }
        System.out.println(myRandomNo);
    }

Java Random [Link|http://docs.oracle.com/javase/6/docs/api/java/util/Random.html] .

Regards,

Raghu_Vamsee

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

>>>but i need to pass only the numbers and it should be only 7 digits..

but not put something completely different there ? a random number of 7 digits ?

PI message id without letters and truncated to 7 digits is not PI message ID anymore at all so why bother

Regards,

Michal Krawczyk

former_member223432
Participant
0 Kudos

Thanks michal..

i am using this logic to generate a random number.....i know i can get this by writing an UDF by taking time(milliscs) or date into consideration...infact i did.but we are facing some issues with that..so we want to avoid using time and date concept here.

Is there any other way to generate a random UNIQUE number?

regards

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

>>>Is there any other way to generate a random UNIQUE number?

no - 7 digt numbers will never be unique in a long run - sorry - maybe try to think about the design a little more

so you can use a real unique number or redesign the end interface

Regards,

Michal Krawczyk

former_member223432
Participant
0 Kudos

Thanks Michal,

Canwe get a UNIQUE random if it is 10 digits without using date and time...

your reply is realy appreciated.

Thanks

former_member181962
Active Contributor
0 Kudos

Hi Arya,

It depends o how frequently a new number gets created.If we assume you generate 1 new ID per second, then it takes approximately 326 years before you get a duplicate.

Best regards,

Ravikanth Talagana

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

>>>It depends o how frequently a new number gets created.If we assume you generate 1 new ID per second, then it takes approximately 326 years before you get a duplicate.

assuming - you keep track on the IDs right ?

I don't know how SAP's messageguid is being generated but I don't think it keeps track of all previous IDs right ?

Regards,

Michal Krawczyk

former_member181962
Active Contributor
0 Kudos

Hi Michal,

Yes, that is my assumption too.

A number that is generated should not be repeated until, all of the number range is exhausted.

Best regards,

Ravikanth Talagana

Former Member
0 Kudos

instead of using PI message id for generating unique number u can create number range object using transaction code SNRO ( may be of char 15 length) and call the above created NRO using the function module "NUMBER_GET_NEXT" in PI mapping....

former_member223432
Participant
0 Kudos

Thanks for your reply Amit..

Can you please provide me the steps in creating the number range in ECC anc calling the same in PI...please.

your help wold realy be appreciated.

thanks

former_member181962
Active Contributor
0 Kudos

http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=50004015

Then you have to create a RFC wrapper around the function module GET_NUMBER_NEXT.

Use this article to see how you can call an RFC from graphical mapping:

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40b64ca6-b1e3-2b10-4c9b-c48234cce...

Best Regards,

Ravi