cancel
Showing results for 
Search instead for 
Did you mean: 

Re: STRING FUNCTIONS in SCREEN PERSONAS

01-28-2015 5:25 PM
sushant_priyadarshi Product and Topic Expert
1491 views 5 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

Hi,

I have a requirement where I need to get the EQUIPMENT Number  from a long string found in SAP. Please view ATTACHMENT.

This is my Input string from Tcode IA02.

Input: Equipment   149054              KOMATSU-PC1250LC-8

I need the Equipment Number 149054 and the Description KOMATSU-PC1250LC-8 separately for my output.

I am not sure if Javascript with string functions will work, since the input has multiple spaces.

Any ideas on how to go about this in PERSONAS???

Thanks

Abraham

0 Likes
View Entire Topic
sushant_priyadarshi
Product and Topic Expert
Product and Topic Expert
0 Likes


Hi Startlet,

As Steve suggested, you can use javascript for this.

Check the below example code and you can combine what you want:

1. Find out the first occurrences of numbers in a string:

   var r = /\d+/;

   var s = "149054 KOMOATEST";

   alert (s.match(r));

2. You want all the numbers in your string

   var r = /\d+/g;

   var s = "635 this is personas 1012";

   var m;

   while ((m = r.exec(s)) != null) {

     alert(m[0]);

    }

3. Remove whitespace from string

   var s = "this is my test        personas";

   alert(s.replace(/ /g,''));

if you want to learn more about regex in js, you might want to check:

JavaScript RegExp Reference

Regards,

Sushant

m4abrams
Participant
0 Likes

Hi Sushant,

This is my code in the script button:

STEP1: COPY_VALUE from textbox and assign to "input".

STEP2: Calculate in JavaScript:

var r = /\d+/;

var args.output = input.match(r);

STEP3: PASTE_VALUE "output" to textbox I am getting an error in STEP2. Could you help me out here ?

sushant_priyadarshi
Product and Topic Expert
Product and Topic Expert
0 Likes

STEP1: COPY_VALUE from textbox and assign to "input".

STEP2: Calculate in JavaScript:

var r = /\d+/;

args.output = args.input.match(r);

STEP3: PASTE_VALUE "output"

Try now?

m4abrams
Participant
0 Likes

Hi Sushant,

I tried as you said in PERSONAS. Now the Javascript error has disappeared but my output is "System.Windows.Browser.ScriptObject"

Do you know what would be wrong here.

Thanks

Abraham

FYI: The javascript code#1 works perfectly to fetch the Equip# from the string. I tested it on one of the online test environments and it works perfectly.

sushant_priyadarshi
Product and Topic Expert
Product and Topic Expert
0 Likes

var r = new RegExp('\\d+');

args.output = parseInt(args.input.match(r));

or

args.output = args.input.match(r).toString();



Should work!!

m4abrams
Participant
0 Likes

Works perfectly.!

Thanks Sushant